Files
blog-eleventy-indiekit/_data/githubRepos.js
Ricardo 0fe99ee5b1 perf: add timeout and watch-mode cache extension to all data files
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
2026-03-10 17:11:24 +01:00

49 lines
1.4 KiB
JavaScript

/**
* GitHub Repos Data
* Fetches public repositories from GitHub API
*/
import { cachedFetch } from "../lib/data-fetch.js";
export default async function () {
const username = process.env.GITHUB_USERNAME || "";
try {
// Fetch public repos, sorted by updated date
const url = `https://api.github.com/users/${username}/repos?sort=updated&per_page=10&type=owner`;
const repos = await cachedFetch(url, {
duration: "1h", // Cache for 1 hour
type: "json",
fetchOptions: {
headers: {
Accept: "application/vnd.github.v3+json",
"User-Agent": "Eleventy-Site",
},
},
});
// Filter and transform repos
return repos
.filter((repo) => !repo.fork && !repo.private) // Exclude forks and private repos
.map((repo) => ({
name: repo.name,
full_name: repo.full_name,
description: repo.description,
html_url: repo.html_url,
homepage: repo.homepage,
language: repo.language,
stargazers_count: repo.stargazers_count,
forks_count: repo.forks_count,
open_issues_count: repo.open_issues_count,
topics: repo.topics || [],
updated_at: repo.updated_at,
created_at: repo.created_at,
}))
.slice(0, 10); // Limit to 10 repos
} catch (error) {
console.error("Error fetching GitHub repos:", error.message);
return [];
}
}