Skip to content

Commit 4fd5da2

Browse files
authored
implement sitemap.xml (stack-auth#815)
1 parent e79ebda commit 4fd5da2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/src/app/sitemap.xml/route.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { apiSource, source } from '../../../lib/source';
2+
3+
export const GET = async () => {
4+
const rootUrl = "https://docs.stack-auth.com";
5+
6+
// Get pages from both sources
7+
const docsPages = source.getPages();
8+
const apiPages = apiSource.getPages();
9+
const allPages = [...docsPages, ...apiPages];
10+
11+
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
12+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
13+
${allPages
14+
.map((page) => {
15+
const url = new URL(page.url, rootUrl);
16+
return ` <url>
17+
<loc>${url.toString()}</loc>
18+
<changefreq>weekly</changefreq>
19+
<priority>0.8</priority>
20+
</url>`;
21+
})
22+
.join("\n")}
23+
</urlset>`;
24+
25+
return new Response(sitemap, {
26+
headers: {
27+
"Content-Type": "application/xml",
28+
"Cache-Control": "public, max-age=3600",
29+
},
30+
});
31+
};

0 commit comments

Comments
 (0)