Skip to content

Instantly share code, notes, and snippets.

@StartZeroGnu
Created September 30, 2016 15:10
Show Gist options
  • Save StartZeroGnu/738d57904f770860832dd13945f123a6 to your computer and use it in GitHub Desktop.
Save StartZeroGnu/738d57904f770860832dd13945f123a6 to your computer and use it in GitHub Desktop.
Jekyll (sitemap.xml) Template to exclude paginate folders (local build)
<!-- Forked from: https://github.com/StartZeroGnu/jekyll-sitemap/blob/master/lib/sitemap.xml -->
<!-- Add condition to exclude paginate folders -->
<?xml version="1.0" encoding="UTF-8"?>
<urlset 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" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% capture site_url %}{% if site.url %}{{ site.url | append: site.baseurl }}{% else %}{{ site.github.url }}{% endif %}{% endcapture %}
{% for post in site.posts %}{% unless post.sitemap == false %}
<url>
<loc>{{ post.url | prepend: site_url | normalize_url }}</loc>
{% if post.last_modified_at %}
<lastmod>{{ post.last_modified_at | date_to_xmlschema }}</lastmod>
{% else %}
<lastmod>{{ post.date | date_to_xmlschema }}</lastmod>
{% endif %}
</url>
{% endunless %}{% endfor %}
<!-- ADDED [or page.url contains 'page'] to exclude paginate folders -->
{% for page in site.html_pages %}{% unless page.sitemap == false or page.url contains 'page' %}
<!-- ADDED [or page.url contains 'page'] to exclude paginate folders -->
<url>
<loc>{{ page.url | replace:'/index.html','/' | prepend: site_url | normalize_url }}</loc>
{% if page.last_modified_at %}
<lastmod>{{ page.last_modified_at | date_to_xmlschema }}</lastmod>
{% endif %}
</url>
{% endunless %}{% endfor %}
{% for collection in site.collections %}{% unless collection.last.output == false or collection.output == false or collection.label == 'posts' %}
{% for doc in collection.last.docs %}{% unless doc.sitemap == false %}
<url>
<loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | normalize_url }}</loc>
{% if doc.last_modified_at %}
<lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
{% endif %}
</url>
{% endunless %}{% endfor %}
{% for doc in collection.docs %}{% unless doc.sitemap == false %}
<url>
<loc>{{ doc.url | replace:'/index.html','/' | prepend: site_url | normalize_url }}</loc>
{% if doc.last_modified_at %}
<lastmod>{{ doc.last_modified_at | date_to_xmlschema }}</lastmod>
{% endif %}
</url>
{% endunless %}{% endfor %}
{% endunless %}{% endfor %}
{% for file in page.static_files %}
<url>
<loc>{{ file.path | prepend: site_url | normalize_url }}</loc>
<lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
</url>
{% endfor %}
</urlset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment