Skip to content

Commit

Permalink
chore(docs): cahnge sitemap to use uncompiled paths
Browse files Browse the repository at this point in the history
  • Loading branch information
krisantrobus committed Dec 17, 2024
1 parent fe566c9 commit 1745ac2
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/paste-website/src/pages/sitemap.xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ 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
${urlPaths
.map((url) => {
return `
<url>
Expand Down

0 comments on commit 1745ac2

Please sign in to comment.