<?php
// sitemap.xml — отдаём с Content-Type XML
header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

    <url>
        <loc>https://sport-reyestr.ru/</loc>
        <lastmod><?= gmdate('Y-m-d\TH:i:s\Z') ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>

<?php
$athletes = json_decode(file_get_contents(__DIR__ . '/data/athletes.json'), true) ?: [];
$now = gmdate('Y-m-d\TH:i:s\Z');

foreach ($athletes as $a) {
    $name = preg_replace('/[^\p{L}\s]/u', '', $a['fio']);
    $name = mb_strtolower($name, 'UTF-8');
    $slug = preg_replace('/\s+/', '-', trim($name));
    $slug = trim($slug, '-');
    if ($slug === '') continue;
    $url = 'https://sport-reyestr.ru/athlete/' . rawurlencode($slug);
?>
    <url>
        <loc><?= htmlspecialchars($url) ?></loc>
        <lastmod><?= $now ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
<?php } ?>
</urlset>
