Files
StarPunk/templates/partials/responses.html
T

115 lines
7.3 KiB
HTML

{# Received webmentions as microformats2 responses (v2.8.0)
Each response is an h-cite in a property of the note's h-entry:
u-comment (replies), u-like, u-repost, u-bookmark, u-mention.
See https://indieweb.org/comments-presentation and microformats.org/wiki/h-entry #}
{# When the source said when it was posted, use that; else when we received it #}
{% macro response_time(wm, fmt='%B %-d, %Y') %}
{% set when = wm.source_published or wm.received_at %}
<time class="dt-published" datetime="{{ when|iso_utc }}">{{ when.strftime(fmt) if when.strftime is defined else when }}</time>
{%- endmacro %}
{# The response's own URL: the source's u-url if it gave one #}
{% macro response_url(wm) %}{{ wm.source_post_url or wm.source_url }}{% endmacro %}
{# Where a backfed response came from, e.g. "via Bluesky" (v2.13.0) #}
{% macro via(wm) %}{% if wm.via %}<span class="webmention-via">via {{ wm.via }}</span>{% endif %}{% endmacro %}
{# Author h-card: name, URL and photo. u-url is on an inner link: on the
h-card element itself it would belong to the enclosing h-cite.
The photo is this site's saved copy (v2.13.0); until there is one, the
initial is shown instead of loading it from the other site. #}
{% macro author_card(wm, class='', photo_size=48, show_name=True) %}
{% set photo = wm.author_photo|local_avatar %}
<span class="p-author h-card {{ class }}"><a class="u-url" href="{{ wm.author_url or wm.source_url }}" title="{{ wm.author_name or 'Anonymous' }}{% if wm.via %} via {{ wm.via }}{% endif %}">
{%- if photo %}<img class="u-photo" src="{{ photo }}" alt="" width="{{ photo_size }}" height="{{ photo_size }}" loading="lazy">
{%- elif wm.author_photo %}<data class="u-photo" value="{{ wm.author_photo }}"></data>{% if not show_name %}<span class="face-initial" style="background-color: {{ wm.author_url|url_to_color }}" aria-hidden="true">{{ (wm.author_name or '?')[0]|upper }}</span>{% endif %}
{%- elif not show_name %}<span class="face-initial" style="background-color: {{ wm.author_url|url_to_color }}" aria-hidden="true">{{ (wm.author_name or '?')[0]|upper }}</span>
{%- endif %}
<span class="p-name{{ '' if show_name else ' visually-hidden' }}">{{ wm.author_name or 'Anonymous' }}</span>
</a></span>
{%- endmacro %}
{# A reply, shown as a comment #}
{% macro reply(wm) %}
<article class="webmention webmention-reply u-comment h-cite">
<div class="webmention-author">{{ author_card(wm) }}</div>
{% if wm.content_snippet %}
<div class="e-content">{{ wm.content_snippet|safe }}</div>
{% endif %}
<a class="u-url webmention-date" href="{{ response_url(wm) }}">{{ response_time(wm) }}</a> {{ via(wm) }}
</article>
{%- endmacro %}
{# A post that mentions this note without replying; also quote posts (v2.13.0) #}
{% macro mention(wm) %}
<div class="webmention webmention-mention u-mention h-cite">
{{ author_card(wm, photo_size=24) }}
{% if wm.content_snippet %}
<p class="p-content">{{ wm.content_snippet|striptags|truncate(200) }}</p>
{% endif %}
<a class="u-url webmention-date" href="{{ response_url(wm) }}">{{ response_time(wm) }}</a> {{ via(wm) }}
</div>
{%- endmacro %}
{# Likes, reposts, replies and bookmarks: one line of counts under the note,
like other sites (v2.13.2). Hovering or focusing a count lists who, and
offers the same action on the note's crossposts. Each action is an
<indie-action> (https://indieweb.org/webactions) with those silo links as
its fallback, so web action handlers can take over. Counts without names
(all of Threads; elsewhere people who opted out, v2.13.3) are added to the
total. The people stay in the
markup as u-like / u-repost / u-bookmark h-cites. #}
{% set ICONS = {
'like': '<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>',
'repost': '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 1l4 4-4 4"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><path d="M7 23l-4-4 4-4"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>',
'reply': '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4 8.6 8.6 0 0 1-3.9-.9L3 21l1.9-5.1A8.4 8.4 0 0 1 12 3.1a8.4 8.4 0 0 1 9 8.4z"/></svg>',
'bookmark': '<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M6 2h12a1 1 0 0 1 1 1v19l-7-4-7 4V3a1 1 0 0 1 1-1z"/></svg>',
} %}
{% set VERBS = {'like': 'Like', 'repost': 'Repost', 'reply': 'Reply'} %}
{% macro reaction(kind, items, prop, anon, one, many, copies=[], permalink='', people=True) %}
{% set ns = namespace(total=items|length) %}
{% for name, n in anon %}{% set ns.total = ns.total + n %}{% endfor %}
{% set verb = VERBS.get(kind) %}
{% if ns.total or (verb and copies) %}
<span class="reaction reaction-{{ kind }}" tabindex="0">
{{ ICONS[kind]|safe }}{% if ns.total %}<span class="reaction-count">{{ ns.total }}</span>{% endif %}<span class="visually-hidden"> {{ ns.total }} {{ one if ns.total == 1 else many }}</span>
<span class="reaction-who" role="tooltip">
{% if ns.total %}<span class="reaction-title">{{ ns.total }} {{ one if ns.total == 1 else many }}</span>{% endif %}
{% if (people and items) or anon %}
<span class="reaction-people">
{% if people %}
{% for wm in items %}
<span class="reaction-person {{ prop }} h-cite">{{ author_card(wm, photo_size=20) }}{% if wm.via %}<span class="webmention-via">{{ wm.via }}</span>{% endif %}<a class="u-url" href="{{ response_url(wm) }}" hidden>{{ response_time(wm) }}</a></span>
{% endfor %}
{% endif %}
{% for name, n in anon %}<span class="reaction-anon">{{ '+' if items and people else '' }}{{ n }} on {{ name }}</span>{% endfor %}
</span>
{% endif %}
{% if verb and copies %}
<indie-action class="reaction-elsewhere" do="{{ kind }}" with="{{ permalink }}">{{ verb }} on {% for s in copies %}<a href="{{ s.remote_url }}" rel="noopener">{{ s.name }}</a>{% if not loop.last %} · {% endif %}{% endfor %}</indie-action>
{% endif %}
</span>
</span>
{% endif %}
{%- endmacro %}
{% macro reactions(likes, reposts, replies, bookmarks, syndications, permalink) %}
{% set anon_likes, anon_reposts = [], [] %}
{% for s in syndications or [] %}
{% if s.likes_count %}{% set _ = anon_likes.append((s.name, s.likes_count)) %}{% endif %}
{% if s.reposts_count %}{% set _ = anon_reposts.append((s.name, s.reposts_count)) %}{% endif %}
{% endfor %}
{% set copies = (syndications or [])|selectattr('remote_url')|list %}
{% if copies or likes or reposts or replies or bookmarks or anon_likes or anon_reposts %}
<div class="reactions">
{{ reaction('like', likes or [], 'u-like', anon_likes, 'like', 'likes', copies, permalink) }}
{{ reaction('repost', reposts or [], 'u-repost', anon_reposts, 'repost', 'reposts', copies, permalink) }}
{# Replies are listed in full below; here just the count and where to reply #}
{{ reaction('reply', replies or [], '', [], 'reply', 'replies', copies, permalink, people=False) }}
{{ reaction('bookmark', bookmarks or [], 'u-bookmark', [], 'bookmark', 'bookmarks') }}
</div>
{% endif %}
{%- endmacro %}