From 33a4e975182ea0cb6382a3950d533cf3fa6fca06 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Thu, 14 Dec 2023 00:35:56 -0800 Subject: [PATCH] chore: remove canonical links from sitemap Closes #849 --- astro.config.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/astro.config.ts b/astro.config.ts index 7e37fff4..b9e9f045 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -20,6 +20,7 @@ import * as path from "path"; import svgr from "vite-plugin-svgr"; import { languages } from "./src/constants/index"; import { fileToOpenGraphConverter } from "./src/utils/translations"; +import { posts } from "./src/utils/data"; await symlink(path.resolve("content"), path.resolve("public/content")); @@ -42,13 +43,17 @@ export default defineConfig({ }, {}), }, filter(page) { - // return true, unless lart part of the URL ends with "_noindex" + // return true, unless last part of the URL ends with "_noindex" // in which case it should not be in the sitemap - return !page + const lastPartOfSlug = page .split("/") .filter((part) => !!part.length) - .at(-1) - .endsWith("_noindex"); + .at(-1); + + if (lastPartOfSlug.endsWith("_noindex")) return false; + const relatedPost = posts.find((post) => post.slug === lastPartOfSlug); + if (relatedPost && relatedPost.originalLink) return false; + return true; }, serialize({ url, ...rest }) { return {