Consolidate post header/menu system into shared infrastructure
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m29s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m29s
Replace duplicated _post_header_html, _oob_header_html, and header-child components across blog/events/market/errors with shared sexpr components (~post-label, ~page-cart-badge, ~oob-header, ~header-child, ~error-content) and shared Python helpers (post_header_html, oob_header_html, header_child_html, error_content_html). App-specific logic (blog container-nav wrapping, admin cog, events calendar links) preserved via thin wrappers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ from markupsafe import escape
|
||||
from shared.sexp.jinja_bridge import render, load_service_components
|
||||
from shared.sexp.helpers import (
|
||||
call_url, get_asset_url, root_header_html,
|
||||
post_header_html as _shared_post_header_html,
|
||||
oob_header_html,
|
||||
search_mobile_html, search_desktop_html,
|
||||
full_page, oob_page,
|
||||
)
|
||||
@@ -23,46 +25,21 @@ load_service_components(os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# OOB header helper (same pattern as market)
|
||||
# OOB header helper — delegates to shared
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _oob_header_html(parent_id: str, child_id: str, row_html: str) -> str:
|
||||
"""Wrap a header row in OOB div with child placeholder."""
|
||||
return render("events-oob-header",
|
||||
parent_id=parent_id, child_id=child_id, row_html=row_html)
|
||||
_oob_header_html = oob_header_html
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Post header helpers (mirrors events/templates/_types/post/header/_header.html)
|
||||
# Post header helpers — thin wrapper over shared post_header_html
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _post_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
"""Build the post-level header row."""
|
||||
post = ctx.get("post") or {}
|
||||
slug = post.get("slug", "")
|
||||
title = (post.get("title") or "")[:160]
|
||||
feature_image = post.get("feature_image")
|
||||
|
||||
label_html = render("events-post-label",
|
||||
feature_image=feature_image, title=title)
|
||||
|
||||
nav_parts = []
|
||||
page_cart_count = ctx.get("page_cart_count", 0)
|
||||
if page_cart_count and page_cart_count > 0:
|
||||
cart_href = call_url(ctx, "cart_url", f"/{slug}/")
|
||||
nav_parts.append(render("events-post-cart-link",
|
||||
href=cart_href, count=str(page_cart_count)))
|
||||
|
||||
# Post nav: calendar links + admin
|
||||
nav_parts.append(_post_nav_html(ctx))
|
||||
|
||||
nav_html = "".join(nav_parts)
|
||||
link_href = call_url(ctx, "blog_url", f"/{slug}/")
|
||||
|
||||
return render("menu-row", id="post-row", level=1,
|
||||
link_href=link_href, link_label_html=label_html,
|
||||
nav_html=nav_html, child_id="post-header-child", oob=oob,
|
||||
external=True)
|
||||
"""Build the post-level header row (events-specific: calendar links + admin cog)."""
|
||||
admin_nav = _post_nav_html(ctx)
|
||||
effective_ctx = {**ctx, "post_admin_nav_html": admin_nav} if admin_nav else ctx
|
||||
return _shared_post_header_html(effective_ctx, oob=oob)
|
||||
|
||||
|
||||
def _post_nav_html(ctx: dict) -> str:
|
||||
@@ -1235,7 +1212,7 @@ async def render_page_summary_page(ctx: dict, entries, has_more, pending_tickets
|
||||
)
|
||||
|
||||
hdr = root_header_html(ctx)
|
||||
hdr += render("events-header-child",
|
||||
hdr += render("header-child",
|
||||
inner_html=_post_header_html(ctx))
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
@@ -1289,7 +1266,7 @@ async def render_calendars_page(ctx: dict) -> str:
|
||||
content = _calendars_main_panel_html(ctx)
|
||||
hdr = root_header_html(ctx)
|
||||
child = _post_header_html(ctx) + _calendars_header_html(ctx)
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1311,7 +1288,7 @@ async def render_calendar_page(ctx: dict) -> str:
|
||||
content = _calendar_main_panel_html(ctx)
|
||||
hdr = root_header_html(ctx)
|
||||
child = _post_header_html(ctx) + _calendar_header_html(ctx)
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1334,7 +1311,7 @@ async def render_day_page(ctx: dict) -> str:
|
||||
hdr = root_header_html(ctx)
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _day_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1358,7 +1335,7 @@ async def render_day_admin_page(ctx: dict) -> str:
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _day_header_html(ctx)
|
||||
+ _day_admin_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1381,7 +1358,7 @@ async def render_calendar_admin_page(ctx: dict) -> str:
|
||||
hdr = root_header_html(ctx)
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _calendar_admin_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1407,7 +1384,7 @@ async def render_slots_page(ctx: dict) -> str:
|
||||
hdr = root_header_html(ctx)
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _calendar_admin_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1476,7 +1453,7 @@ async def render_markets_page(ctx: dict) -> str:
|
||||
content = _markets_main_panel_html(ctx)
|
||||
hdr = root_header_html(ctx)
|
||||
child = _post_header_html(ctx) + _markets_header_html(ctx)
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -1860,7 +1837,7 @@ async def render_entry_page(ctx: dict) -> str:
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _day_header_html(ctx)
|
||||
+ _entry_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
nav_html = _entry_nav_html(ctx)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content, menu_html=nav_html)
|
||||
|
||||
@@ -2873,7 +2850,7 @@ async def render_entry_admin_page(ctx: dict) -> str:
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _day_header_html(ctx)
|
||||
+ _entry_header_html(ctx) + _entry_admin_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
nav_html = render("events-admin-placeholder-nav")
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content, menu_html=nav_html)
|
||||
|
||||
@@ -2932,7 +2909,7 @@ async def render_slot_page(ctx: dict) -> str:
|
||||
child = (_post_header_html(ctx)
|
||||
+ _calendar_header_html(ctx) + _calendar_admin_header_html(ctx)
|
||||
+ _slot_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content)
|
||||
|
||||
|
||||
@@ -3140,7 +3117,7 @@ async def render_ticket_types_page(ctx: dict) -> str:
|
||||
+ _calendar_header_html(ctx) + _day_header_html(ctx)
|
||||
+ _entry_header_html(ctx) + _entry_admin_header_html(ctx)
|
||||
+ _ticket_types_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
nav_html = render("events-admin-placeholder-nav")
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content, menu_html=nav_html)
|
||||
|
||||
@@ -3214,7 +3191,7 @@ async def render_ticket_type_page(ctx: dict) -> str:
|
||||
+ _calendar_header_html(ctx) + _day_header_html(ctx)
|
||||
+ _entry_header_html(ctx) + _entry_admin_header_html(ctx)
|
||||
+ _ticket_types_header_html(ctx) + _ticket_type_header_html(ctx))
|
||||
hdr += render("events-header-child", inner_html=child)
|
||||
hdr += render("header-child", inner_html=child)
|
||||
nav_html = render("events-admin-placeholder-nav")
|
||||
return full_page(ctx, header_rows_html=hdr, content_html=content, menu_html=nav_html)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user