Add Phase 5: link-card fragments, oEmbed endpoints, OG meta
- fetch_fragment_batch() for N+1 avoidance with per-key Redis cache - link-card fragment handlers in blog, market, events, federation (single + batch mode) - link_card.html templates per app with content-specific previews - shared/infrastructure/oembed.py: build_oembed_response, build_og_meta, build_oembed_link_tag - GET /oembed routes on blog, market, events - og_meta + oembed_link rendering in base template <head> - INTERNAL_URL_ARTDAG in docker-compose.yml for cross-stack fragment fetches Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -161,6 +161,35 @@ def create_app() -> "Quart":
|
||||
from bp.ticket_admin.routes import register as register_ticket_admin
|
||||
app.register_blueprint(register_ticket_admin())
|
||||
|
||||
# --- oEmbed endpoint ---
|
||||
@app.get("/oembed")
|
||||
async def oembed():
|
||||
from urllib.parse import urlparse
|
||||
from quart import jsonify
|
||||
from shared.infrastructure.urls import events_url
|
||||
from shared.infrastructure.oembed import build_oembed_response
|
||||
|
||||
url = request.args.get("url", "")
|
||||
if not url:
|
||||
return jsonify({"error": "url parameter required"}), 400
|
||||
|
||||
parsed = urlparse(url)
|
||||
slug = parsed.path.strip("/").split("/")[0] if parsed.path.strip("/") else ""
|
||||
if not slug:
|
||||
return jsonify({"error": "could not extract slug"}), 404
|
||||
|
||||
post = await services.blog.get_post_by_slug(g.s, slug)
|
||||
if not post:
|
||||
return jsonify({"error": "not found"}), 404
|
||||
|
||||
resp = build_oembed_response(
|
||||
title=post.title,
|
||||
oembed_type="link",
|
||||
thumbnail_url=post.feature_image,
|
||||
url=events_url(f"/{post.slug}"),
|
||||
)
|
||||
return jsonify(resp)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
@@ -125,6 +125,55 @@ def register():
|
||||
|
||||
_handlers["account-page"] = _account_page_handler
|
||||
|
||||
# --- link-card fragment: event page preview card ----------------------------
|
||||
|
||||
async def _link_card_handler():
|
||||
from shared.infrastructure.urls import events_url
|
||||
|
||||
slug = request.args.get("slug", "")
|
||||
keys_raw = request.args.get("keys", "")
|
||||
|
||||
# Batch mode
|
||||
if keys_raw:
|
||||
slugs = [k.strip() for k in keys_raw.split(",") if k.strip()]
|
||||
parts = []
|
||||
for s in slugs:
|
||||
parts.append(f"<!-- fragment:{s} -->")
|
||||
post = await services.blog.get_post_by_slug(g.s, s)
|
||||
if post:
|
||||
calendars = await services.calendar.calendars_for_container(
|
||||
g.s, "page", post.id,
|
||||
)
|
||||
cal_names = ", ".join(c.name for c in calendars) if calendars else ""
|
||||
parts.append(await render_template(
|
||||
"fragments/link_card.html",
|
||||
title=post.title,
|
||||
feature_image=post.feature_image,
|
||||
calendar_names=cal_names,
|
||||
link=events_url(f"/{post.slug}"),
|
||||
))
|
||||
return "\n".join(parts)
|
||||
|
||||
# Single mode
|
||||
if not slug:
|
||||
return ""
|
||||
post = await services.blog.get_post_by_slug(g.s, slug)
|
||||
if not post:
|
||||
return ""
|
||||
calendars = await services.calendar.calendars_for_container(
|
||||
g.s, "page", post.id,
|
||||
)
|
||||
cal_names = ", ".join(c.name for c in calendars) if calendars else ""
|
||||
return await render_template(
|
||||
"fragments/link_card.html",
|
||||
title=post.title,
|
||||
feature_image=post.feature_image,
|
||||
calendar_names=cal_names,
|
||||
link=events_url(f"/{post.slug}"),
|
||||
)
|
||||
|
||||
_handlers["link-card"] = _link_card_handler
|
||||
|
||||
bp._fragment_handlers = _handlers
|
||||
|
||||
return bp
|
||||
|
||||
17
events/templates/fragments/link_card.html
Normal file
17
events/templates/fragments/link_card.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<a href="{{ link }}" class="block rounded border border-stone-200 bg-white hover:bg-stone-50 transition-colors no-underline" data-fragment="link-card" data-app="events" data-hx-disable>
|
||||
<div class="flex flex-row items-start gap-3 p-3">
|
||||
{% if feature_image %}
|
||||
<img src="{{ feature_image }}" alt="" class="flex-shrink-0 w-16 h-16 rounded object-cover">
|
||||
{% else %}
|
||||
<div class="flex-shrink-0 w-16 h-16 rounded bg-stone-100 flex items-center justify-center text-stone-400">
|
||||
<i class="fas fa-calendar text-lg"></i>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="font-medium text-stone-900 text-sm clamp-2">{{ title }}</div>
|
||||
{% if calendar_names %}
|
||||
<div class="text-xs text-stone-500 mt-0.5">{{ calendar_names }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
Reference in New Issue
Block a user