<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/core/db.php';

header('Content-Type: application/xml; charset=UTF-8');
$articles = db_query("SELECT slug, published_at FROM articles WHERE status='published' ORDER BY published_at DESC", array());
?>
<?= '<?xml version="1.0" encoding="UTF-8"?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc><?= SITE_URL ?></loc>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>
  <?php foreach ($articles as $art): ?>
  <url>
    <loc><?= SITE_URL ?>article/<?= htmlspecialchars($art['slug']) ?>/</loc>
    <lastmod><?= date('Y-m-d', strtotime($art['published_at'])) ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>
  <?php endforeach; ?>
</urlset>