rsnext/examples/with-sitemap/app/sitemap.ts
archanaagivale30 b5f97ca70e
Updated with-sitemap example for App Router (#66995)
Hello

This PR updates the with-sitemap example to use:

1. App Router
2. TypeScript
3. sitemap.js

---------

Co-authored-by: Sam Ko <sam@vercel.com>
2024-06-20 09:18:56 +00:00

24 lines
580 B
TypeScript

const globby = require("globby");
function addPage(page: string) {
const path = page
.replace("app", "")
.replace(".tsx", "")
.replace(".mdx", "")
.replace("/page", "");
return path;
}
export default async function sitemap() {
const pages = await globby([
"app/**/*{.js,jsx,ts,tsx,.mdx}",
"!app/_*.js",
"!app/{sitemap,layout}.{js,jsx,ts,tsx}",
"!app/api",
]);
const routes = pages.map((page: string) => ({
url: `${process.env.WEBSITE_URL}${addPage(page)}`,
lastModified: new Date().toISOString(),
}));
return [...routes];
}