From fe566c939c836a72c86ba8c4238821bf46a2ea4c Mon Sep 17 00:00:00 2001 From: Kristian Antrobus Date: Mon, 16 Dec 2024 11:19:02 -0600 Subject: [PATCH 1/3] chore(docs): fix sitemap caching --- packages/paste-website/src/pages/sitemap.xml.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/paste-website/src/pages/sitemap.xml.tsx b/packages/paste-website/src/pages/sitemap.xml.tsx index 10033d0b4a..9e888971ac 100644 --- a/packages/paste-website/src/pages/sitemap.xml.tsx +++ b/packages/paste-website/src/pages/sitemap.xml.tsx @@ -1,16 +1,19 @@ 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}/`; From 1745ac2a21c10b0a2eb02e51e29f896cacc234bd Mon Sep 17 00:00:00 2001 From: Kristian Antrobus Date: Tue, 17 Dec 2024 11:16:37 -0600 Subject: [PATCH 2/3] chore(docs): cahnge sitemap to use uncompiled paths --- .../paste-website/src/pages/sitemap.xml.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/paste-website/src/pages/sitemap.xml.tsx b/packages/paste-website/src/pages/sitemap.xml.tsx index 9e888971ac..efa34f0686 100644 --- a/packages/paste-website/src/pages/sitemap.xml.tsx +++ b/packages/paste-website/src/pages/sitemap.xml.tsx @@ -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 = ` - ${staticPaths + ${urlPaths .map((url) => { return ` From 8e13c3529e256c65a9654944611c7c7e1ed98d80 Mon Sep 17 00:00:00 2001 From: Kristian Antrobus Date: Tue, 17 Dec 2024 12:15:33 -0600 Subject: [PATCH 3/3] chore(docs): add root to sitemap --- packages/paste-website/src/pages/sitemap.xml.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/paste-website/src/pages/sitemap.xml.tsx b/packages/paste-website/src/pages/sitemap.xml.tsx index efa34f0686..b858aebcdc 100644 --- a/packages/paste-website/src/pages/sitemap.xml.tsx +++ b/packages/paste-website/src/pages/sitemap.xml.tsx @@ -25,6 +25,11 @@ export const getServerSideProps: GetServerSideProps = async ({ res }) => { const sitemap = ` + + ${BASE_URL} + daily + 0.7 + ${urlPaths .map((url) => { return `