fix: use proper User-Agent for unfurl requests

The default facebookexternalhit UA causes many sites to block or
redirect-loop, resulting in timeouts. Switch to a well-identified
bot UA that sites handle correctly.
This commit is contained in:
Ricardo
2026-02-20 12:31:42 +01:00
parent e0cbf8121e
commit 41c7fae2f1

View File

@@ -6,6 +6,7 @@ import { createHash } from "crypto";
const CACHE_DIR = resolve(import.meta.dirname, "..", ".cache", "unfurl");
const CACHE_DURATION_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
const FAILURE_CACHE_MS = 24 * 60 * 60 * 1000; // 1 day for failed fetches
const USER_AGENT = "Mozilla/5.0 (compatible; Indiekit/1.0; +https://getindiekit.com)";
// Concurrency limiter — prevents overwhelming outbound network
let activeRequests = 0;
@@ -135,7 +136,10 @@ export default function registerUnfurlShortcode(eleventyConfig) {
// Not cached — fetch with concurrency limiting
const metadata = await throttled(async () => {
try {
return await unfurl(url, { timeout: 20000 });
return await unfurl(url, {
timeout: 20000,
headers: { "User-Agent": USER_AGENT },
});
} catch (err) {
console.warn(`[unfurl] Failed to fetch ${url}: ${err.message}`);
return null;