feat(portal): expose bounded public sitemap

This commit is contained in:
2026-11-10 10:41:50 +02:00
parent 7f13149723
commit 252f38bb0a
4 changed files with 159 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Support;
use Generator;
final class PublicSitemapXml
{
/** @param iterable<string> $locations
* @return Generator<int, string>
*/
public function chunks(iterable $locations, bool $index = false): Generator
{
$root = $index ? 'sitemapindex' : 'urlset';
$item = $index ? 'sitemap' : 'url';
yield '<?xml version="1.0" encoding="UTF-8"?>'."\n";
yield '<'.$root.' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
foreach ($locations as $location) {
yield '<'.$item.'><loc>'.htmlspecialchars($location, ENT_XML1 | ENT_QUOTES, 'UTF-8').'</loc></'.$item.'>'."\n";
}
yield '</'.$root.'>';
}
}