'/', 'lastmod' => sitemap_lastmod($rootIndex), 'priority' => '1.0', 'hreflang' => 'x-default', ]; } foreach (glob(__DIR__ . '/*/index.html') ?: [] as $file) { $folder = basename(dirname($file)); if (in_array(strtolower($folder), $skipDirs, true)) { continue; } if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/i', $folder)) { continue; } $entries[] = [ 'path' => '/' . $folder . '/', 'lastmod' => sitemap_lastmod($file), 'priority' => '0.9', 'hreflang' => sitemap_folder_hreflang($folder), ]; } // Build alternate map for xhtml:link $alts = []; foreach ($entries as $entry) { $alts[] = [ 'hreflang' => $entry['hreflang'], 'href' => $o . $entry['path'], ]; } // Also expose short language code for locale folders (ro-RO → ro) when unique $shortSeen = []; foreach ($entries as $entry) { if ($entry['path'] === '/') { continue; } if (preg_match('/^([a-z]{2})-/i', ltrim($entry['path'], '/'), $m)) { $short = strtolower($m[1]); if (!isset($shortSeen[$short])) { $shortSeen[$short] = $o . $entry['path']; $alts[] = [ 'hreflang' => $short, 'href' => $o . $entry['path'], ]; } } } echo '' . "\n"; echo '' . "\n"; foreach ($entries as $entry) { $loc = htmlspecialchars($o . $entry['path'], ENT_XML1 | ENT_QUOTES, 'UTF-8'); $lm = htmlspecialchars($entry['lastmod'], ENT_XML1 | ENT_QUOTES, 'UTF-8'); $pr = htmlspecialchars($entry['priority'], ENT_XML1 | ENT_QUOTES, 'UTF-8'); echo " \n"; echo " {$loc}\n"; foreach ($alts as $alt) { $hl = htmlspecialchars($alt['hreflang'], ENT_XML1 | ENT_QUOTES, 'UTF-8'); $href = htmlspecialchars($alt['href'], ENT_XML1 | ENT_QUOTES, 'UTF-8'); echo " \n"; } echo "\n";