<?php
header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';
$pages = [
    ['path' => '/',           'priority' => '1.0', 'freq' => 'weekly'],
    ['path' => '/download',   'priority' => '0.9', 'freq' => 'weekly'],
    ['path' => '/features',   'priority' => '0.8', 'freq' => 'monthly'],
    ['path' => '/guide',      'priority' => '0.8', 'freq' => 'monthly'],
    ['path' => '/faq',        'priority' => '0.7', 'freq' => 'monthly'],
    ['path' => '/links',      'priority' => '0.7', 'freq' => 'monthly'],
    ['path' => '/changelog',  'priority' => '0.7', 'freq' => 'weekly'],
    ['path' => '/contact',    'priority' => '0.6', 'freq' => 'monthly'],
    ['path' => '/privacy',    'priority' => '0.3', 'freq' => 'yearly'],
];
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
<?php foreach ($pages as $page): ?>
  <?php
    $phpFile = __DIR__ . $page['path'] . ($page['path'] === '/' ? 'index' : '') . '.php';
    $lastmod = file_exists($phpFile) ? date('Y-m-d', filemtime($phpFile)) : date('Y-m-d');
  ?>
  <url>
    <loc>https://www.kernelcheat.org<?= $page['path'] ?></loc>
    <lastmod><?= $lastmod ?></lastmod>
    <changefreq><?= $page['freq'] ?></changefreq>
    <priority><?= $page['priority'] ?></priority>
    <xhtml:link rel="alternate" hreflang="zh" href="https://www.kernelcheat.org<?= $page['path'] ?>"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://www.kernelcheat.org/en<?= $page['path'] === '/' ? '/' : $page['path'] ?>"/>
    <xhtml:link rel="alternate" hreflang="x-default" href="https://www.kernelcheat.org/en<?= $page['path'] === '/' ? '/' : $page['path'] ?>"/>
  </url>
<?php endforeach; ?>
</urlset>
