From 0bfbbba07fd8d1720fe6a693089e62dbc0dc018a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 21 May 2022 19:12:49 +0200 Subject: [PATCH] Add page priority support --- src/Services/SitemapService.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Services/SitemapService.php b/src/Services/SitemapService.php index badebb73..dd6b2229 100644 --- a/src/Services/SitemapService.php +++ b/src/Services/SitemapService.php @@ -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)); + } } } @@ -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();