{# 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 %} {%- 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 %}via {{ wm.via }}{% 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 %} {%- if photo %} {%- elif wm.author_photo %}{% if not show_name %}{% endif %} {%- elif not show_name %} {%- endif %} {{ wm.author_name or 'Anonymous' }} {%- endmacro %} {# A reply, shown as a comment; replies to it are nested inside, as comments of the comment (v2.20.2) #} {% macro reply(wm) %}
{{ author_card(wm) }}
{% if wm.content_snippet %}
{{ wm.content_snippet|safe }}
{% endif %} {{ response_time(wm) }} {{ via(wm) }} {% if wm.children %}
{% for child in wm.children %}{{ reply(child) }}{% endfor %}
{% endif %}
{%- endmacro %} {# A post that mentions this note without replying; also quote posts (v2.13.0) #} {% macro mention(wm) %}
{{ author_card(wm, photo_size=24) }} {% if wm.content_snippet %}

{{ wm.content_snippet|striptags|truncate(200) }}

{% endif %} {{ response_time(wm) }} {{ via(wm) }}
{%- 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 (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': '', 'repost': '', 'reply': '', 'quote': '', 'bookmark': '', } %} {% 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) %} {{ ICONS[kind]|safe }}{% if ns.total %}{{ ns.total }}{% endif %} {{ ns.total }} {{ one if ns.total == 1 else many }} {% if ns.total %}{{ ns.total }} {{ one if ns.total == 1 else many }}{% endif %} {% if (people and items) or anon %} {% if people %} {% for wm in items %} {{ author_card(wm, photo_size=20) }}{% if wm.via %}{{ wm.via }}{% endif %} {% endfor %} {% endif %} {% for name, n in anon %}{{ '+' if items and people else '' }}{{ n }} on {{ name }}{% endfor %} {% endif %} {% if verb and copies %} {{ verb }} on {% for s in copies %}{{ s.name }}{% if not loop.last %} ยท {% endif %}{% endfor %} {% endif %} {% endif %} {%- endmacro %} {% macro reactions(likes, reposts, replies, bookmarks, syndications, permalink, quotes=[]) %} {% set anon_likes, anon_reposts, anon_quotes = [], [], [] %} {% 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 %} {% if s.quotes_count %}{% set _ = anon_quotes.append((s.name, s.quotes_count)) %}{% endif %} {% endfor %} {% set copies = (syndications or [])|selectattr('remote_url')|list %} {% if copies or likes or reposts or replies or quotes or bookmarks or anon_likes or anon_reposts or anon_quotes %}
{{ 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) }} {# Quotes: named ones are listed below; the card shows those without names (v2.14.2) #} {{ reaction('quote', quotes or [], '', anon_quotes, 'quote', 'quotes', people=False) }} {{ reaction('bookmark', bookmarks or [], 'u-bookmark', [], 'bookmark', 'bookmarks') }}
{% endif %} {%- endmacro %} {# Compact like / repost / reply counts for lists of notes (v2.13.4); links to the note's responses. `counts` is from webmention_queries.response_counts. #} {% macro list_counts(counts, permalink) %} {% if counts %} {%- for key, kind, one, many in [('likes', 'like', 'like', 'likes'), ('reposts', 'repost', 'repost', 'reposts'), ('replies', 'reply', 'reply', 'replies'), ('quotes', 'quote', 'quote', 'quotes')] if counts.get(key) -%} {{ ICONS[kind]|safe }}{{ counts[key] }} {{ one if counts[key] == 1 else many }} {%- endfor -%} {% endif %} {%- endmacro %}