diff --git a/hooks/nav.py b/hooks/nav.py index 958d27d..0c2be05 100644 --- a/hooks/nav.py +++ b/hooks/nav.py @@ -23,6 +23,15 @@ def children(page): return page_children +def get_parent_page(page): + if is_list_page(page) and len(page.parent.children) == 1: + parent_section = page.parent.parent + if parent_section: + return parent_section.children[0] + + return page.parent + + @jinja2.pass_context def get_page(context, slug): nav = context["nav"] @@ -45,3 +54,4 @@ def on_env(env, config, files): env.filters["children"] = children env.globals["get_page"] = get_page env.globals["get_page_url"] = get_page_url + env.globals["get_parent_page"] = get_parent_page diff --git a/theme/main.html b/theme/main.html index c6cff26..c9a55c0 100644 --- a/theme/main.html +++ b/theme/main.html @@ -3,6 +3,7 @@ Nav: {{ nav }} Parent: {{ page.parent }} +Custom parent: {{ get_parent_page(page) }} Section: {{ page.is_section }} Is lits page: {{ page|is_list_page }}