From 064569a68e20daeacc835bb9904220e4ca0757ce Mon Sep 17 00:00:00 2001 From: David Maciejewski Date: Sun, 31 Mar 2024 17:12:36 +0200 Subject: [PATCH] refactor: Switch to sites without trailing slash --- astro.config.mjs | 5 ++++- src/components/Metadata.astro | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index edcbd6a..4c8b315 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -18,7 +18,10 @@ import rehypeSlug from 'rehype-slug' // https://astro.build/config export default defineConfig({ site: 'https://hawk-gt1191.de', - trailingSlash: 'ignore', + trailingSlash: 'never', + build: { + format: 'directory' + }, redirects: { '/komponenten': { status: 301, diff --git a/src/components/Metadata.astro b/src/components/Metadata.astro index c9534a9..e38b130 100644 --- a/src/components/Metadata.astro +++ b/src/components/Metadata.astro @@ -1,6 +1,10 @@ --- import AstroFont from '@gamesome/astro-font/AstroFont.astro' +function removeTrailingSlash(str: string) { + return str.replace(/\/+$/, '') +} + interface Props { title: string description: string @@ -13,10 +17,12 @@ interface Props { const { title, description, type = 'website', pubDate, redirect } = Astro.props -const canonicalURL = new URL(Astro.url.pathname, Astro.site) +const canonicalUrl = removeTrailingSlash( + new URL(Astro.url.pathname, Astro.site).toString() +) const openGraphImage = Astro.url.pathname.startsWith('/tutorials') - ? new URL(`${canonicalURL}og.png`, Astro.url) + ? new URL(`${canonicalUrl}/og.png`, Astro.url) : new URL('images/website-cover.png', Astro.url) --- @@ -24,7 +30,7 @@ const openGraphImage = Astro.url.pathname.startsWith('/tutorials') - + {redirect ? : null} @@ -56,7 +62,7 @@ const openGraphImage = Astro.url.pathname.startsWith('/tutorials') - + { openGraphImage && (