Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No trailing slash on alt="_primary"? #1176

Open
kno10 opened this issue Dec 21, 2023 · 0 comments
Open

No trailing slash on alt="_primary"? #1176

kno10 opened this issue Dec 21, 2023 · 0 comments

Comments

@kno10
Copy link

kno10 commented Dec 21, 2023

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).

@kno10 kno10 changed the title No trailing slash on alt="_default"? No trailing slash on alt="_primary"? Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant