Skip to content

Commit 407346e

Browse files
authored
add sitemap override example, closes #120
1 parent a75a6ea commit 407346e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Diff for: docs/howto/override-a-theme.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,28 @@ We can use the [mkdocs template variables](https://www.mkdocs.org/dev-guide/them
143143
</div>
144144
{% endif %}
145145
{% endblock %}
146-
```
146+
```
147+
148+
## Example: Populate `sitemap.xlm`
149+
150+
Having a correct lastmod in your `sitemap.xlm` is important for SEO, as it indicates to Search engines when to re-index pages, see [this blog from Bing](https://blogs.bing.com/webmaster/february-2023/The-Importance-of-Setting-the-lastmod-Tag-in-Your-Sitemap).
151+
152+
[`@thesuperzapper`](https://github.com/thesuperzapper) shared this [override](https://squidfunk.github.io/mkdocs-material/customization/?h=overri#extending-the-theme) in [mkdocs-git-revision-date-localized-plugin#120](https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/120):
153+
154+
```html
155+
<?xml version="1.0" encoding="UTF-8"?>
156+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
157+
{%- for file in pages -%}
158+
{% if not file.page.is_link and (file.page.abs_url or file.page.canonical_url) %}
159+
<url>
160+
<loc>{% if file.page.canonical_url %}{{ file.page.canonical_url|e }}{% else %}{{ file.page.abs_url|e }}{% endif %}</loc>
161+
{#- NOTE: we exclude `lastmod` for pages using a template, as their update time is not correctly detected #}
162+
{%- if not file.page.meta.template and file.page.meta.git_revision_date_localized_raw_iso_datetime %}
163+
<lastmod>{{ (file.page.meta.git_revision_date_localized_raw_iso_datetime + "+00:00") | replace(" ", "T") }}</lastmod>
164+
{%- endif %}
165+
<changefreq>daily</changefreq>
166+
</url>
167+
{%- endif -%}
168+
{% endfor %}
169+
</urlset>
170+
```

0 commit comments

Comments
 (0)