1
Fork 0

Add util for finding page

This commit is contained in:
Jake Howard 2023-09-09 10:56:04 +01:00
parent b04042a839
commit 9c06ead675
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 15 additions and 0 deletions

View file

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

View file

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