Skip to content

Commit

Permalink
fix(docs): change sitemap generation (#4193)
Browse files Browse the repository at this point in the history
* chore(docs): fix sitemap caching

* chore(docs): cahnge sitemap to use uncompiled paths

* chore(docs): add root to sitemap

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
krisantrobus and kodiakhq[bot] authored Dec 18, 2024
1 parent 58096a1 commit 6f49ba7
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/paste-website/src/pages/sitemap.xml.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import { globby } from "globby-esm";
import type { GetServerSideProps } from "next";
import { unstable_noStore as noStore } from "next/cache";

const Sitemap = (): React.ReactElement | null => {
return null;
};

export const getServerSideProps: GetServerSideProps = async ({ res }) => {
noStore();
const BASE_URL = "https://paste.twilio.design";

const paths = await globby(["**/*.js", "!sitemap.xml.js", "!404.js", "!_*.js"], {
cwd: __dirname,
});
const staticPaths = paths.map((staticPagePath) => {
const path = staticPagePath.replace(".js", "");
const route = path === "index" ? "" : `${path}/`;

return `${BASE_URL}/${route}`;
// Get a list of all pages currently in the site, must be mdx and not tsx which they all currently are
const uncompiledPaths = await globby(["**/pages/**/*.mdx", "!**/api/**", "!**/pages/404/**"]);

const urlPaths = uncompiledPaths.map((path) => {
// Remove `src/pages/`
let modifiedPath = path.replace(/^src\/pages\//, "");
// Remove `.mdx`
modifiedPath = modifiedPath.replace(/\.mdx$/, "");
// Remove `/index` if it's at the end of the path
modifiedPath = modifiedPath.replace(/\/index$/, "");
return `${BASE_URL}/${modifiedPath}`;
});

const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${staticPaths
<url>
<loc>${BASE_URL}</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
${urlPaths
.map((url) => {
return `
<url>
Expand Down

0 comments on commit 6f49ba7

Please sign in to comment.