Initial export from WebStudio.is
This commit is contained in:
34
app/routes/[sitemap.xml]._index.tsx
Normal file
34
app/routes/[sitemap.xml]._index.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
import { sitemap } from "../__generated__/$resources.sitemap.xml";
|
||||
|
||||
export const loader = (arg: LoaderFunctionArgs) => {
|
||||
const host =
|
||||
arg.request.headers.get("x-forwarded-host") ||
|
||||
arg.request.headers.get("host") ||
|
||||
"";
|
||||
|
||||
const urls = sitemap.map((page) => {
|
||||
const url = new URL(`https://${host}${page.path}`);
|
||||
|
||||
return `
|
||||
<url>
|
||||
<loc>${url.href}</loc>
|
||||
<lastmod>${page.lastModified.split("T")[0]}</lastmod>
|
||||
</url>
|
||||
`;
|
||||
});
|
||||
|
||||
return new Response(
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${urls.join("")}
|
||||
</urlset>
|
||||
`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/xml",
|
||||
},
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user