-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.js
More file actions
49 lines (42 loc) · 1.37 KB
/
route.js
File metadata and controls
49 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import cityData from "@/data/cities";
export const dynamic = 'force-static';
export const revalidate = 3600;
export async function GET() {
const baseUrl = (process.env.NEXT_PUBLIC_SITE_URL || "https://pyday.cl").replace(/\/$/, '');
// Validación de datos
if (!cityData || typeof cityData !== 'object') {
throw new Error('Datos de ciudades no encontrados');
}
// Generar URLs
const urls = [
...['', '/multimedia', '/previous', '/register', '/sponsors']
.map(path => ({
url: new URL(path, baseUrl).href,
lastModified: new Date().toISOString(),
priority: path === '' ? 1.0 : 0.8,
})),
...Object.keys(cityData).map(citySlug => ({
url: new URL(`/${citySlug}`, baseUrl).href,
lastModified: new Date().toISOString(),
priority: 0.9,
}))
];
// Generar XML
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls.map(({ url, lastModified, priority }) => `
<url>
<loc>${url}</loc>
<lastmod>${lastModified}</lastmod>
<changefreq>weekly</changefreq>
<priority>${priority}</priority>
</url>
`).join('')}
</urlset>`;
return new Response(xml, {
headers: {
'Content-Type': 'application/xml',
'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate=3600'
},
});
}