Add Phase 5: link-card fragments, oEmbed endpoints, OG meta
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 4m48s

- 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:
giles
2026-02-24 21:44:11 +00:00
parent 4d7f8cfea2
commit b3d853ad35
15 changed files with 601 additions and 0 deletions

View File

@@ -195,6 +195,44 @@ def create_app() -> "Quart":
return {}
return {**post_data}
# --- oEmbed endpoint ---
@app.get("/oembed")
async def oembed():
from urllib.parse import urlparse
from quart import jsonify
from shared.models.market import Product
from shared.infrastructure.urls import market_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)
# Market product URLs: /.../<page_slug>/<market_slug>/product/<slug>/
parts = [p for p in parsed.path.strip("/").split("/") if p]
slug = ""
for i, part in enumerate(parts):
if part == "product" and i + 1 < len(parts):
slug = parts[i + 1]
break
if not slug:
return jsonify({"error": "could not extract product slug"}), 404
product = (
await g.s.execute(select(Product).where(Product.slug == slug))
).scalar_one_or_none()
if not product:
return jsonify({"error": "not found"}), 404
resp = build_oembed_response(
title=product.title or slug,
oembed_type="link",
thumbnail_url=product.image,
url=market_url(f"/product/{product.slug}/"),
)
return jsonify(resp)
return app

View File

@@ -49,6 +49,59 @@ def register():
_handlers["container-nav"] = _container_nav_handler
# --- link-card fragment: product preview card --------------------------------
async def _link_card_handler():
from sqlalchemy import select
from shared.models.market import Product
from shared.infrastructure.urls import market_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} -->")
product = (
await g.s.execute(select(Product).where(Product.slug == s))
).scalar_one_or_none()
if product:
parts.append(await render_template(
"fragments/link_card.html",
title=product.title,
image=product.image,
description_short=product.description_short,
brand=product.brand,
regular_price=product.regular_price,
special_price=product.special_price,
link=market_url(f"/product/{product.slug}/"),
))
return "\n".join(parts)
# Single mode
if not slug:
return ""
product = (
await g.s.execute(select(Product).where(Product.slug == slug))
).scalar_one_or_none()
if not product:
return ""
return await render_template(
"fragments/link_card.html",
title=product.title,
image=product.image,
description_short=product.description_short,
brand=product.brand,
regular_price=product.regular_price,
special_price=product.special_price,
link=market_url(f"/product/{product.slug}/"),
)
_handlers["link-card"] = _link_card_handler
bp._fragment_handlers = _handlers
return bp

View File

@@ -0,0 +1,28 @@
<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="market" data-hx-disable>
<div class="flex flex-row items-start gap-3 p-3">
{% if image %}
<img src="{{ 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-shopping-bag 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 brand %}
<div class="text-xs text-stone-500 mt-0.5">{{ brand }}</div>
{% endif %}
{% if description_short %}
<div class="text-xs text-stone-500 mt-1 clamp-2">{{ description_short }}</div>
{% endif %}
<div class="text-xs mt-1">
{% if special_price %}
<span class="text-red-600 font-medium">&pound;{{ "%.2f"|format(special_price) }}</span>
<span class="text-stone-400 line-through ml-1">&pound;{{ "%.2f"|format(regular_price) }}</span>
{% elif regular_price %}
<span class="text-stone-700 font-medium">&pound;{{ "%.2f"|format(regular_price) }}</span>
{% endif %}
</div>
</div>
</div>
</a>