From 45a80e513d1fb75628c88a2cdd214ca3dd424edb Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 1 Feb 2023 08:54:25 +0000 Subject: [PATCH] sitemap: Remove trailing slashes from URLs --- website/astro.config.mjs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/website/astro.config.mjs b/website/astro.config.mjs index b573f2e2..7c83e27f 100644 --- a/website/astro.config.mjs +++ b/website/astro.config.mjs @@ -1,4 +1,4 @@ -import { defineConfig } from 'astro/config'; +import { defineConfig } from "astro/config"; import alpinejs from "@astrojs/alpinejs"; import tailwind from "@astrojs/tailwind"; import mdx from "@astrojs/mdx"; @@ -8,10 +8,23 @@ import sitemap from "@astrojs/sitemap"; // https://astro.build/config export default defineConfig({ - integrations: [alpinejs(), tailwind({ - config: { - applyBaseStyles: false - } - }), mdx(), sitemap()], - site: 'https://www.oliverdavies.uk' -}); \ No newline at end of file + integrations: [ + alpinejs(), + mdx(), + sitemap({ + serialize(item) { + // To prevent crawling errors, remove the trailing slash from the URL + // otherwise it will be a link to a redirect URL and not the content. + item.url = item.url.replace(/\/$/, ""); + + return item; + }, + }), + tailwind({ + config: { + applyBaseStyles: false, + }, + }), + ], + site: "https://www.oliverdavies.uk", +});