getgrav / grav-plugin-langswitcher

Grav LangSwitcher Plugin
https://getgrav.org
MIT License
28 stars 26 forks source link

Absolute url #27

Closed jimblue closed 7 years ago

jimblue commented 7 years ago

Hey,

First thanks for this nice plugin.

I just have a question about langswitcher.hreflang.html.twig. Why it returns a relative url?

From what I've read the best practice is to use an absolute url like for link rel="canonical".

jimblue commented 7 years ago

I've try to adapt the template to make this working but I'm not sure what is base_url_simple for?

There is no documentation about this variable.

Anyway here is what I've write:

{% set langobj = grav['language'] %}
{% for key in langswitcher.languages %}
{% if key == langswitcher.current %}
    {% set lang_url = page.url(true) %}
{% else %}
    {% set lang_url = base_url_absolute ~ langobj.getLanguageURLPrefix(key)~langswitcher.page_route ?: '/' %}
{% endif %}
<link rel="alternate" hreflang="{{ key }}" href="{{ lang_url ~ uri.params }}" />
{% endfor %}

It could be the default template, what do you think?

jimblue commented 7 years ago

In fact my solution is not working because base_url_absolutereturns the lang in the string too and that break the correct markup.

I've tried so many solution without success... 😞

flaviocopes commented 7 years ago

As written in Slack, use base_url_simple instead. That won't contain the lang string

jimblue commented 7 years ago

tks @flaviocopes

jimblue commented 7 years ago

Hey @flaviocopes !

I've just look at your solution but I notice that base_url_simple is already what langswitcher.hreflang.html.twig use.

And this doesn't give an absolute URL but a relative.