From 41c7fae2f1152fd3e9c0aafaf245aa7341dfb4bd Mon Sep 17 00:00:00 2001 From: Ricardo Date: Fri, 20 Feb 2026 12:31:42 +0100 Subject: [PATCH] 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. --- lib/unfurl-shortcode.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/unfurl-shortcode.js b/lib/unfurl-shortcode.js index 9173fec..b196e69 100644 --- a/lib/unfurl-shortcode.js +++ b/lib/unfurl-shortcode.js @@ -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;