I'm trying to use site.pages to automatically generate sitemap.xml
in Jekyll (GitHub Pages), This is the sitemap.xml
code I got:
---
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in site.pages %}
<url>
<loc>https://example.com{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endfor %}
</urlset>
It's output is something similar to this:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/samplepage.html</loc>
<!--<loc>https://example.com/samplepage</loc>-->
</url>
</urlset>
My goal is to generate a sitemap.xml without the trailing .html
as in the commented line. I've tried gsub
(I assumed Jekyll takes Ruby syntax: Replace words in string - ruby) but it seems either doesn't change anything or remove page.url completely.
I'd appreciate if anyone can
- modify the Jekyll syntax so that it generates URLs without the trailing
.html
. - explain the syntax of
| remove: 'index.html'
(which removes the URLhttps://example.com/index.html
from the generatedsitemap.xml
).
I'm very unfamiliar with Jekyll so apologies if the question seems trivial.