Add util for finding page
This commit is contained in:
parent
b04042a839
commit
9c06ead675
2 changed files with 15 additions and 0 deletions
11
hooks/nav.py
11
hooks/nav.py
|
@ -1,3 +1,5 @@
|
|||
import jinja2
|
||||
|
||||
def is_list_page(page) -> bool:
|
||||
if not page.parent:
|
||||
return False
|
||||
|
@ -9,6 +11,15 @@ def children(page):
|
|||
return []
|
||||
return page.parent.children[1:]
|
||||
|
||||
@jinja2.pass_context
|
||||
def get_page(context, slug):
|
||||
nav = context["nav"]
|
||||
for page in nav.pages:
|
||||
if page.file.src_uri == slug:
|
||||
return page
|
||||
return None
|
||||
|
||||
def on_env(env, config, files):
|
||||
env.filters["is_list_page"] = is_list_page
|
||||
env.filters["children"] = children
|
||||
env.globals["get_page"] = get_page
|
||||
|
|
|
@ -8,3 +8,7 @@ Section: {{ page.is_section }}
|
|||
Is lits page: {{ page|is_list_page }}
|
||||
|
||||
Children: {{ page|children }}
|
||||
|
||||
{% set tag_1_page = get_page('tags/tag1.md') %}
|
||||
|
||||
Found page: {{ tag_1_page }}
|
||||
|
|
Loading…
Reference in a new issue