Skip to content

Commit

Permalink
added new route attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jul 20, 2021
1 parent 9609b3d commit 5f38828
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v3.0.2
## mm/dd/2021

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

Expand Down
19 changes: 19 additions & 0 deletions classes/SitemapEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class SitemapEntry
{
public $title;
public $route;
public $lang;
public $translated = false;
public $location;
Expand Down Expand Up @@ -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
*/
Expand Down
9 changes: 5 additions & 4 deletions sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5f38828

Please sign in to comment.