Skip to content

Commit 2640552

Browse files
committed
fix: canonical urls in sitemap
1 parent 6b8712e commit 2640552

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pages/sitemap.xml.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ export const getServerSideProps = async ({ res }: any) => {
1010
const baseDirPath = process.cwd();
1111

1212
const tree = directoryTree(baseDirPath + "/" + docsConfig.docsEntryPoint);
13-
const filePaths = getFilePaths(tree);
13+
const allFilePaths = getFilePaths(tree);
14+
const versions = Object.keys(docsConfig.versionMap);
15+
// To remove canonical urls, removing the urls with the version number
16+
const filePaths = allFilePaths?.filter((filePath) => {
17+
let flag = true;
18+
[...versions, "next"].map((version) => {
19+
if (filePath.includes(version)) {
20+
flag = false;
21+
}
22+
});
23+
return flag;
24+
});
25+
// console.log({ ...filePaths });
1426
const sitemap = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
1527
${
1628
filePaths &&

0 commit comments

Comments
 (0)