Skip to content

Commit

Permalink
Add page priority support
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 21, 2022
1 parent 937a54d commit 0bfbbba
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 0bfbbba

Please sign in to comment.