Closed lin-ycv closed 2 years ago
Not much I can do in the plugin, but you can override the template for sitemap.xml
to achieve what you want.
In mkdocs.yml
:
theme:
name: material
custom_dir: templates/
static_templates:
- sitemap.xml
Create a new file templates/sitemap.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for page in nav.pages -%}
{% if not page.is_link %}
<url>
<loc>{% if page.canonical_url %}{{ page.canonical_url|e }}{% else %}{{ page.abs_url|e }}{% endif %}</loc>
{% if page.update_date %}<lastmod>{{page.update_date}}</lastmod>{% endif %}
<changefreq>daily</changefreq>
</url>
{%- endif -%}
{% endfor %}
</urlset>
It's almost the same as the original template from mkdocs but uses nav.pages
so only pages that are part of the navigation actually end up in the sitemap.
Thanks!
I'm wondering if it's possible to configure it so that pages that are hidden from the nav is also excluded form the sitemap.xml that gets generated.