getgrav / grav-plugin-langswitcher

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

Fix hreflang URL #57

Closed Karmalakas closed 3 years ago

Karmalakas commented 3 years ago

Google complains about hreflang URL being invalid. When full URL provided, complaints are gone

marcocevoli commented 3 years ago

Not sure it's working as expected. This is what I get: https://i.imgur.com/QfEudUe.png if I visit the Spanish page, https://qabiria.com/es. Code in base.html.twig is: {% include 'partials/langswitcher.hreflang.html.twig' %} <link rel="canonical" href="{{ page.canonical(true) }}{{ uri.params('page') }}" />

Karmalakas commented 3 years ago

Not sure it's working as expected. This is what I get: https://i.imgur.com/QfEudUe.png if I visit the Spanish page, https://qabiria.com/es. Code in base.html.twig is: {% include 'partials/langswitcher.hreflang.html.twig' %} <link rel="canonical" href="{{ page.canonical(true) }}{{ uri.params('page') }}" />

Looks fine. What do you expect? :) Maybe x-default could also be added there, but I believe that's another issue. I don't fully understand when it should be present actually.

Here's some reading on Google and Moz

marcocevoli commented 3 years ago

If you look at the image, you'll see that the base URL is considered with the language code, such as https://qabiria.com/es so that all alternate are built upon it and resulting in wrong URLs, such as https://qabiria.com/es/es, https://qabiria.com/es/en and https://qabiria.com/es/it, instead of https://qabiria.com/es, https://qabiria.com/en, https://qabiria.com/it. Again, I don't know why this happens and if it's my configuration or not. However, the line of code that generates those metadata are only controlled by langswitcher, so my bet is that the error depends on it.

Karmalakas commented 3 years ago

Ah.. I see what you mean. Same on my page when url already has lang part in it.. Can check this in ~8 hours - I'm at work now :( Already had similar issue with images when Grav is installed not on root :/

If someone could check this sooner, please do. If not, I'll let you know when I have a PR

Karmalakas commented 3 years ago

@marcocevoli, I really tried to test every URL format I could think of. You can take the template and help check if it works as expected now. Here's the PR

rhukster commented 3 years ago

i've merged this into the develop branch, so should be easier to test there

mahagr commented 3 years ago

@ptarmic please create a new issue on this, otherwise, your comment may be lost.

maofree commented 2 years ago

Hi there are other problems with hreflang, x-default and urls on the language selector https://github.com/getgrav/grav-plugin-langswitcher/issues/63