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) => {