Sitemap

Menu

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

Org Mode is instructed to generate the sitemap.xml file upon execution of this source block. This block is executed when the website is build and this file exported to HTML.

SITEMAP_TEMPLATE = <<EOS
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <%- pages.each do |page| -%>
  <url>
    <loc><%= page[:absolute_url] %></loc>
    <lastmod><%= (page["DATE"] ? DateTime.parse(page["DATE"]) : DateTime.now).to_s %></lastmod>
  </url>
  <%- end -%>
</urlset> 
EOS

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

  pages = Metadata::collect ".", url: "https://ict4g.net/adolfo"

  renderer = ERB.new(SITEMAP_TEMPLATE, nil, "-")
  content = renderer.result(binding)
  puts content