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:
@@ -15,6 +15,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,
|
||||
)
|
||||
@@ -24,14 +26,10 @@ load_service_components(os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# OOB header helper
|
||||
# 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("blog-oob-header",
|
||||
parent_id=parent_id, child_id=child_id, row_html=row_html,
|
||||
)
|
||||
_oob_header_html = oob_header_html
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -48,59 +46,40 @@ def _blog_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Post header helpers
|
||||
# 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")
|
||||
"""Build the post-level header row (blog-specific: container-nav wrapping + admin cog)."""
|
||||
overrides: dict = {}
|
||||
|
||||
label_html = render("blog-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("blog-post-cart-link",
|
||||
href=cart_href, count=str(page_cart_count),
|
||||
))
|
||||
|
||||
# Container nav fragments (calendars, markets)
|
||||
# Blog wraps container_nav_html in border styling
|
||||
container_nav = ctx.get("container_nav_html", "")
|
||||
if container_nav:
|
||||
nav_parts.append(render("blog-container-nav",
|
||||
overrides["container_nav_html"] = render("blog-container-nav",
|
||||
container_nav_html=container_nav,
|
||||
))
|
||||
)
|
||||
|
||||
# Admin link
|
||||
from quart import url_for as qurl, g, request
|
||||
# Admin cog link
|
||||
from quart import url_for as qurl, request
|
||||
post = ctx.get("post") or {}
|
||||
slug = post.get("slug", "")
|
||||
rights = ctx.get("rights") or {}
|
||||
has_admin = rights.get("admin") if isinstance(rights, dict) else getattr(rights, "admin", False)
|
||||
if has_admin:
|
||||
if has_admin and slug:
|
||||
select_colours = ctx.get("select_colours", "")
|
||||
styles = ctx.get("styles") or {}
|
||||
nav_btn = styles.get("nav_button", "") if isinstance(styles, dict) else getattr(styles, "nav_button", "")
|
||||
admin_href = qurl("blog.post.admin.admin", slug=slug)
|
||||
is_admin_page = "/admin" in request.path
|
||||
nav_parts.append(render("nav-link",
|
||||
overrides["post_admin_nav_html"] = render("nav-link",
|
||||
href=admin_href, hx_select="#main-panel", icon="fa fa-cog",
|
||||
aclass=f"{nav_btn} {select_colours}",
|
||||
select_colours=select_colours, is_selected=is_admin_page,
|
||||
))
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
effective_ctx = {**ctx, **overrides} if overrides else ctx
|
||||
return _shared_post_header_html(effective_ctx, oob=oob)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user