<?php
require __DIR__ . '/includes/bootstrap.php';
header('Content-Type: application/xml; charset=utf-8');
header('Cache-Control: public, max-age=3600');
function sxe($value) { return htmlspecialchars((string) $value, ENT_XML1 | ENT_QUOTES, 'UTF-8'); }
$files = [__FILE__, __DIR__.'/config/site.php'];
$mtime = 0; foreach ($files as $f) if (is_file($f)) $mtime = max($mtime, (int) filemtime($f));
$lastmod = gmdate('Y-m-d', $mtime ?: time());
$urls = [
    ['/', '1.0', 'weekly'], ['/tools', '0.9', 'weekly'], ['/about', '0.6', 'monthly'],
    ['/architecture', '0.6', 'monthly'], ['/privacy', '0.4', 'monthly'], ['/terms', '0.3', 'monthly'],
    ['/disclaimer', '0.3', 'monthly'], ['/contact', '0.5', 'monthly'], ['/locations', '0.7', 'monthly'],
    ['/guides', '0.8', 'weekly'], ['/editorial-policy', '0.4', 'monthly'], ['/cookies', '0.3', 'monthly'],
];
foreach (all_guides() as $slug => $guide) $urls[] = ['/guides/' . rawurlencode($slug), '0.7', 'monthly'];
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
foreach ($urls as [$path,$priority,$freq]) {
    echo "  <url><loc>" . sxe(absolute_url($path)) . "</loc><lastmod>" . $lastmod . "</lastmod><changefreq>" . $freq . "</changefreq><priority>" . $priority . "</priority></url>\n";
}
echo "</urlset>\n";
