{# A post's rich links (crate::link_cards): cards under the body, and for
staff the manage panel. Rendered from stored rows only: nothing here
fetches anything, so a page view never waits on (or tells) another site.
`post` is a PostRow: `links` is empty on a deleted or hidden post, so its
cards never show; `staff_links` is every link, for staff. The block swaps
as a whole (hx-target the #links- id) after a staff action, with
`links_open`; `links_poll` re-asks while a fetch is pending. #}
<div id="links-{{ post.id }}" data-links="{{ post.id }}"
{% if links_poll %}hx-get="/p/{{ post.id }}/links?open=1" hx-trigger="load delay:3s" hx-target="this" hx-select="unset" hx-swap="outerHTML"{% endif %}>
{% if post.links %}
<div class="grid gap-2 mt-3 grid-cols-1 sm:grid-cols-2 {% if post.links | length > 2 %}lg:grid-cols-3{% endif %}" data-link-cards>
{% for link in post.links %}
{# Opaque on every theme and on the sea-glass panels: base-100 inside
the base-200 post card. rel: noopener so the other page can't reach
back through window.opener; noreferrer keeps this page's address out
of its logs; nofollow ugc because staff picked it, not us. #}
<a href="{{ link.href | attr }}" rel="noopener noreferrer nofollow ugc" target="_blank" hx-boost="false"
class="link-card group rounded-box border border-base-300 bg-base-100 text-base-content overflow-hidden flex flex-col no-underline hover:border-primary/60 transition-colors"
data-link-card="{{ link.status }}" title="{{ link.url | attr }}">
{% if link.image_url %}
<img src="{{ link.image_url | attr }}" alt="" loading="lazy" decoding="async" class="w-full h-28 object-cover bg-base-200"/>
{% endif %}
<span class="p-3 flex flex-col gap-1 flex-1 min-w-0">
<span class="text-sm font-semibold leading-snug break-words line-clamp-2">{% if link.title %}{{ link.title }}{% else %}{{ link.host }}{% endif %}</span>
{% if link.description %}
<span class="text-xs opacity-70 leading-snug break-words line-clamp-3">{{ link.description }}</span>
{% elif not link.title %}
<span class="text-xs opacity-60 break-all line-clamp-2">{{ link.url }}</span>
{% endif %}
<span class="text-xs opacity-60 mt-auto pt-1 flex items-center gap-1 min-w-0">
<i class="fas fa-arrow-up-right-from-square fa-xs shrink-0"></i>
<span class="truncate">{% if link.site_name %}{{ link.site_name }} · {% endif %}{{ link.host }}</span>
{% if link.status == "pending" %}<span class="shrink-0 opacity-70">· reading…</span>{% endif %}
</span>
</span>
</a>
{% endfor %}
</div>
{% endif %}
{% if links_open and post.can_moderate %}
<div class="mt-3 rounded-box border border-base-300 bg-base-100 p-3 text-sm" data-links-panel>
<div class="flex items-center justify-between gap-2 mb-2">
<span class="font-semibold text-xs uppercase tracking-wide opacity-70"><i class="fas fa-link mr-1"></i>Links on this post · {{ post.staff_links | length }}/{{ max_links }}</span>
<button type="button" class="btn btn-ghost btn-xs" hx-get="/p/{{ post.id }}/links" hx-target="#links-{{ post.id }}" hx-select="unset" hx-swap="outerHTML">Done</button>
</div>
{% if post.hidden %}<p class="text-xs opacity-70 mb-2">This post is hidden, so its cards aren't shown to anyone until it is.</p>{% endif %}
{% if post.staff_links %}
<ul class="space-y-1 mb-2">
{% for link in post.staff_links %}
<li class="flex items-center gap-2 min-w-0" data-link-row="{{ link.status }}">
<span class="badge badge-sm shrink-0 {% if link.status == 'ok' %}badge-success{% elif link.status == 'failed' %}badge-warning{% else %}badge-ghost{% endif %}" title="{% if link.status == 'failed' %}Nothing could be read from that page; the card shows the link and its host{% elif link.status == 'pending' %}Fetching{% else %}Card built{% endif %}">{{ link.status }}</span>
<span class="truncate flex-1 min-w-0" title="{{ link.url | attr }}">{% if link.title %}{{ link.title }} · {% endif %}<span class="opacity-60">{{ link.url }}</span></span>
<form method="post" action="/links/{{ link.id }}/refetch" class="m-0 shrink-0"
hx-post="/links/{{ link.id }}/refetch" hx-target="#links-{{ post.id }}" hx-select="unset" hx-swap="outerHTML">
<button class="btn btn-ghost btn-xs" type="submit" title="Fetch the page again"><i class="fas fa-rotate"></i><span class="sr-only">Refetch</span></button>
</form>
<form method="post" action="/links/{{ link.id }}/delete" class="m-0 shrink-0"
hx-post="/links/{{ link.id }}/delete" hx-target="#links-{{ post.id }}" hx-select="unset" hx-swap="outerHTML">
<button class="btn btn-ghost btn-xs text-error" type="submit" title="Remove this link"><i class="fas fa-xmark"></i><span class="sr-only">Remove</span></button>
</form>
</li>
{% endfor %}
</ul>
{% endif %}
{% if links_error %}<p class="text-error text-xs mb-2" role="alert" data-links-error>{{ links_error }}</p>{% endif %}
{% if post.staff_links | length < max_links %}
<form method="post" action="/p/{{ post.id }}/links" class="flex gap-2 items-center m-0"
hx-post="/p/{{ post.id }}/links" hx-target="#links-{{ post.id }}" hx-select="unset" hx-swap="outerHTML">
<input class="input input-bordered input-sm flex-1 min-w-0" type="text" inputmode="url" name="url"
placeholder="https://… or example.com" maxlength="2000" required autocomplete="off" aria-label="Link to attach"/>
<button class="btn btn-outline btn-sm" type="submit"><i class="fas fa-plus mr-1"></i>Attach</button>
</form>
<p class="text-xs opacity-60 mt-1">The page is read once in the background; its card appears here when it's done.</p>
{% endif %}
</div>
{% endif %}
</div>
neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
⭐
Log in to mark this repository.
5.8 KiB · text
History
7ce364f