The following Ruby code generates the XML sitemap of my website. It is composed of two parts:

Org Mode is instructed to generate a sitemap.xml file upon execution of this source block, thus generating the file.

Warning! Executing this piece of code is not enough to publish the sitemap, since the file sitemap.xml is created in the current directory. We need to ensure sitemap.xml is also copied into the _site directory. This is guaranteed by the order in which we execute the site generation commands. More in details, if we first process the org-mode files and then manage the “random bits in home”, we should be pretty sure the sitemap is copied.

sitemap_template = <<EOS
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
  <%- pages.each do |page| -%>
    <loc><%= page[:url] %></loc>
    <lastmod><%= page[:updated_at] %></lastmod>
  <%- end -%>

load '_scripts/metadata.rb'
require 'erb'

pages = Metadata::collect(".").select { |x| not x[:filename].start_with?("_") }
renderer =, nil, "-")
content = renderer.result(binding)

Author: Adolfo Villafiorita

Last modified: 2020-08-05 Wed 11:26 (created on: 2020-03-11 Wed 00:00)

Published: 2020-08-05 Wed 20:53