Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): change sitemap generation #4193

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading