From 1a3e4bf64a62b398a1e5e9cec3264c3691e45fa5 Mon Sep 17 00:00:00 2001 From: Adrian Altner Date: Wed, 22 Apr 2026 02:41:14 +0200 Subject: [PATCH] Refactor fetchMentions function to improve token handling and debug output --- src/components/Webmentions.astro | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/Webmentions.astro b/src/components/Webmentions.astro index 47e6e55..14b5e1f 100644 --- a/src/components/Webmentions.astro +++ b/src/components/Webmentions.astro @@ -30,12 +30,15 @@ interface FetchResult { } async function fetchMentions(target: string): Promise { - const importMetaToken = import.meta.env.WEBMENTION_TOKEN; - const processToken = typeof process !== 'undefined' ? process.env.WEBMENTION_TOKEN : undefined; - const token = importMetaToken || processToken; - const iLen = typeof importMetaToken === 'string' ? importMetaToken.length : 0; + // Bracket notation prevents Vite from statically replacing at build time. + const envKey = 'WEBMENTION_TOKEN'; + const processToken = + typeof process !== 'undefined' ? (process.env as Record)[envKey] : undefined; + const importMetaToken = (import.meta.env as Record)[envKey]; + const token = processToken || importMetaToken; const pLen = typeof processToken === 'string' ? processToken.length : 0; - if (!token) return { mentions: [], debug: `no-token(iml=${iLen},pe=${pLen})` }; + const iLen = typeof importMetaToken === 'string' ? importMetaToken.length : 0; + if (!token) return { mentions: [], debug: `no-token(pe=${pLen},iml=${iLen})` }; const withSlash = target.endsWith('/') ? target : `${target}/`; const withoutSlash = target.replace(/\/+$/, ''); const fetchOne = async (t: string) => {