/** * @param Urlset $urlSet */ private function addTags(Urlset $urlSet) { foreach ($this->catalogueRepository->loadAllTags() as $tag) { $url = new Url(htmlspecialchars($tag->url())); $url->setLastMod($tag->updated_at->toW3cString()); $url->setChangeFreq('monthly'); $url->setPriority(0.3); $urlSet->addUrl($url); } }
require_once __DIR__ . '/../bootstrap.php'; use Thepixeldeveloper\Sitemap\Output; use Thepixeldeveloper\Sitemap\Url; use Thepixeldeveloper\Sitemap\Urlset; /** * Helper function to build each sitemap * * @param array $entries * @param string $domain * @return boolean */ $buildSitemap = function (array $entries, $domain, $folder) { $urlSet = new Urlset(); foreach ($entries as $path => $entry) { $url = new Url("{$domain}{$path}"); // todo better detection of domain by env $url->setLastMod($entry['lastmod']); // todo check if exists $url->setChangeFreq($entry['changefreq']); // todo check if exists $url->setPriority($entry['priority']); // todo check if exists $urlSet->addUrl($url); } $output = new Output(); $output->setIndentString(' '); // change indentation from 4 to 2 spaces $tempSitemap = __DIR__ . "/../../web/public/{$folder}/sitemap-new.xml"; $finalSitemap = __DIR__ . "/../../web/public/{$folder}/sitemap.xml"; $sitemapHandle = fopen($tempSitemap, 'w');