<?php
require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/db.php';
header('Content-Type: application/xml; charset=utf-8');
$posts = Database::fetchAll("SELECT slug, updated_at FROM blog_posts WHERE status = 'published'");
?>
<?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>
  <url><loc><?= SITE_URL ?>/roast.php</loc><changefreq>monthly</changefreq><priority>0.9</priority></url>
  <url><loc><?= SITE_URL ?>/blog.php</loc><changefreq>weekly</changefreq><priority>0.8</priority></url>
  <url><loc><?= SITE_URL ?>/about.php</loc><changefreq>yearly</changefreq><priority>0.5</priority></url>
  <url><loc><?= SITE_URL ?>/contact.php</loc><changefreq>yearly</changefreq><priority>0.4</priority></url>
  <url><loc><?= SITE_URL ?>/privacy.php</loc><changefreq>yearly</changefreq><priority>0.3</priority></url>
  <url><loc><?= SITE_URL ?>/terms.php</loc><changefreq>yearly</changefreq><priority>0.3</priority></url>
  <?php foreach ($posts as $post): ?>
  <url>
    <loc><?= SITE_URL ?>/post.php?slug=<?= urlencode($post['slug']) ?></loc>
    <lastmod><?= date('Y-m-d', strtotime($post['updated_at'])) ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
  <?php endforeach; ?>
</urlset>
