<?php
header('Content-Type: application/xml; charset=utf-8');

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<!-- HOME -->
<url>
  <loc>https://www.laurabren.com.ar/</loc>
  <lastmod><?= date('Y-m-d') ?></lastmod>
</url>

<?php
/* =========================
   PAGINAS FIJAS
========================= */

$paginas = [
  "marketing-intencional.php",
  "posicionamiento-web.php",
  "quiero-una-web.php",
  "asesoria-agencia.php",
  "blog.php"
];

foreach ($paginas as $p) {
  echo "<url>
    <loc>https://www.laurabren.com.ar/$p</loc>
    <lastmod>" . date('Y-m-d') . "</lastmod>
  </url>";
}

/* =========================
   ARTICULOS DESDE JSON
========================= */

$base = __DIR__ . "/articulos/";

$categorias = scandir($base);

foreach ($categorias as $cat) {

  if ($cat === '.' || $cat === '..') continue;

  $rutaCat = $base . $cat;

  if (!is_dir($rutaCat)) continue;

  $archivos = scandir($rutaCat);

  foreach ($archivos as $slug) {

    if ($slug === '.' || $slug === '..') continue;

    $rutaArticulo = $rutaCat . "/" . $slug . "/data.json";

    if (file_exists($rutaArticulo)) {

      echo "<url>
        <loc>https://www.laurabren.com.ar/ver-nota.php?cat=$cat&slug=$slug</loc>
        <lastmod>" . date('Y-m-d') . "</lastmod>
      </url>";

    }
  }
}
?>

</urlset>