feat: add textcasting support, feed attachments, and protocol badges

- Add _textcasting extension to JSON feed with support/monetization config
- Add feedAttachments filter for photo/audio/video media in feed items
- Add content_text and date_modified fields to feed items
- Add protocol badges (ATmosphere, Fediverse, Web) on reply posts
- Add support configuration via environment variables in site data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
rmdes
2026-02-18 08:42:59 +01:00
parent fe06fe3f4f
commit afc394525b
4 changed files with 121 additions and 4 deletions

View File

@@ -101,4 +101,12 @@ export default {
// Fediverse creator for meta tag (e.g., @rmdes@mstdn.social)
fediverseCreator: getMastodonHandle(),
// Support/monetization configuration (used in _textcasting JSON Feed extension)
support: {
url: process.env.SUPPORT_URL || null,
stripe: process.env.SUPPORT_STRIPE_URL || null,
lightning: process.env.SUPPORT_LIGHTNING_ADDRESS || null,
paymentPointer: process.env.SUPPORT_PAYMENT_POINTER || null,
},
};

View File

@@ -69,6 +69,78 @@ export default function (eleventyConfig) {
return JSON.stringify(value);
});
// Guess MIME type from URL extension
function guessMimeType(url, category) {
const lower = (typeof url === "string" ? url : "").toLowerCase();
if (category === "photo") {
if (lower.includes(".png")) return "image/png";
if (lower.includes(".gif")) return "image/gif";
if (lower.includes(".webp")) return "image/webp";
if (lower.includes(".svg")) return "image/svg+xml";
return "image/jpeg";
}
if (category === "audio") {
if (lower.includes(".ogg") || lower.includes(".opus")) return "audio/ogg";
if (lower.includes(".flac")) return "audio/flac";
if (lower.includes(".wav")) return "audio/wav";
return "audio/mpeg";
}
if (category === "video") {
if (lower.includes(".webm")) return "video/webm";
if (lower.includes(".mov")) return "video/quicktime";
return "video/mp4";
}
return "application/octet-stream";
}
// Extract URL string from value that may be a string or {url, alt} object
function resolveMediaUrl(value) {
if (typeof value === "string") return value;
if (value && typeof value === "object" && value.url) return value.url;
return null;
}
// Feed attachments filter — builds JSON Feed attachments array from post data
eleventyConfig.addFilter("feedAttachments", (postData) => {
const attachments = [];
const processMedia = (items, category) => {
const list = Array.isArray(items) ? items : [items];
for (const item of list) {
const rawUrl = resolveMediaUrl(item);
if (!rawUrl) continue;
const url = rawUrl.startsWith("http") ? rawUrl : `${siteUrl}${rawUrl}`;
attachments.push({ url, mime_type: guessMimeType(rawUrl, category) });
}
};
if (postData.photo) processMedia(postData.photo, "photo");
if (postData.audio) processMedia(postData.audio, "audio");
if (postData.video) processMedia(postData.video, "video");
return attachments;
});
// Textcasting support filter — builds clean support object excluding null values
eleventyConfig.addFilter("textcastingSupport", (support) => {
if (!support) return {};
const obj = {};
if (support.url) obj.url = support.url;
if (support.stripe) obj.stripe = support.stripe;
if (support.lightning) obj.lightning = support.lightning;
if (support.paymentPointer) obj.payment_pointer = support.paymentPointer;
return obj;
});
// Protocol type filter — classifies a URL by its origin protocol/network
eleventyConfig.addFilter("protocolType", (url) => {
if (!url || typeof url !== "string") return "web";
const lower = url.toLowerCase();
if (lower.includes("bsky.app") || lower.includes("bluesky")) return "atmosphere";
// Match Fediverse instances by known domain patterns (avoid overly broad "social")
if (lower.includes("mastodon.") || lower.includes("mstdn.") || lower.includes("fosstodon.") ||
lower.includes("pleroma.") || lower.includes("misskey.") || lower.includes("pixelfed.") ||
lower.includes("fediverse")) return "fediverse";
return "web";
});
// Email obfuscation filter - converts email to HTML entities
// Blocks ~95% of spam harvesters while remaining valid for microformat parsers
// Usage: {{ email | obfuscateEmail }} or {{ email | obfuscateEmail("href") }}

View File

@@ -21,6 +21,14 @@ eleventyExcludeFromCollections: true
"url": "{{ site.url }}/"
}
],
"_textcasting": {
"version": "1.0",
"about": "https://textcasting.org/"
{%- set hasSupport = site.support and (site.support.url or site.support.stripe or site.support.lightning or site.support.paymentPointer) %}
{%- if hasSupport %},
"support": {{ site.support | textcastingSupport | jsonEncode | safe }}
{%- endif %}
},
"items": [
{%- for post in collections.feed %}
{%- set absolutePostUrl = site.url + post.url %}
@@ -37,12 +45,18 @@ eleventyExcludeFromCollections: true
{
"id": "{{ absolutePostUrl }}",
"url": "{{ absolutePostUrl }}",
"title": {{ post.data.title | default(post.content | striptags | truncate(80)) | jsonEncode | safe }},
"title": {% if post.data.title %}{{ post.data.title | jsonEncode | safe }}{% else %}null{% endif %},
"content_html": {{ post.content | htmlToAbsoluteUrls(absolutePostUrl) | jsonEncode | safe }},
"date_published": "{{ post.date | dateToRfc3339 }}"
"content_text": {{ post.content | striptags | jsonEncode | safe }},
"date_published": "{{ post.date | dateToRfc3339 }}",
"date_modified": "{{ (post.data.updated or post.date) | dateToRfc3339 }}"
{%- if postImage and postImage != "" and (postImage | length) > 10 %},
"image": "{{ postImage | url | absoluteUrl(site.url) }}"
{%- endif %}
{%- set attachments = post.data | feedAttachments %}
{%- if attachments.length > 0 %},
"attachments": {{ attachments | jsonEncode | safe }}
{%- endif %}
}{% if not loop.last %},{% endif %}
{%- endfor %}
]

View File

@@ -51,11 +51,34 @@ permalink: "replies/{% if pagination.pageNumber > 0 %}page/{{ pagination.pageNum
{# Support both camelCase (Indiekit Eleventy preset) and underscore (legacy) property names #}
{% set replyTo = post.data.inReplyTo or post.data.in_reply_to %}
{% if replyTo %}
<p class="mt-2 text-sm">
{% set protocol = replyTo | protocolType %}
<p class="mt-2 text-sm flex items-center gap-2 flex-wrap">
<span class="text-surface-500">In reply to:</span>
<a class="u-in-reply-to text-primary-600 dark:text-primary-400 hover:underline break-all" href="{{ replyTo }}">
{{ replyTo }}
{{ replyTo | replace("https://", "") | replace("http://", "") | truncate(60) }}
</a>
{% if protocol == "atmosphere" %}
<span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-[#0085ff]/10 text-[#0085ff] text-xs font-medium">
<svg class="w-3 h-3" viewBox="0 0 568 501" fill="currentColor" aria-hidden="true">
<path d="M123.121 33.664C188.241 82.553 258.281 181.68 284 234.873c25.719-53.192 95.759-152.32 160.879-201.21C491.866-1.611 568-28.906 568 57.947c0 17.346-9.945 145.713-15.778 166.555-20.275 72.453-94.155 90.933-159.875 79.748C507.222 323.8 536.444 388.56 473.333 453.32c-119.86 122.992-172.272-30.859-185.702-70.281-2.462-7.227-3.614-10.608-3.631-7.733-.017-2.875-1.169.506-3.631 7.733-13.43 39.422-65.842 193.273-185.702 70.281-63.111-64.76-33.89-129.52 80.986-149.071-65.72 11.185-139.6-7.295-159.875-79.748C9.945 203.659 0 75.291 0 57.946 0-28.906 76.135-1.612 123.121 33.664Z"/>
</svg>
via ATmosphere
</span>
{% elif protocol == "fediverse" %}
<span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-[#6364ff]/10 text-[#6364ff] text-xs font-medium">
<svg class="w-3 h-3" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path d="M23.268 5.313c-.35-2.578-2.617-4.61-5.304-5.004C17.51.242 15.792 0 11.813 0h-.03c-3.98 0-4.835.242-5.288.309C3.882.692 1.496 2.518.917 5.127.64 6.412.61 7.837.661 9.143c.074 1.874.088 3.745.26 5.611.118 1.24.325 2.47.62 3.68.55 2.237 2.777 4.098 4.96 4.857 2.336.792 4.849.923 7.256.38.265-.061.527-.132.786-.213.585-.184 1.27-.39 1.774-.753a.057.057 0 0 0 .023-.043v-1.809a.052.052 0 0 0-.02-.041.053.053 0 0 0-.046-.01 20.282 20.282 0 0 1-4.709.545c-2.73 0-3.463-1.284-3.674-1.818a5.593 5.593 0 0 1-.319-1.433.053.053 0 0 1 .066-.054c1.517.363 3.072.546 4.632.546.376 0 .75 0 1.125-.01 1.57-.044 3.224-.124 4.768-.422.038-.008.077-.015.11-.024 2.435-.464 4.753-1.92 4.989-5.604.008-.145.03-1.52.03-1.67.002-.512.167-3.63-.024-5.545zm-3.748 9.195h-2.561V8.29c0-1.309-.55-1.976-1.67-1.976-1.23 0-1.846.79-1.846 2.35v3.403h-2.546V8.663c0-1.56-.617-2.35-1.848-2.35-1.112 0-1.668.668-1.668 1.977v6.218H4.822V8.102c0-1.31.337-2.35 1.011-3.12.696-.77 1.608-1.164 2.74-1.164 1.311 0 2.302.5 2.962 1.498l.638 1.06.638-1.06c.66-.999 1.65-1.498 2.96-1.498 1.13 0 2.043.395 2.74 1.164.675.77 1.012 1.81 1.012 3.12z"/>
</svg>
via Fediverse
</span>
{% else %}
<span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-surface-100 dark:bg-surface-800 text-surface-600 dark:text-surface-300 text-xs font-medium">
<svg class="w-3 h-3" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/>
</svg>
via Web
</span>
{% endif %}
</p>
{% endif %}
<div class="e-content prose dark:prose-invert prose-sm mt-3 max-w-none">