54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
// Динамический sitemap из всех 6 коллекций
|
|
import { getCollection } from 'astro:content';
|
|
|
|
const BASE = 'https://нейросети.рус';
|
|
|
|
function lastmod(dateStr) {
|
|
if (!dateStr) return new Date().toISOString().split('T')[0];
|
|
const d = typeof dateStr === 'string' ? new Date(dateStr) : dateStr;
|
|
return d.toISOString().split('T')[0];
|
|
}
|
|
|
|
const pages = [
|
|
{ url: '/', priority: '1.0' },
|
|
{ url: '/examples/', priority: '0.9' },
|
|
{ url: '/models/', priority: '0.9' },
|
|
{ url: '/compare/', priority: '0.8' },
|
|
{ url: '/news/', priority: '0.8' },
|
|
{ url: '/guide/', priority: '0.8' },
|
|
{ url: '/ace-studio/', priority: '0.8' },
|
|
];
|
|
|
|
export async function GET() {
|
|
const collections = ['examples', 'models', 'compare', 'news', 'guide', 'aceStudio'];
|
|
for (const name of collections) {
|
|
try {
|
|
const items = await getCollection(name);
|
|
for (const item of items) {
|
|
const slug = name === 'aceStudio' ? 'ace-studio' : name;
|
|
pages.push({
|
|
url: `/${slug}/${item.slug}/`,
|
|
priority: '0.7',
|
|
lastmod: lastmod(item.data.date),
|
|
});
|
|
}
|
|
} catch (e) {
|
|
// коллекция может быть пустой
|
|
}
|
|
}
|
|
|
|
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
${pages.map(p =>
|
|
` <url><loc>${BASE}${p.url}</loc><priority>${p.priority}</priority>${p.lastmod ? `<lastmod>${p.lastmod}</lastmod>` : ''}</url>`
|
|
).join('\n')}
|
|
</urlset>`;
|
|
|
|
return new Response(xml, {
|
|
headers: {
|
|
'Content-Type': 'application/xml; charset=utf-8',
|
|
'Cache-Control': 'public, max-age=86400',
|
|
},
|
|
});
|
|
}
|