From 9c06ead675a4a71ea8f9b28f82ba34e2cfcb2560 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 9 Sep 2023 10:56:04 +0100 Subject: [PATCH] Add util for finding page --- hooks/nav.py | 11 +++++++++++ theme/main.html | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/hooks/nav.py b/hooks/nav.py index fbca9be..ad63d0f 100644 --- a/hooks/nav.py +++ b/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 diff --git a/theme/main.html b/theme/main.html index 5c3f169..ecc2871 100644 --- a/theme/main.html +++ b/theme/main.html @@ -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 }}