Consolidate post header/menu system into shared infrastructure
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:
2026-02-28 19:06:18 +00:00
parent 97c4e25ba7
commit 6d43404b12
9 changed files with 140 additions and 215 deletions

View File

@@ -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 _post_header_html,
oob_header_html as _oob_header_html,
search_mobile_html, search_desktop_html,
full_page, oob_page,
)
@@ -66,42 +68,9 @@ def _card_price_html(p: dict) -> str:
# ---------------------------------------------------------------------------
# Header helpers
# Header helpers — _post_header_html and _oob_header_html imported from shared
# ---------------------------------------------------------------------------
def _post_header_html(ctx: dict, *, oob: bool = False) -> str:
"""Build the post-level header row (feature image + title + page cart count)."""
post = ctx.get("post") or {}
slug = post.get("slug", "")
title = (post.get("title") or "")[:160]
feature_image = post.get("feature_image")
label_html = ""
if feature_image:
label_html += render("market-post-label-image", src=feature_image)
label_html += render("market-post-label-title", title=title)
nav_html = ""
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_html += render("market-post-cart-badge", href=cart_href, count=str(page_cart_count))
# Container nav
container_nav = ctx.get("container_nav_html", "")
if container_nav:
nav_html += container_nav
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,
)
def _market_header_html(ctx: dict, *, oob: bool = False) -> str:
"""Build the market-level header row (shop icon + market title + category slugs + nav)."""
@@ -1153,16 +1122,9 @@ def _market_cards_html(markets: list, page_info: dict, page: int, has_more: bool
# ---------------------------------------------------------------------------
# OOB header helpers
# OOB header helpers — _oob_header_html imported from 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(
"market-oob-header",
parent_id=parent_id, child_id=child_id, row_html=row_html,
)
# ===========================================================================
# PUBLIC API
@@ -1258,7 +1220,7 @@ async def render_page_markets_page(ctx: dict, markets: list, has_more: bool,
content += render("market-bottom-spacer")
hdr = root_header_html(ctx)
hdr += render("market-header-child", inner_html=_post_header_html(ctx))
hdr += render("header-child", inner_html=_post_header_html(ctx))
return full_page(ctx, header_rows_html=hdr, content_html=content)
@@ -1309,7 +1271,7 @@ async def render_market_home_page(ctx: dict) -> str:
hdr = root_header_html(ctx)
child = _post_header_html(ctx) + _market_header_html(ctx)
hdr += render("market-header-child", inner_html=child)
hdr += render("header-child", inner_html=child)
menu = _mobile_nav_panel_html(ctx)
return full_page(ctx, header_rows_html=hdr, content_html=content, menu_html=menu)
@@ -1354,7 +1316,7 @@ async def render_browse_page(ctx: dict) -> str:
hdr = root_header_html(ctx)
child = _post_header_html(ctx) + _market_header_html(ctx)
hdr += render("market-header-child", inner_html=child)
hdr += render("header-child", inner_html=child)
menu = _mobile_nav_panel_html(ctx)
filter_html = _mobile_filter_summary_html(ctx)
aside_html = _desktop_filter_html(ctx)
@@ -1395,7 +1357,7 @@ async def render_product_page(ctx: dict, d: dict) -> str:
hdr = root_header_html(ctx)
child = _post_header_html(ctx) + _market_header_html(ctx) + _product_header_html(ctx, d)
hdr += render("market-header-child", inner_html=child)
hdr += render("header-child", inner_html=child)
return full_page(ctx, header_rows_html=hdr, content_html=content, meta_html=meta)
@@ -1421,7 +1383,7 @@ async def render_product_admin_page(ctx: dict, d: dict) -> str:
hdr = root_header_html(ctx)
child = (_post_header_html(ctx) + _market_header_html(ctx)
+ _product_header_html(ctx, d) + _product_admin_header_html(ctx, d))
hdr += render("market-header-child", inner_html=child)
hdr += render("header-child", inner_html=child)
return full_page(ctx, header_rows_html=hdr, content_html=content)
@@ -1459,7 +1421,7 @@ async def render_market_admin_page(ctx: dict) -> str:
hdr = root_header_html(ctx)
child = _post_header_html(ctx) + _market_header_html(ctx) + _market_admin_header_html(ctx)
hdr += render("market-header-child", inner_html=child)
hdr += render("header-child", inner_html=child)
return full_page(ctx, header_rows_html=hdr, content_html=content)