sitemap: Remove trailing slashes from URLs

This commit is contained in:
Oliver Davies 2023-02-01 08:54:25 +00:00
parent 12ab12af72
commit 45a80e513d

View file

@ -1,4 +1,4 @@
import { defineConfig } from 'astro/config'; import { defineConfig } from "astro/config";
import alpinejs from "@astrojs/alpinejs"; import alpinejs from "@astrojs/alpinejs";
import tailwind from "@astrojs/tailwind"; import tailwind from "@astrojs/tailwind";
import mdx from "@astrojs/mdx"; import mdx from "@astrojs/mdx";
@ -8,10 +8,23 @@ import sitemap from "@astrojs/sitemap";
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [alpinejs(), tailwind({ 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: { config: {
applyBaseStyles: false applyBaseStyles: false,
} },
}), mdx(), sitemap()], }),
site: 'https://www.oliverdavies.uk' ],
site: "https://www.oliverdavies.uk",
}); });