feat(portal): expose bounded public sitemap
This commit is contained in:
@@ -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.'>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user