diff --git a/CHANGELOG.md b/CHANGELOG.md index 05987d7..dda4742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v3.0.2 +## 06/14/2022 + +1. [](#new) + * Added new `route:` field to JSON format sitemap +1. [](#bugfix) + * Fixed an issue with `x-default` entry not working with non-string based language code + # v3.0.1 ## 02/23/2021 diff --git a/blueprints.yaml b/blueprints.yaml index 7e45980..61a03f0 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Sitemap type: plugin slug: sitemap -version: 3.0.1 +version: 3.0.2 description: "Provide automatically generated **XML sitemaps** with this very useful, but simple to configure, Grav plugin." icon: map-marker author: diff --git a/classes/SitemapEntry.php b/classes/SitemapEntry.php index ce7fb6c..2a9d29c 100644 --- a/classes/SitemapEntry.php +++ b/classes/SitemapEntry.php @@ -4,6 +4,7 @@ class SitemapEntry { public $title; + public $route; public $lang; public $translated = false; public $location; @@ -83,6 +84,24 @@ public function setTitle($title): SitemapEntry return $this; } + /** + * @return mixed + */ + public function getRoute() + { + return $this->route; + } + + /** + * @param mixed $route + * @return SitemapEntry + */ + public function setRoute($route): SitemapEntry + { + $this->route = $route; + return $this; + } + /** * @return mixed */ diff --git a/sitemap.php b/sitemap.php index ae23dfa..1dfc470 100644 --- a/sitemap.php +++ b/sitemap.php @@ -148,12 +148,12 @@ public function onPagesInitialized() if ($language->enabled()) { foreach ($route_data as $l => $l_data) { $entry->addHreflangs(['hreflang' => $l, 'href' => $l_data['location']]); - if ($l === $default_lang) { + if ($l == $default_lang) { $entry->addHreflangs(['hreflang' => 'x-default', 'href' => $l_data['location']]); } } } - $this->sitemap[$data['route']] = $entry; + $this->sitemap[$data['url']] = $entry; } } } @@ -275,11 +275,12 @@ protected function addRouteData($pages, $lang) $page_languages = array_keys($page->translatedLanguages()); $include_lang = $this->multilang_skiplang_prefix !== $lang; $location = $page->canonical($include_lang); - $page_route = $page->url(false, $include_lang); + $url = $page->url(false, $include_lang); $lang_route = [ 'title' => $page->title(), - 'route' => $page_route, + 'url' => $url, + 'route' => $route, 'lang' => $lang, 'translated' => in_array($lang, $page_languages), 'location' => $location,