From 4497904ce2001912509bf0f972296e9699bf53e8 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 15 Sep 2023 18:11:06 +0100 Subject: [PATCH] Show child sections as children --- content/list/index.md | 6 ++++++ content/list/item-1.md | 5 +++++ content/list/item-2.md | 5 +++++ content/list/item-3/index.md | 5 +++++ hooks/nav.py | 13 ++++++++++++- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 content/list/index.md create mode 100644 content/list/item-1.md create mode 100644 content/list/item-2.md create mode 100644 content/list/item-3/index.md diff --git a/content/list/index.md b/content/list/index.md new file mode 100644 index 0000000..1780dab --- /dev/null +++ b/content/list/index.md @@ -0,0 +1,6 @@ +--- +tags: + - tag1 + - list +--- +# List page diff --git a/content/list/item-1.md b/content/list/item-1.md new file mode 100644 index 0000000..dfc7d14 --- /dev/null +++ b/content/list/item-1.md @@ -0,0 +1,5 @@ +--- +tags: + - item +--- +# Item 1 diff --git a/content/list/item-2.md b/content/list/item-2.md new file mode 100644 index 0000000..28ed259 --- /dev/null +++ b/content/list/item-2.md @@ -0,0 +1,5 @@ +--- +tags: + - item +--- +# Item 2 diff --git a/content/list/item-3/index.md b/content/list/item-3/index.md new file mode 100644 index 0000000..ff96dec --- /dev/null +++ b/content/list/item-3/index.md @@ -0,0 +1,5 @@ +--- +tags: + - item +--- +# Item 3 diff --git a/hooks/nav.py b/hooks/nav.py index b1f6f6c..958d27d 100644 --- a/hooks/nav.py +++ b/hooks/nav.py @@ -10,7 +10,18 @@ def is_list_page(page) -> bool: def children(page): if not is_list_page(page): return [] - return page.parent.children[1:] + + page_children = [] + + for child in page.parent.children[1:]: + if child.is_page: + page_children.append(child) + + # If the child is a section, use its index page as the child + if child.is_section: + page_children.append(child.children[0]) + + return page_children @jinja2.pass_context def get_page(context, slug):