Site.Atom

Menu

The following Ruby code generates the Atom feed of my website. It is composed of three parts:

Org Mode is instructed to generate a site.atom file upon execution of this source block.

Warning! Executing this piece of code is not enough to publish the feed, since the site.atom file 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.

title       = "Adolfo Villafiorita's Homepage"
author      = "Adolfo Villafiorita"
description = "Homepage of Adolfo Villafiorita"
url         = "https://ict4g.net/adolfo"
email       = "adolfo.villafiorita@ict4g.net"

atom_filename = "site.atom"
atom_template = <<EOS
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title><%= title %></title>
  <link href="<%= url %>/site.atom" rel="self" type="application/rss+xml" />
  <link href="<%= url %>"/>
  <updated><%= DateTime.now.to_s %></updated>
  <author><name><%= author %></name></author>
  <id><%= url %></id>

  <%- pages.each do |page| -%>
  <entry>
    <title><%= page["TITLE"] %></title>
    <link href="<%= page[:url] %>"/>
    <id><%= page[:url] %></id>
    <updated><%= (DateTime.parse(page["DATE"]) || DateTime.now).to_s %></updated>
    <summary>
      <%= page["DESCRIPTION"] || page[:excerpt] %>
    </summary>
  </entry>
  <%- end -%>
</feed>
EOS

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

pages = Metadata::collect("notes/").select { |x| not ["notes/index.org", "notes/chronological.org"].include?(x[:filename]) }
renderer = ERB.new(atom_template, nil, "-")
content = renderer.result(binding)

Author: Adolfo Villafiorita

Last modified: 2020-04-03 Fri 18:43 (created on: 2020-03-11 Wed 00:00)

Published: 2020-06-05 Fri 18:24