All <link rel="alternate" hreflang> for i18n pages

This commit is contained in:
Zach Leatherman 2022-07-15 15:15:02 -05:00
parent 143f2b33df
commit 847258f60c
2 changed files with 12 additions and 5 deletions

View File

@ -15,7 +15,13 @@
<link rel="alternate" href="{{ '/feed/feed.xml' | url }}" type="application/atom+xml" title="{{ metadata.title }}"> <link rel="alternate" href="{{ '/feed/feed.xml' | url }}" type="application/atom+xml" title="{{ metadata.title }}">
<link rel="alternate" href="{{ '/feed/feed.json' | url }}" type="application/json" title="{{ metadata.title }}"> <link rel="alternate" href="{{ '/feed/feed.json' | url }}" type="application/json" title="{{ metadata.title }}">
{# TODO add link rel="alternate" for langs #} {%- set alternateUrls = page.url | locale_links %}
{% if alternateUrls.length %}
<link rel="alternate" hreflang="{{ lang or metadata.language }}" href="{{ page.url | absoluteUrl(metadata.url) }}">
{%- for link in alternateUrls %}
<link rel="alternate" hreflang="{{ link.lang }}" href="{{ link.url | absoluteUrl(metadata.url) }}">
{%- endfor %}
{%- endif %}
</head> </head>
<body> <body>
<header> <header>

View File

@ -18,10 +18,11 @@ templateClass: tmpl-post
{% if i18nLinks.length %} {% if i18nLinks.length %}
<ul> <ul>
<li> <li>
This page is also available in: <!-- dont forget to localize this text too --> This page is also available in:
{%- for link in i18nLinks %} {%- for link in i18nLinks %}
{%- if not loop.first %},{% endif %}<a href="{{link.url}}" lang="{{link.lang}}" hreflang="{{link.lang}}">{{link.label}}</a> <a href="{{ link.url }}" lang="{{ link.lang }}" hreflang="{{ link.lang }}">{{ link.label }}</a>
{%- endfor -%} {%- if not loop.last %},{% endif %}
{%- endfor -%}
</li> </li>
</ul> </ul>
{% endif %} {% endif %}