From d6a073d234d060dae2f25d689ab1d566b2d9c6dc Mon Sep 17 00:00:00 2001 From: Adrian Altner Date: Wed, 22 Apr 2026 02:31:35 +0200 Subject: [PATCH] Refactor fetchMentions function to enhance token handling and debug information --- src/components/Webmentions.astro | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Webmentions.astro b/src/components/Webmentions.astro index 82cbd24..47e6e55 100644 --- a/src/components/Webmentions.astro +++ b/src/components/Webmentions.astro @@ -30,9 +30,12 @@ interface FetchResult { } async function fetchMentions(target: string): Promise { - const token = import.meta.env.WEBMENTION_TOKEN; - const tokenLen = typeof token === 'string' ? token.length : 0; - if (!token) return { mentions: [], debug: `no-token(len=${tokenLen})` }; + 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; + const pLen = typeof processToken === 'string' ? processToken.length : 0; + if (!token) return { mentions: [], debug: `no-token(iml=${iLen},pe=${pLen})` }; const withSlash = target.endsWith('/') ? target : `${target}/`; const withoutSlash = target.replace(/\/+$/, ''); const fetchOne = async (t: string) => { @@ -56,7 +59,7 @@ async function fetchMentions(target: string): Promise { } return { mentions: merged, - debug: `len=${tokenLen} slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`, + debug: `iml=${iLen} pe=${pLen} slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`, }; }