Skip to content

Commit

Permalink
chore(docs): fix sitemap (#4200)
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

* chore(docs): test different sitemap

* chore(docs): test different sitemap

* chore(docs): attempt moving readme file

* chore(docs): use cwd

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): debug

* chore(docs): final sitemap

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
krisantrobus and kodiakhq[bot] authored Jan 8, 2025
1 parent c128d63 commit 357f378
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/sitemap-vrt/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export const SITEMAP = [
"/tokens/",
];

const SITEMAP_CHUNKS: string[][] = [];
const SITEMAP_CHUNKS = [];
const CHUNK_SIZE = 25;

for (let i = 0, len = SITEMAP.length; i < len; i += CHUNK_SIZE) {
Expand Down
33 changes: 6 additions & 27 deletions packages/paste-website/src/pages/sitemap.xml.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,25 @@
import { globby } from "globby-esm";
import type { GetServerSideProps } from "next";
import { unstable_noStore as noStore } from "next/cache";

import { SITEMAP } from "../../../../cypress/integration/sitemap-vrt/constants"; // Import the SITEMAP used for cypress

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

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

// 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">
<url>
<loc>${BASE_URL}</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
${urlPaths
.map((url) => {
return `
${SITEMAP.map((url) => {
return `
<url>
<loc>${url}</loc>
<loc>${BASE_URL}${url}</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
`;
})
.join("")}
}).join("")}
</urlset>
`;

Expand Down

0 comments on commit 357f378

Please sign in to comment.