2024-02-16 16:13:07 +00:00
|
|
|
import jinja2
|
|
|
|
|
|
|
|
@jinja2.pass_context
|
|
|
|
def get_page(context, slug):
|
|
|
|
nav = context["nav"]
|
|
|
|
for page in nav.pages:
|
|
|
|
if page.file.src_uri == slug:
|
|
|
|
return page
|
|
|
|
|
|
|
|
raise ValueError("Unable to find page for '%s'", slug)
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.pass_context
|
|
|
|
def get_notes(context):
|
|
|
|
notes = []
|
|
|
|
for page in context["nav"].pages:
|
|
|
|
if not page.file.src_uri.startswith("notes/"):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if page.file.src_uri == "notes/index.md":
|
|
|
|
continue
|
|
|
|
|
|
|
|
notes.append(page)
|
|
|
|
return sorted(notes, key=lambda p: p.meta["git_creation_date_localized_raw_iso_date"], reverse=True)
|
|
|
|
|
|
|
|
|
2024-02-15 18:07:13 +00:00
|
|
|
def on_env(env, config, files):
|
|
|
|
env.tests["startswith"] = str.startswith
|
2024-02-16 16:13:07 +00:00
|
|
|
env.globals["get_page"] = get_page
|
|
|
|
env.globals["get_notes"] = get_notes
|