Files
indiekit-blog/_data/newsActivity.js
svemagie a166af2306 chore: sync upstream — performance, webmentions v2, OG v3
- _data: switch to cachedFetch wrapper (10s timeout + 4h watch cache)
- js/webmentions.js: owner reply threading, platform provenance badges, DOM dedup, Micropub reply support
- js/comments.js: owner detection, reply system, Alpine.store integration
- _includes/components/webmentions.njk: data-wm-* attrs, provenance badge slots, reply buttons
- _includes/components/comments.njk: owner-aware comment form, threaded replies
- widgets/toc.njk: Alpine.js tocScanner upgrade (replaces is-land/inline-JS)
- lib/og.js + og-cli.js: OG card v3 (light theme, avatar, batched spawn, DESIGN_VERSION=3)
- eleventy.config.js: hasOgImage cache, memoized date filters, batched OG/unfurl, post-build GC, YouTube check opt
- base.njk: Inter font preloads + toc-scanner.js script
- critical.css: font-face declarations (font-display:optional)
- tailwind.css: font-display swap→optional
- tailwind.config.js: prose link colors -700→-600
- Color design system: accent-700/300 → accent-600/400 across components

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 23:56:56 +01:00

100 lines
2.5 KiB
JavaScript

/**
* News/RSS Activity Data
* Fetches from Indiekit's endpoint-rss public API
*/
import { cachedFetch } from "../lib/data-fetch.js";
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
/**
* Fetch from Indiekit's public RSS API endpoint
*/
async function fetchFromIndiekit(endpoint) {
try {
const url = `${INDIEKIT_URL}/rssapi/api/${endpoint}`;
console.log(`[newsActivity] Fetching from Indiekit: ${url}`);
const data = await cachedFetch(url, {
duration: "15m",
type: "json",
});
console.log(`[newsActivity] Indiekit ${endpoint} success`);
return data;
} catch (error) {
console.log(
`[newsActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
);
return null;
}
}
export default async function () {
try {
console.log("[newsActivity] Fetching RSS feed data...");
// Fetch all data from Indiekit API
const [itemsRes, feedsRes, statusRes] = await Promise.all([
fetchFromIndiekit("items?limit=50"),
fetchFromIndiekit("feeds"),
fetchFromIndiekit("status"),
]);
// Check if we got data
const hasData = itemsRes?.items?.length || feedsRes?.feeds?.length;
if (!hasData) {
console.log("[newsActivity] No data available from Indiekit");
return {
items: [],
feeds: [],
status: null,
lastUpdated: null,
source: "unavailable",
};
}
console.log(
`[newsActivity] Got ${itemsRes?.items?.length || 0} items from ${feedsRes?.feeds?.length || 0} feeds`
);
// Create a map of feed IDs to feed info for quick lookup
const feedMap = new Map();
for (const feed of feedsRes?.feeds || []) {
feedMap.set(feed.id, feed);
}
// Enhance items with additional feed info
const items = (itemsRes?.items || []).map((item) => {
const feed = feedMap.get(item.feedId);
return {
...item,
feedInfo: feed
? {
title: feed.title,
siteUrl: feed.siteUrl,
imageUrl: feed.imageUrl,
}
: null,
};
});
return {
items,
feeds: feedsRes?.feeds || [],
pagination: itemsRes?.pagination || null,
status: statusRes || null,
lastUpdated: statusRes?.lastSync || new Date().toISOString(),
source: "indiekit",
};
} catch (error) {
console.error("[newsActivity] Error:", error.message);
return {
items: [],
feeds: [],
status: null,
lastUpdated: null,
source: "error",
};
}
}