<?php
require_once __DIR__ . '/db.php';

header('Content-Type: application/xml; charset=utf-8');

// Fetch all published articles
$stmt = $pdo->query("
    SELECT slug, updated_at, published_at 
    FROM articles 
    WHERE status = 'published' 
    ORDER BY published_at DESC
");
$articles = $stmt->fetchAll();
?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <!-- Main Pages -->
  <url>
    <loc>https://another.consulting/</loc>
    <lastmod><?= date('Y-m-d') ?></lastmod>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>

  <url>
    <loc>https://another.consulting/services</loc>
    <lastmod><?= date('Y-m-d') ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.9</priority>
  </url>

  <url>
    <loc>https://another.consulting/thisisus</loc>
    <lastmod><?= date('Y-m-d') ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>

  <url>
    <loc>https://another.consulting/becurious</loc>
    <lastmod><?= date('Y-m-d') ?></lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>

  <url>
    <loc>https://another.consulting/contact</loc>
    <lastmod><?= date('Y-m-d') ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>

  <!-- Articles -->
  <?php foreach ($articles as $article): ?>
  <url>
    <loc>https://another.consulting/becurious/<?= htmlspecialchars($article['slug']) ?></loc>
    <lastmod><?= htmlspecialchars($article['updated_at']) ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
  <?php endforeach; ?>
</urlset>
