Created
August 24, 2021 13:18
-
-
Save vivi90/a8563f3ccbf4e90961540b6dc98224f4 to your computer and use it in GitHub Desktop.
Global multilingual sitemap for Jekyll based websites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# Global multilingual sitemap for Jekyll based websites | |
# | |
# Version: 1.0.0 | |
# Author: Vivien Richter <[email protected]> | |
# License: CC-BY-4.0 | |
# | |
# Based on: https://sylvaindurand.org/making-jekyll-multilingual/#with-a-sitemaps-file | |
# | |
# See also: | |
# - https://developers.google.com/search/docs/advanced/crawling/localized-versions | |
# - https://www.sitemaps.org/de/protocol.html | |
layout: null | |
--- | |
<?xml version="1.0" encoding="UTF-8"?> | |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" | |
xmlns:xhtml="http://www.w3.org/1999/xhtml" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> | |
<!-- Posts --> | |
{%- for post in site.posts -%} | |
{%- unless post.published == false or post.sitemap == false %} | |
<url> | |
<loc>{{ site.url }}{{ post.url }}</loc> | |
{%- assign translations = site.posts | where:"ref", post.ref -%} | |
{%- for translation in translations %} | |
<xhtml:link | |
rel="alternate" | |
hreflang="{{ translation.locale }}" | |
href="{{ site.url }}{{ translation.url }}"/> | |
{%- endfor %} | |
<xhtml:link | |
rel="alternate" | |
hreflang="x-default" | |
href="{{ site.url }}"/> | |
<lastmod>{{ post.date | date_to_xmlschema }}</lastmod> | |
<changefreq>{{ post.changefreq }}</changefreq> | |
<priority>{{ post.priority }}</priority> | |
</url> | |
{%- endunless -%} | |
{%- endfor %} | |
<!-- Pages --> | |
{%- assign pages = site.pages | where: "sitemap", true -%} | |
{%- for page in pages %} | |
<url> | |
<loc>{{ site.url }}{{ page.url }}</loc> | |
{%- assign translations = pages | where:"ref", page.ref -%} | |
{%- for translation in translations %} | |
<xhtml:link | |
rel="alternate" | |
hreflang="{{ translation.locale }}" | |
href="{{ site.url }}{{ translation.url }}"/> | |
{%- endfor %} | |
<xhtml:link | |
rel="alternate" | |
hreflang="x-default" | |
href="{{ site.url }}"/> | |
<lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod> | |
<changefreq>{{ page.changefreq }}</changefreq> | |
</url> | |
{%- endfor %} | |
</urlset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required front matter YAML:
Example for pages:
Example for posts:
Required Jekyll plugins: