1
Fork 0

Correctly find parent for single-child sections

More like pages with associated files, really
This commit is contained in:
Jake Howard 2023-09-15 18:19:06 +01:00
parent 4497904ce2
commit 495f64c10e
Signed by: jake
GPG Key ID: 57AFB45680EDD477
2 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -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 }}