Phase 4: replace container widgets with fragment fetches
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m3s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m3s
Blog post page and home route fetch container-nav from events + market concurrently via fetch_fragments(). Blog listing fetches container-cards from events and parses per-post HTML via comment markers. widget_paginate proxies calendar pagination to events fragment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from quart import (
|
||||
from .services.post_data import post_data
|
||||
from .services.post_operations import toggle_post_like
|
||||
from shared.services.registry import services
|
||||
from shared.services.widget_registry import widgets
|
||||
from shared.infrastructure.fragments import fetch_fragment, fetch_fragments
|
||||
|
||||
from shared.browser.app.redis_cacher import cache_page, clear_cache
|
||||
|
||||
@@ -69,24 +69,27 @@ def register():
|
||||
db_post_id = (g.post_data.get("post") or {}).get("id")
|
||||
post_slug = (g.post_data.get("post") or {}).get("slug", "")
|
||||
|
||||
# Widget-driven container nav
|
||||
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
|
||||
# Fetch container nav fragments from events + market
|
||||
paginate_url = url_for(
|
||||
'blog.post.widget_paginate',
|
||||
slug=post_slug, widget_domain='calendar',
|
||||
)
|
||||
nav_params = {
|
||||
"container_type": "page",
|
||||
"container_id": str(db_post_id),
|
||||
"post_slug": post_slug,
|
||||
"paginate_url": paginate_url,
|
||||
}
|
||||
events_nav_html, market_nav_html = await fetch_fragments([
|
||||
("events", "container-nav", nav_params),
|
||||
("market", "container-nav", nav_params),
|
||||
])
|
||||
container_nav_html = events_nav_html + market_nav_html
|
||||
|
||||
ctx = {
|
||||
**p_data,
|
||||
"base_title": f"{config()['title']} {p_data['post']['title']}",
|
||||
"container_nav_widgets": container_nav_loaded,
|
||||
"container_nav_html": container_nav_html,
|
||||
}
|
||||
|
||||
# Page cart badge via service
|
||||
@@ -154,20 +157,22 @@ def register():
|
||||
|
||||
@bp.get("/w/<widget_domain>/")
|
||||
async def widget_paginate(slug: str, widget_domain: str):
|
||||
"""Generic paginated widget endpoint for infinite scroll."""
|
||||
"""Proxies paginated widget requests to the appropriate fragment provider."""
|
||||
page = int(request.args.get("page", 1))
|
||||
post_id = g.post_data["post"]["id"]
|
||||
|
||||
for w in widgets.container_nav:
|
||||
if w.domain == widget_domain:
|
||||
ctx = await w.context_fn(
|
||||
g.s, container_type="page", container_id=post_id,
|
||||
post_slug=slug, page=page,
|
||||
)
|
||||
html = await render_template(
|
||||
w.template, ctx=ctx, post=g.post_data["post"],
|
||||
)
|
||||
return await make_response(html)
|
||||
if widget_domain == "calendar":
|
||||
html = await fetch_fragment("events", "container-nav", params={
|
||||
"container_type": "page",
|
||||
"container_id": str(post_id),
|
||||
"post_slug": slug,
|
||||
"page": str(page),
|
||||
"paginate_url": url_for(
|
||||
'blog.post.widget_paginate',
|
||||
slug=slug, widget_domain='calendar',
|
||||
),
|
||||
})
|
||||
return await make_response(html or "")
|
||||
abort(404)
|
||||
|
||||
return bp
|
||||
|
||||
Reference in New Issue
Block a user