<?php
/* =====================================================
   sitemap-posts.php — карта только статей
   Доступ: https://neurodog.ru/sitemap-posts.xml
   ===================================================== */
require_once 'config.php';

header('Content-Type: application/xml; charset=utf-8');

$posts = $pdo->query("SELECT slug, title, updated_at, created_at, image
                      FROM posts WHERE is_published = 1
                      ORDER BY updated_at DESC LIMIT 1000")->fetchAll();

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<?php foreach ($posts as $p): ?>
  <url>
    <loc><?= htmlspecialchars(postUrl($p)) ?></loc>
    <lastmod><?= date('c', strtotime($p['updated_at'] ?? $p['created_at'])) ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
<?php if (!empty($p['image']) && is_file(UPLOAD_DIR . $p['image'])): ?>
    <image:image>
      <image:loc><?= htmlspecialchars(SITE_URL . '/uploads/' . $p['image']) ?></image:loc>
      <image:title><?= htmlspecialchars($p['title']) ?></image:title>
    </image:image>
<?php endif; ?>
  </url>
<?php endforeach; ?>
</urlset>