diff --git a/CHANGELOG.md b/CHANGELOG.md index eb7d9ae..4f408c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v1.4.3 +## 06/25/2021 + +1. [](#new) + * Made langswitcher data available in Grav object +1. [](#bugfix) + * Fix multilang alternatives [#58](https://github.com/getgrav/grav-plugin-langswitcher/pull/58) # v1.4.2 ## 03/17/2021 diff --git a/blueprints.yaml b/blueprints.yaml index e156c68..56717a4 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: LangSwitcher -version: 1.4.2 +version: 1.4.3 description: LangSwitcher is a [Grav](http://github.com/getgrav/grav) plugin that provides native language text links to switch between [multiple languages](http://learn.getgrav.org/content/multi-language) in Grav **v0.9.30** or greater. icon: globe author: diff --git a/langswitcher.php b/langswitcher.php index a2a43a7..8e3c5bb 100644 --- a/langswitcher.php +++ b/langswitcher.php @@ -8,6 +8,7 @@ class LangSwitcherPlugin extends Plugin { + /** * @return array */ @@ -99,7 +100,7 @@ public function onTwigSiteVariables() $data->current = $this->grav['language']->getLanguage(); - $this->grav['twig']->twig_vars['langswitcher'] = $data; + $this->grav['twig']->twig_vars['langswitcher'] = $this->grav['langswitcher'] = $data; if ($this->config->get('plugins.langswitcher.built_in_css')) { $this->grav['assets']->add('plugin://langswitcher/css/langswitcher.css'); diff --git a/templates/partials/langswitcher.hreflang.html.twig b/templates/partials/langswitcher.hreflang.html.twig index e3bce2f..921b7e0 100644 --- a/templates/partials/langswitcher.hreflang.html.twig +++ b/templates/partials/langswitcher.hreflang.html.twig @@ -1,9 +1,9 @@ {% set langobj = grav['language'] %} {% for key in langswitcher.languages %} {% if key == langswitcher.current %} - {% set lang_url = page.url %} + {% set lang_url = page.url is same as('/') ? '' : page.url %} {% else %} - {% set lang_url = base_url_simple ~ langobj.getLanguageURLPrefix(key) ~ langswitcher.page_route ~ page.urlExtension ?: '/' %} + {% set lang_url = (langobj.getLanguageURLPrefix(key) ~ langswitcher.page_route ~ page.urlExtension ?: '')|rtrim('/') %} {% endif %} - + {% endfor %}