
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <!-- Homepage -->
    <url>
        <loc>https://<?php echo $_SERVER['HTTP_HOST']; ?>/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    
    <!-- Últimas Notícias -->
    <url>
        <loc>https://<?php echo $_SERVER['HTTP_HOST']; ?>/ultimas-noticias.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>0.9</priority>
    </url>
    
    <?php
    require_once 'includes/config.php';
    
    // Categorias
    $stmt = $pdo->query("SELECT slug FROM categorias ORDER BY ordem ASC");
    $categorias = $stmt->fetchAll();
    
    foreach ($categorias as $categoria):
    ?>
    <url>
        <loc>https://<?php echo $_SERVER['HTTP_HOST']; ?>/categoria.php?slug=<?php echo $categoria['slug']; ?></loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <?php endforeach; ?>
    
    <?php
    // Notícias
    $stmt = $pdo->query("
        SELECT slug, data_publicacao 
        FROM noticias 
        WHERE status = 'ativo' 
        ORDER BY data_publicacao DESC 
        LIMIT 1000
    ");
    $noticias = $stmt->fetchAll();
    
    foreach ($noticias as $noticia):
    ?>
    <url>
        <loc>https://<?php echo $_SERVER['HTTP_HOST']; ?>/noticia.php?slug=<?php echo $noticia['slug']; ?></loc>
        <lastmod><?php echo date('Y-m-d', strtotime($noticia['data_publicacao'])); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    <?php endforeach; ?>
</urlset>
