init
This commit is contained in:
37
src/pages/sitemap.xml.ts
Normal file
37
src/pages/sitemap.xml.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
|
||||
// List of all pages
|
||||
const pages = [
|
||||
'',
|
||||
'/services',
|
||||
'/contact'
|
||||
];
|
||||
|
||||
// Function to generate sitemap
|
||||
export const GET: APIRoute = async ({ site }) => {
|
||||
if (!site) {
|
||||
return new Response('Site configuration error', { status: 500 });
|
||||
}
|
||||
|
||||
const siteUrl = site.toString();
|
||||
const currentDate = new Date().toISOString().split('T')[0];
|
||||
|
||||
return new Response(
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${pages.map(page => `
|
||||
<url>
|
||||
<loc>${siteUrl}${page}</loc>
|
||||
<lastmod>${currentDate}</lastmod>
|
||||
<changefreq>${page === '' ? 'daily' : 'weekly'}</changefreq>
|
||||
<priority>${page === '' ? '1.0' : '0.7'}</priority>
|
||||
</url>
|
||||
`).join('')}
|
||||
</urlset>`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/xml',
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user