Merge pull request #296 from dvarrazzo/stable-sitemap

Suggest a way to create a stable sitemap
This commit is contained in:
Andreas Runfalk 2020-02-26 16:16:35 +01:00 committed by GitHub
commit 784b49c796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -38,11 +38,16 @@ skips hidden pages so those will not be generated out.
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for page in [site.root] if page != this recursive %} {%- for page in [site.root] if page != this recursive %}
<url><loc>{{ page|url(external=true) }}</loc></url> <url><loc>{{ page|url(external=true) }}</loc></url>
{{- loop(page.children) }} {{- loop(page.children|sort(attribute='path')) }}
{%- endfor %} {%- endfor %}
</urlset> </urlset>
``` ```
Sorting the page using `|sort(attribute='path')` is not mandatory, but can be
useful if you prefer to have stable builds, for instance if you use `git` to
version the generated page and would like a clean history or a meaningful diff
from the last build.
Note that because sitemaps need to have external URLs (with scheme and Note that because sitemaps need to have external URLs (with scheme and
everything) you will need to configure the `url` of the site before the everything) you will need to configure the `url` of the site before the
template starts working. For more information see [Project File template starts working. For more information see [Project File
@ -63,7 +68,7 @@ create a `sitemap/contents.lr` file instead and use a template like
{% for page in [site.root] if page.record_label recursive %} {% for page in [site.root] if page.record_label recursive %}
<li><a href="{{ page|url }}">{{ page.record_label }}</a> <li><a href="{{ page|url }}">{{ page.record_label }}</a>
{% if page.children %} {% if page.children %}
<ul>{{ loop(page.children) }}</ul> <ul>{{ loop(page.children|sort(attribute='path')) }}</ul>
{% endif %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}