chore: remove canonical links from sitemap

Closes #849
This commit is contained in:
Corbin Crutchley
2023-12-14 00:35:56 -08:00
parent bb00fefec2
commit 33a4e97518

View File

@@ -20,6 +20,7 @@ import * as path from "path";
import svgr from "vite-plugin-svgr"; import svgr from "vite-plugin-svgr";
import { languages } from "./src/constants/index"; import { languages } from "./src/constants/index";
import { fileToOpenGraphConverter } from "./src/utils/translations"; import { fileToOpenGraphConverter } from "./src/utils/translations";
import { posts } from "./src/utils/data";
await symlink(path.resolve("content"), path.resolve("public/content")); await symlink(path.resolve("content"), path.resolve("public/content"));
@@ -42,13 +43,17 @@ export default defineConfig({
}, {}), }, {}),
}, },
filter(page) { 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 // in which case it should not be in the sitemap
return !page const lastPartOfSlug = page
.split("/") .split("/")
.filter((part) => !!part.length) .filter((part) => !!part.length)
.at(-1) .at(-1);
.endsWith("_noindex");
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 }) { serialize({ url, ...rest }) {
return { return {