No trailing slash on alt="_primary"?
kno10 opened this issue · comments
My template includes the following to generate links to alternate languages:
{%- if get_alts(this) %}
<link rel="alternate" hreflang="x-default" href="{{ this._path|url(alt="_primary",external=True) }}">
{%- for hreflang in get_alts(this) %}
<link rel="alternate" hreflang="{{hreflang}}" href="{{ this._path|url(alt=hreflang,external=True) }}">
{%- endfor %}
{%- endif %}
However, the x-default
link does not have a trailing slash, the ones generated via get_alts
do.
I have a similar problem with missing trailing slashes in my sitemap:
<url>
<loc>{{ page._path|url(alt="_primary",external=True) }}</loc>
{%- for hreflang in get_alts(page) %}
{%- set apage = site.get(page._path, alt=hreflang) %}
{%- if apage.is_visible %}
<xhtml:link rel="alternate" hreflang="{{ hreflang }}" href="{{ page._path|url(alt=hreflang,external=True) }}"/>
{%- endif %}
{%- endfor %}
</url>
again, the URL in loc
is missing the trailing slash.
Note: I use content negotiation for handling the x-default
URL, so it is different from my regular alt urls - all my alternatives have a URL prefix, and I never use the "non-overlay" version. I am not totally happy with the way alternatives are currently handled in lektor, which is designed around the idea that you have one primary language and second-class alternates, and does not allow for some pages to have one, and others the other language only (and still have a canonical URL). But independent of this, the output of above example is inconsistent by sometimes having the trailing slash, sometimes not.
My workaround now is to |trim("/")
and always append a slash (as all pages will be saved as /index.html
by lektor anyway).