Skip to content

Commit

Permalink
Merge pull request #437 from hydephp/add-dynamic-page-priorities-for-…
Browse files Browse the repository at this point in the history
…sitemap

Fix #429: Add page priorities to sitemap generation
  • Loading branch information
caendesilva authored May 21, 2022
2 parents 937a54d + 0bfbbba commit b6d83ec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Services/SitemapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function addPageModelUrls(string $pageClass, string $routePrefix = ''): v
$urlItem->addChild('loc', htmlentities(Hyde::uriPath(Hyde::pageLink($routePrefix.$slug.'.html'))));
$urlItem->addChild('lastmod', htmlentities($this->getLastModDate($pageClass, $slug)));
$urlItem->addChild('changefreq', 'daily');
if (config('hyde.sitemap.dynamic_priority', true)) {
$urlItem->addChild('priority', $this->getPriority($pageClass, $slug));
}
}
}

Expand All @@ -83,6 +86,31 @@ protected function getLastModDate(string $pageClass, string $slug): string
));
}

protected function getPriority(string $pageClass, string $slug): string
{
$priority = 0.5;

if (in_array($pageClass, [BladePage::class, MarkdownPage::class])) {
$priority = 0.9;
if ($slug === 'index') {
$priority = 1;
}
if ($slug === '404') {
$priority = 0.5;
}
}

if ($pageClass === DocumentationPage::class) {
$priority = 0.9;
}

if ($pageClass === MarkdownPost::class) {
$priority = 0.75;
}

return (string) $priority;
}

public static function generateSitemap(): string
{
return (new static)->generate()->getXML();
Expand Down

0 comments on commit b6d83ec

Please sign in to comment.