<?php
require_once __DIR__ . '/config.php';
header('Content-Type: application/xml; charset=utf-8');
$base = 'https://' . $site['domain'];
$urls = [
    ['/index.php', '1.0', 'daily'],
    ['/services.php', '0.9', 'daily'],
    ['/about.php', '0.7', 'monthly'],
    ['/news.php', '0.9', 'daily'],
    ['/contact.php', '0.7', 'monthly'],
];
foreach ($products as $p) $urls[] = ['/service.php?id=' . $p['id'], '0.8', 'monthly'];

// 已发布的静态文章（来自静态缓存，不读数据库）
$cacheFile = __DIR__ . '/includes/articles_cache.php';
if (is_file($cacheFile)) {
    foreach (require $cacheFile as $a) {
        $urls[] = [$a['file'], '0.7', 'monthly'];
    }
} else {
    foreach ($articles as $a) $urls[] = ['/article.php?id=' . $a['id'], '0.7', 'monthly'];
}

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
$today = date('Y-m-d');
foreach ($urls as $u) {
    echo "  <url>\n    <loc>{$base}{$u[0]}</loc>\n    <lastmod>{$today}</lastmod>\n    <changefreq>{$u[2]}</changefreq>\n    <priority>{$u[1]}</priority>\n  </url>\n";
}
echo '</urlset>';
