Files
sp/src/pages/sitemap.xml.ts
2025-03-19 20:42:16 +05:30

38 lines
863 B
TypeScript

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',
},
}
);
};