Add function to get page URL
This is much easier to work with
This commit is contained in:
parent
c25fb3e76c
commit
ae44083c72
2 changed files with 13 additions and 0 deletions
11
hooks/nav.py
11
hooks/nav.py
|
@ -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
|
||||
|
|
|
@ -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 }}
|
||||
|
|
Loading…
Reference in a new issue