import type { RequestHandler } from './$types';

const SITE = 'https://libnovel.cc';

// Only static public pages are listed here. Book/catalogue pages are
// discoverable via the catalogue link and don't need individual entries
// (the catalogue itself serves as an index for crawlers).
const PUBLIC_PAGES = [
	{ path: '/catalogue',  changefreq: 'daily',    priority: '0.9' },
	{ path: '/login',      changefreq: 'monthly',  priority: '0.5' },
	{ path: '/disclaimer', changefreq: 'yearly',   priority: '0.2' },
	{ path: '/privacy',    changefreq: 'yearly',   priority: '0.2' },
	{ path: '/dmca',       changefreq: 'yearly',   priority: '0.2' },
];

export const GET: RequestHandler = () => {
	const urls = PUBLIC_PAGES.map(
		({ path, changefreq, priority }) => `
  <url>
    <loc>${SITE}${path}</loc>
    <changefreq>${changefreq}</changefreq>
    <priority>${priority}</priority>
  </url>`
	).join('');

	const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls}
</urlset>`;

	return new Response(xml, {
		headers: {
			'Content-Type': 'application/xml',
			'Cache-Control': 'public, max-age=86400'
		}
	});
};
