Correctly find parent for single-child sections
More like pages with associated files, really
This commit is contained in:
parent
4497904ce2
commit
495f64c10e
2 changed files with 11 additions and 0 deletions
10
hooks/nav.py
10
hooks/nav.py
|
@ -23,6 +23,15 @@ def children(page):
|
||||||
|
|
||||||
return page_children
|
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
|
@jinja2.pass_context
|
||||||
def get_page(context, slug):
|
def get_page(context, slug):
|
||||||
nav = context["nav"]
|
nav = context["nav"]
|
||||||
|
@ -45,3 +54,4 @@ def on_env(env, config, files):
|
||||||
env.filters["children"] = children
|
env.filters["children"] = children
|
||||||
env.globals["get_page"] = get_page
|
env.globals["get_page"] = get_page
|
||||||
env.globals["get_page_url"] = get_page_url
|
env.globals["get_page_url"] = get_page_url
|
||||||
|
env.globals["get_parent_page"] = get_parent_page
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
Nav: {{ nav }}
|
Nav: {{ nav }}
|
||||||
|
|
||||||
Parent: {{ page.parent }}
|
Parent: {{ page.parent }}
|
||||||
|
Custom parent: {{ get_parent_page(page) }}
|
||||||
Section: {{ page.is_section }}
|
Section: {{ page.is_section }}
|
||||||
|
|
||||||
Is lits page: {{ page|is_list_page }}
|
Is lits page: {{ page|is_list_page }}
|
||||||
|
|
Loading…
Reference in a new issue