Add load_page_by_slug helper for single-page operations

This commit is contained in:
Walter Jekat 2025-12-05 11:43:43 +01:00
parent bb94351584
commit 68bf11a54e
1 changed files with 18 additions and 0 deletions

View File

@ -27,6 +27,24 @@ def load_pages():
pages.append(data)
return pages
def load_page_by_slug(slug):
"""
Load a single page dict and its file path by slug.
Assumes each YAML file in CONTENT_PAGES_DIR has a 'slug' field.
"""
for filename in os.listdir(CONTENT_PAGES_DIR):
if not filename.endswith(".yaml"):
continue
path = os.path.join(CONTENT_PAGES_DIR, filename)
with open(path, "r", encoding="utf-8") as f:
data = yaml.safe_load(f)
if data and data.get("slug") == slug:
return data, path
raise FileNotFoundError(f"No page with slug={slug!r} in {CONTENT_PAGES_DIR}")
def render_page(page):
template_name = "page.html" # all use same template for now
template = env.get_template(template_name)