<?php
include_once __DIR__ . '/config.php';
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
echo '<url><loc>' . $base_url . '/</loc><lastmod>' . date('Y-m-d') . '</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>';
if (isset($posts) && is_array($posts)) {
    foreach ($posts as $post) {
        $full_url = $base_url . $post['url'];
        $clean_date = date('Y-m-d', strtotime($post['date'] ?? date('Y-m-d')));
        echo '<url><loc>' . htmlspecialchars($full_url) . '</loc><lastmod>' . $clean_date . '</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>';
    }
}
echo '</urlset>';
?>