1
Fork 0

Add function to get page URL

This is much easier to work with
This commit is contained in:
Jake Howard 2023-09-14 22:02:40 +01:00
parent c25fb3e76c
commit ae44083c72
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 13 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import jinja2
from mkdocs.utils.templates import url_filter
def is_list_page(page) -> bool:
if not page.parent:
@ -19,7 +20,17 @@ def get_page(context, slug):
return page
return None
@jinja2.pass_context
def get_page_url(context, slug):
page = get_page(context, slug)
if page is None:
return None
return url_filter(context, page.url)
def on_env(env, config, files):
env.filters["is_list_page"] = is_list_page
env.filters["children"] = children
env.globals["get_page"] = get_page
env.globals["get_page_url"] = get_page_url

View file

@ -13,6 +13,8 @@ Children: {{ page|children }}
Found page: {{ tag_1_page }}
URL: {{ get_page_url("tags/tag1.md") }}
Image resized: {{ "./assets/test.jpg"|resize_image(1500) }}
Globals: {{ globals.foo }}