Add load_page_by_slug helper for single-page operations
This commit is contained in:
parent
bb94351584
commit
68bf11a54e
18
build.py
18
build.py
|
|
@ -27,6 +27,24 @@ def load_pages():
|
||||||
pages.append(data)
|
pages.append(data)
|
||||||
return pages
|
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):
|
def render_page(page):
|
||||||
template_name = "page.html" # all use same template for now
|
template_name = "page.html" # all use same template for now
|
||||||
template = env.get_template(template_name)
|
template = env.get_template(template_name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue