<?php
// Dynamic XML sitemap — served via .htaccess rewrite of sitemap.xml
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/blog_posts.php';
header('Content-Type: application/xml; charset=utf-8');
$base = getBaseUrl();
$paths = [
    ['/index.php', '1.0', 'daily'],
    ['/blog.php', '0.9', 'daily'],
    ['/docs.php', '0.9', 'weekly'],
    ['/demo.php', '0.6', 'weekly'],
    ['/about.php', '0.5', 'monthly'],
    ['/contact.php', '0.6', 'monthly'],
    ['/terms.php', '0.3', 'yearly'],
    ['/privacy.php', '0.3', 'yearly'],
    ['/refund-policy.php', '0.3', 'yearly'],
];
foreach (ah_all_posts() as $p) {
    $paths[] = ['/blog/' . $p['slug'] . '/', '0.8', 'monthly'];
}
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
foreach ($paths as [$path, $prio, $freq]) {
    echo "  <url>\n";
    echo "    <loc>" . htmlspecialchars($base . $path) . "</loc>\n";
    echo "    <changefreq>{$freq}</changefreq>\n";
    echo "    <priority>{$prio}</priority>\n";
    echo "  </url>\n";
}
echo '</urlset>';