Question for generating sitemap.xml


#1

Hello,
to create the sitemap.xml, I created the following file:



<?xml version="1.0" encoding="UTF-8"?> {% for post in site.posts %} {{site.url}}{{ post.url | remove: 'index.html' }} {% endfor %}
{% for page in site.pages %}
{% if page.layout != nil %}
{% if page.layout != 'feed' %}
<url>
    <loc>{{site.url}}{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endif %}
{% endif %}
{% endfor %}

It generated the following sitemap.xml file

<?xml version="1.0" encoding="UTF-8"?>
<url>
    <loc>http://localhost:4000/jekyll/update/2017/12/30/welcome-to-jekyll.html</loc>
</url>

<url>
    <loc>http://localhost:4000/404.html</loc>
</url>
  
<url>
    <loc>http://localhost:4000/about/</loc>
</url>
   
<url>
    <loc>http://localhost:4000/pages/coveredMunicipalities.html</loc>
</url>    

<url>
    <loc>http://localhost:4000/pages/</loc>
</url>

<url>
    <loc>http://localhost:4000/pages/whoami.html</loc>
</url>
 
<url>
    <loc>http://localhost:4000/pages/yeartariffs.html</loc>
</url>

I was wondering if I could get rid of the two files : 404.html and about.md, in the project itself and in my sitemap.xml file also.
These two files were created by default. I presume that this two files may have an utility, but I can’t see which.

I have also another file :

/_posts/2017-12-30-welcome-to-jekyll.markdown

that was created by default (I have no post in my project, only pages) and I find it also in my _site folder

_site/jekyll/update/2017/12/30/welcome-to-jekyll.html
as well as in my sitemap.xml file.

Do you think I can also get rid of these files under _posts directory , under _site directory as well as in sitemap.xml

Thank you in advance for your answers


#2

Sure, you can add another conditional in your for loop. jekyll-sitemap does something similar.

Essentially if you add sitemap: false to a post/page’s YAML Front Matter, it’s excluded.


#3

Hi mmistakes and thank you for your answer. Nice idea, it works