Skip to content

Commit b6d83ec

Browse files
authored
Merge pull request #437 from hydephp/add-dynamic-page-priorities-for-sitemap
Fix #429: Add page priorities to sitemap generation
2 parents 937a54d + 0bfbbba commit b6d83ec

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Services/SitemapService.php

+28
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public function addPageModelUrls(string $pageClass, string $routePrefix = ''): v
7373
$urlItem->addChild('loc', htmlentities(Hyde::uriPath(Hyde::pageLink($routePrefix.$slug.'.html'))));
7474
$urlItem->addChild('lastmod', htmlentities($this->getLastModDate($pageClass, $slug)));
7575
$urlItem->addChild('changefreq', 'daily');
76+
if (config('hyde.sitemap.dynamic_priority', true)) {
77+
$urlItem->addChild('priority', $this->getPriority($pageClass, $slug));
78+
}
7679
}
7780
}
7881

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

89+
protected function getPriority(string $pageClass, string $slug): string
90+
{
91+
$priority = 0.5;
92+
93+
if (in_array($pageClass, [BladePage::class, MarkdownPage::class])) {
94+
$priority = 0.9;
95+
if ($slug === 'index') {
96+
$priority = 1;
97+
}
98+
if ($slug === '404') {
99+
$priority = 0.5;
100+
}
101+
}
102+
103+
if ($pageClass === DocumentationPage::class) {
104+
$priority = 0.9;
105+
}
106+
107+
if ($pageClass === MarkdownPost::class) {
108+
$priority = 0.75;
109+
}
110+
111+
return (string) $priority;
112+
}
113+
86114
public static function generateSitemap(): string
87115
{
88116
return (new static)->generate()->getXML();

0 commit comments

Comments
 (0)