@@ -399,6 +399,38 @@ def _is_valueless(obj: dc.Object):
399
399
return False
400
400
401
401
402
+ def _insert_contents (
403
+ x : dict | list ,
404
+ contents : list ,
405
+ sentinel : str = "{{ contents }}" ,
406
+ ):
407
+ """Splice `contents` into a list.
408
+
409
+ Splices `contents` into the first element in `x` that exactly matches
410
+ `sentinel`. This functions recurses into dictionaries, but because
411
+ `contents` is a list, we only look within lists in `x` for the sentinel
412
+ value where `contents` should be inserted.
413
+
414
+ Returns
415
+ -------
416
+ :
417
+ Returns `True` if `contents` was inserted into `x`, otherwise returns
418
+ `False`. Note that `x` is modified in place.
419
+ """
420
+ if isinstance (x , dict ):
421
+ for value in x .values ():
422
+ if _insert_contents (value , contents ):
423
+ return True
424
+ elif isinstance (x , list ):
425
+ for i , item in enumerate (x ):
426
+ if item == sentinel :
427
+ x [i : i + 1 ] = contents # noqa: E203
428
+ return True
429
+ elif _insert_contents (item , contents ):
430
+ return True
431
+ return False
432
+
433
+
402
434
# pkgdown =====================================================================
403
435
404
436
@@ -713,22 +745,7 @@ def _generate_sidebar(
713
745
if not isinstance (sidebar ["contents" ], list ):
714
746
raise TypeError ("`sidebar.contents` must be a list" )
715
747
716
- def splice_contents_recursive (sidebar , contents ):
717
- """Splice quartodoc contents into first element exactly '{{ contents }}'"""
718
- if isinstance (sidebar , dict ):
719
- for value in sidebar .values ():
720
- if splice_contents_recursive (value , contents ):
721
- return True
722
- elif isinstance (sidebar , list ):
723
- for i , item in enumerate (sidebar ):
724
- if item == "{{ contents }}" :
725
- sidebar [i : i + 1 ] = contents # noqa: E203
726
- return True
727
- elif splice_contents_recursive (item , contents ):
728
- return True
729
- return False
730
-
731
- if not splice_contents_recursive (sidebar ["contents" ], contents ):
748
+ if not _insert_contents (sidebar ["contents" ], contents ):
732
749
# otherwise append contents to existing list
733
750
sidebar ["contents" ].extend (contents )
734
751
0 commit comments