Switch federation link-card fragment to sexp rendering
All four services (blog, market, events, federation) now use the shared ~link-card s-expression component instead of per-service Jinja templates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|||||||
from quart import Blueprint, Response, request
|
from quart import Blueprint, Response, request
|
||||||
|
|
||||||
from shared.infrastructure.fragments import FRAGMENT_HEADER
|
from shared.infrastructure.fragments import FRAGMENT_HEADER
|
||||||
|
from shared.sexp.jinja_bridge import sexp
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
@@ -31,8 +32,20 @@ def register():
|
|||||||
|
|
||||||
# --- link-card fragment: actor profile preview card --------------------------
|
# --- link-card fragment: actor profile preview card --------------------------
|
||||||
|
|
||||||
|
def _render_federation_link_card(actor, link: str) -> str:
|
||||||
|
return sexp(
|
||||||
|
'(~link-card :link link :title title :image image'
|
||||||
|
' :icon "fas fa-user" :subtitle username'
|
||||||
|
' :detail summary :data-app "federation")',
|
||||||
|
link=link,
|
||||||
|
title=actor.display_name or actor.preferred_username,
|
||||||
|
image=None,
|
||||||
|
username=f"@{actor.preferred_username}" if actor.preferred_username else None,
|
||||||
|
summary=actor.summary,
|
||||||
|
)
|
||||||
|
|
||||||
async def _link_card_handler():
|
async def _link_card_handler():
|
||||||
from quart import g, render_template
|
from quart import g
|
||||||
from shared.services.registry import services
|
from shared.services.registry import services
|
||||||
from shared.infrastructure.urls import federation_url
|
from shared.infrastructure.urls import federation_url
|
||||||
|
|
||||||
@@ -48,13 +61,8 @@ def register():
|
|||||||
parts.append(f"<!-- fragment:{u} -->")
|
parts.append(f"<!-- fragment:{u} -->")
|
||||||
actor = await services.federation.get_actor_by_username(g.s, u)
|
actor = await services.federation.get_actor_by_username(g.s, u)
|
||||||
if actor:
|
if actor:
|
||||||
parts.append(await render_template(
|
parts.append(_render_federation_link_card(
|
||||||
"fragments/link_card.html",
|
actor, federation_url(f"/users/{actor.preferred_username}"),
|
||||||
display_name=actor.display_name,
|
|
||||||
username=actor.preferred_username,
|
|
||||||
avatar_url=None,
|
|
||||||
summary=actor.summary,
|
|
||||||
link=federation_url(f"/users/{actor.preferred_username}"),
|
|
||||||
))
|
))
|
||||||
return "\n".join(parts)
|
return "\n".join(parts)
|
||||||
|
|
||||||
@@ -65,13 +73,8 @@ def register():
|
|||||||
actor = await services.federation.get_actor_by_username(g.s, lookup)
|
actor = await services.federation.get_actor_by_username(g.s, lookup)
|
||||||
if not actor:
|
if not actor:
|
||||||
return ""
|
return ""
|
||||||
return await render_template(
|
return _render_federation_link_card(
|
||||||
"fragments/link_card.html",
|
actor, federation_url(f"/users/{actor.preferred_username}"),
|
||||||
display_name=actor.display_name,
|
|
||||||
username=actor.preferred_username,
|
|
||||||
avatar_url=None,
|
|
||||||
summary=actor.summary,
|
|
||||||
link=federation_url(f"/users/{actor.preferred_username}"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
_handlers["link-card"] = _link_card_handler
|
_handlers["link-card"] = _link_card_handler
|
||||||
|
|||||||
Reference in New Issue
Block a user