Skip to content

Commit

Permalink
Implement multilingual sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
batlab committed Feb 18, 2017
1 parent e4d6d7c commit 682ac88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions _includes/sitemap-url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% assign p_done = "404" %}
{% for p in include.objects %}
{% unless p.path contains ".xml" %}
{% unless p.path contains ".scss" %}
{% assign pname = p.path | split:"." | first %}
{% assign p_done_arr = p_done | split:"," %}
{% unless p_done_arr contains pname %}
<url>
<loc>{{ site.url }}{{ p.url | url_escape }}</loc>
{% assign versions = include.objects | where_exp:"p","p.path contains pname" %}
{% for v in versions %}
<xhtml:link
rel="alternate"
hreflang="{{ v.lang }}"
href="{{ site.url }}{{ v.url | url_escape }}"
/>
{% endfor %}
{% assign p_done = p_done | append:"," | append:pname %}
{% if p.layout == "post" %}
<lastmod>{{ p.last_modified_at | default:p.date | date_to_xmlschema }}</lastmod>
{% endif %}
<changefreq>weekly</changefreq>
{% if p.layout == "home" %}
<priority>1</priority>
{% endif %}
</url>
{% endunless %}
{% endunless %}
{% endunless %}
{% endfor %}
6 changes: 6 additions & 0 deletions _layouts/sitemap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaposts.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml" >
{% include sitemap-url.html objects=site.pages %}
{% include sitemap-url.html objects=site.posts %}
</urlset>
3 changes: 3 additions & 0 deletions sitemaps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
layout: sitemap
---

0 comments on commit 682ac88

Please sign in to comment.