Fix home route: build full post context for template rendering
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m52s

The post template needs context (base_title, container_nav_widgets,
page_cart_count) that the post blueprint's context_processor provides.
Since home() runs on the blog blueprint, it must build this context
itself.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-23 17:25:15 +00:00
parent 5f97c7cf46
commit b96800c71a

View File

@@ -82,6 +82,10 @@ def register(url_prefix, title):
async def home():
"""Render the Ghost page with slug 'home' as the site homepage."""
from ..post.services.post_data import post_data as _post_data
from shared.config import config as get_config
from shared.infrastructure.cart_identity import current_cart_identity
from shared.services.registry import services as svc
from shared.services.widget_registry import widgets
p_data = await _post_data("home", g.s, include_drafts=False)
if not p_data:
@@ -89,10 +93,44 @@ def register(url_prefix, title):
return redirect(host_url(url_for("blog.index")))
g.post_data = p_data
# Build the same context the post blueprint's context_processor provides
db_post_id = p_data["post"]["id"]
post_slug = p_data["post"]["slug"]
container_nav_loaded = []
for w in widgets.container_nav:
try:
wctx = await w.context_fn(
g.s, container_type="page", container_id=db_post_id,
post_slug=post_slug,
)
has_data = any(v for v in wctx.values() if isinstance(v, list) and v)
if has_data:
container_nav_loaded.append({"widget": w, "ctx": wctx})
except Exception:
pass
ctx = {
**p_data,
"base_title": f"{get_config()['title']} {p_data['post']['title']}",
"container_nav_widgets": container_nav_loaded,
}
# Page cart badge
if p_data["post"].get("is_page"):
ident = current_cart_identity()
page_summary = await svc.cart.cart_summary(
g.s, user_id=ident["user_id"], session_id=ident["session_id"],
page_slug=post_slug,
)
ctx["page_cart_count"] = page_summary.count + page_summary.calendar_count + page_summary.ticket_count
ctx["page_cart_total"] = float(page_summary.total + page_summary.calendar_total + page_summary.ticket_total)
if not is_htmx_request():
html = await render_template("_types/post/index.html", **p_data)
html = await render_template("_types/post/index.html", **ctx)
else:
html = await render_template("_types/post/_oob_elements.html", **p_data)
html = await render_template("_types/post/_oob_elements.html", **ctx)
return await make_response(html)
@blogs_bp.get("/index")