100 lines
2.4 KiB
TypeScript
100 lines
2.4 KiB
TypeScript
import type { APIRoute } from 'astro';
|
|
import {
|
|
getEnv,
|
|
generateSitemapXml,
|
|
inferChangeFreq,
|
|
inferPriority,
|
|
type SitemapUrl
|
|
} from '../lib/astro-helpers';
|
|
import { listDocuments } from '../lib/documents';
|
|
|
|
/**
|
|
* Dynamiczny sitemap generator
|
|
* GET /sitemap.xml
|
|
*/
|
|
export const GET: APIRoute = async ({ site }) => {
|
|
const base = site?.toString().replace(/\/$/, '') ||
|
|
getEnv('PUBLIC_SITE_URL') ||
|
|
"https://www.fuz.pl";
|
|
|
|
const now = new Date().toISOString();
|
|
const urls: SitemapUrl[] = [];
|
|
|
|
// ========================================
|
|
// STATYCZNE STRONY
|
|
// ========================================
|
|
const staticPages = [
|
|
'/',
|
|
'/internet-swiatlowodowy',
|
|
'/internet-telewizja',
|
|
'/telefon',
|
|
'/mapa-zasiegu',
|
|
'/kontakt',
|
|
'/dokumenty',
|
|
'/premium',
|
|
'/telewizja-mozliwosci',
|
|
];
|
|
|
|
staticPages.forEach(path => {
|
|
urls.push({
|
|
loc: `${base}${path}`,
|
|
lastmod: now,
|
|
changefreq: inferChangeFreq(path),
|
|
priority: inferPriority(path),
|
|
});
|
|
});
|
|
|
|
// ========================================
|
|
// DYNAMICZNE STRONY: Dokumenty
|
|
// ========================================
|
|
try {
|
|
const docs = listDocuments();
|
|
|
|
docs
|
|
.filter(d => d.visible === true)
|
|
.forEach(d => {
|
|
const path = `/dokumenty/${d.slug}`;
|
|
urls.push({
|
|
loc: `${base}${path}`,
|
|
lastmod: now,
|
|
changefreq: 'yearly',
|
|
priority: 0.5,
|
|
});
|
|
});
|
|
} catch (e) {
|
|
console.warn('⚠️ Sitemap: Could not load documents:', e);
|
|
}
|
|
|
|
// ========================================
|
|
// DYNAMICZNE STRONY: Premium packages (opcjonalnie)
|
|
// ========================================
|
|
// TODO: Jeśli masz dynamiczne pakiety premium, dodaj tutaj:
|
|
/*
|
|
try {
|
|
const packages = await loadPremiumPackages();
|
|
packages.forEach(p => {
|
|
urls.push({
|
|
loc: `${base}/premium/${p.tid}`,
|
|
lastmod: now,
|
|
changefreq: 'monthly',
|
|
priority: 0.7,
|
|
});
|
|
});
|
|
} catch (e) {
|
|
console.warn('⚠️ Sitemap: Could not load premium packages:', e);
|
|
}
|
|
*/
|
|
|
|
// ========================================
|
|
// GENERUJ XML
|
|
// ========================================
|
|
const sitemap = generateSitemapXml(urls);
|
|
|
|
return new Response(sitemap, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'application/xml; charset=utf-8',
|
|
'Cache-Control': 'public, max-age=3600', // 1h cache
|
|
},
|
|
});
|
|
}; |