mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 08:44:56 +02:00
Introduce shared cachedFetch helper (lib/data-fetch.js) wrapping EleventyFetch with two protections: - 10-second hard timeout via AbortController on every network request, preventing slow or unresponsive APIs from hanging the build - 4-hour cache TTL in watch/serve mode (vs 5-15 min originals), so incremental rebuilds serve from disk cache instead of re-fetching APIs every time a markdown file changes All 13 network _data files updated to use cachedFetch. Production builds keep original short TTLs for fresh data. Targets the "Data File" benchmark (12,169ms / 32% of incremental rebuild) — the largest remaining bottleneck after filter memoization. Confab-Link: http://localhost:8080/sessions/0b241cd6-aff2-4fec-853c-2b5a61e61946
25 lines
708 B
JavaScript
25 lines
708 B
JavaScript
/**
|
|
* Recent Comments Data
|
|
* Fetches the 5 most recent comments at build time for the sidebar widget.
|
|
*/
|
|
|
|
import { cachedFetch } from "../lib/data-fetch.js";
|
|
|
|
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
|
|
|
|
export default async function () {
|
|
try {
|
|
const url = `${INDIEKIT_URL}/comments/api/comments?limit=5`;
|
|
console.log(`[recentComments] Fetching: ${url}`);
|
|
const data = await cachedFetch(url, {
|
|
duration: "15m",
|
|
type: "json",
|
|
});
|
|
console.log(`[recentComments] Got ${(data.children || []).length} comments`);
|
|
return data.children || [];
|
|
} catch (error) {
|
|
console.log(`[recentComments] Unavailable: ${error.message}`);
|
|
return [];
|
|
}
|
|
}
|