From 3337ee668e8a8674eff0394df1918bd4c2d527f4 Mon Sep 17 00:00:00 2001 From: Misael Taveras Date: Wed, 27 Dec 2023 12:05:35 -0400 Subject: [PATCH] refact: add console.logs to avoid false warnings Known astro-lang issue => https://github.com/withastro/language-tools/issues/476 --- src/pages/[...slug].astro | 8 ++++---- src/pages/index.astro | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 72c75ae..dd4a13a 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -16,8 +16,8 @@ if (!collectionName || collectionName !== "blog") { return Astro.redirect(`/404?from=${slug}`); } const postFound = await getCollection(collectionName, ({ slug }) => slug.includes(name)); - -return postFound.length - ? Astro.redirect(getEntryURL(collectionName, postFound[0].slug), 301 /* Moved Permanently */) - : Astro.redirect(`/404?from=${slug}`); +const knownPostURL = postFound.length ? getEntryURL(collectionName, postFound[0].slug) : null; +// KI: To supress `astro:check` warning -- https://github.com/withastro/language-tools/issues/476 +console.log(`knownPostURL: ${knownPostURL}`); +return knownPostURL ? Astro.redirect(knownPostURL, 301 /* Moved Permanently */) : Astro.redirect(`/404?from=${slug}`); --- diff --git a/src/pages/index.astro b/src/pages/index.astro index 5f667ec..aafe56b 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -6,6 +6,8 @@ const headerLang = Astro.request.headers.get("accept-language"); if (headerLang) { const browserLang = headerLang.split(",")[0].split("-")[0]; const lang = isSupportedLang(browserLang) ? browserLang : DEFAULT_LOCALE; + // KI: To supress `astro:check` warning -- https://github.com/withastro/language-tools/issues/476 + console.log(`Redirecting to ${lang}`) return Astro.redirect(`/${lang}`); }