48b6d920c4
Key changes merged from svemagie/blog-eleventy-indiekit: - feat: /updated.xml feed for recently edited posts - feat: sitemap.xml generation in eleventy.after hook - feat: excludePostTypes filter for homepage section config - feat: view mode toggle (repo/type) for changelog page - feat: replyTargets config for platform-to-syndicator mapping - feat: syndication badge + linked timestamp on owner replies - perf: memoize aiPosts/aiStats/hash filters; batch unfurl pre-fetch - perf: clear eleventy-img in-memory cache between builds (OOM fix) - perf: memory profiler (logMemory) at build phases - perf: OG batch tracking (totalGenerated/batch counters) - fix: h-entry u-url absolute for IndieNews compatibility - fix: webmention platform detection in build-time templates - fix: deduplicate interactions via interactionKey - fix: reply form syndication via replyTargets (not hardcoded platforms) - fix: remove skeleton loader CSS (CLS fix) - fix: avatar dimensions 96→128 to match CSS classes - css: remove unused skeleton loader rules Local customisations preserved: - Gitea-based data files (githubActivity, githubRepos, githubStarred) - Funkwhale cover image cache copy in eleventy.after - URL fallback arrays in funkwhale/lastfm data fetchers - CONFIGURABLE cache durations (FUNKWHALE_FETCH_CACHE_DURATION etc.) - OG_CACHE_DIR naming (not cacheDir) - Our ogSlug format (plain slug, not date-prefixed) - Gruvbox design tokens (link colours, selection colours) - Unfurl manifest optimisation (skip re-fetching known URLs) - CLAUDE.md, README.md, .github/workflows (ours) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
117 lines
3.2 KiB
JavaScript
117 lines
3.2 KiB
JavaScript
/**
|
|
* Mastodon Feed Data
|
|
* Fetches recent posts from Mastodon using the public API
|
|
*/
|
|
|
|
import { cachedFetch } from "../lib/data-fetch.js";
|
|
|
|
export default async function () {
|
|
const instance = (
|
|
process.env.MASTODON_URL ||
|
|
process.env.MASTODON_INSTANCE ||
|
|
""
|
|
)
|
|
.replace(/^https?:\/\//, "")
|
|
.replace(/\/+$/, "");
|
|
const username = (
|
|
process.env.MASTODON_USER ||
|
|
process.env.MASTODON_USERNAME ||
|
|
""
|
|
).trim().replace(/^@+/, "");
|
|
|
|
if (!instance || !username) {
|
|
console.log("[mastodonFeed] MASTODON_URL/MASTODON_USER not set, skipping");
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
// First, look up the account ID
|
|
const lookupUrl = `https://${instance}/api/v1/accounts/lookup?acct=${username}`;
|
|
|
|
const account = await cachedFetch(lookupUrl, {
|
|
duration: "1h", // Cache account lookup for 1 hour
|
|
type: "json",
|
|
fetchOptions: {
|
|
headers: {
|
|
Accept: "application/json",
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!account || !account.id) {
|
|
console.log("Mastodon account not found:", username);
|
|
return [];
|
|
}
|
|
|
|
// Fetch recent statuses (excluding replies; boosts included since that's primary activity)
|
|
const statusesUrl = `https://${instance}/api/v1/accounts/${account.id}/statuses?limit=10&exclude_replies=true`;
|
|
|
|
const statuses = await cachedFetch(statusesUrl, {
|
|
duration: "15m", // Cache for 15 minutes
|
|
type: "json",
|
|
fetchOptions: {
|
|
headers: {
|
|
Accept: "application/json",
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!statuses || !Array.isArray(statuses)) {
|
|
console.log("No Mastodon statuses found for:", username);
|
|
return [];
|
|
}
|
|
|
|
// Transform statuses into a simpler format; for boosts use the reblogged post's content
|
|
return statuses.map((status) => {
|
|
const isBoost = !!status.reblog;
|
|
const source = isBoost ? status.reblog : status;
|
|
return {
|
|
id: status.id,
|
|
url: source.url,
|
|
text: stripHtml(source.content),
|
|
htmlContent: source.content,
|
|
createdAt: status.created_at,
|
|
isBoost,
|
|
author: {
|
|
username: source.account.username,
|
|
displayName: source.account.display_name || source.account.username,
|
|
avatar: source.account.avatar,
|
|
url: source.account.url,
|
|
},
|
|
favouritesCount: source.favourites_count || 0,
|
|
reblogsCount: source.reblogs_count || 0,
|
|
repliesCount: source.replies_count || 0,
|
|
// Media attachments
|
|
media: source.media_attachments
|
|
? source.media_attachments.map((m) => ({
|
|
type: m.type,
|
|
url: m.url,
|
|
previewUrl: m.preview_url,
|
|
description: m.description,
|
|
}))
|
|
: [],
|
|
};
|
|
});
|
|
} catch (error) {
|
|
console.error("Error fetching Mastodon feed:", error.message);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// Simple HTML stripper for plain text display
|
|
function stripHtml(html) {
|
|
if (!html) return "";
|
|
return html
|
|
.replace(/<br\s*\/?>/gi, " ")
|
|
.replace(/<\/p>/gi, " ")
|
|
.replace(/<[^>]+>/g, "")
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, "'")
|
|
.replace(/ /g, " ")
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
}
|