Site Atom Generator
The following Ruby code generates the Atom feed of my website. It is composed of three parts:
- some global variables used for customizing the Atom feed
- an ERB template to generate the feed
- Ruby code which collects information about all pages in the notes directory and passes it to the atom template.
Org Mode is told to generate a site.atom file upon execution of this source block. This block is executed when the website is built (or this page exported).
TITLE = "Adolfo Villafiorita's Homepage" AUTHOR = "Adolfo Villafiorita" DESCRIPTION = "Homepage of Adolfo Villafiorita" URL = "https://ict4g.net/adolfo" EMAIL = "adolfo.villafiorita@ict4g.net" 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[:absolute_url] %>"/> <id><%= page[:absolute_url] %></id> <updated><%= (page["DATE"] ? 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", url: URL).select { |x| x["CATEGORY"] != "index-page" } renderer = ERB.new(ATOM_TEMPLATE, nil, "-") content = renderer.result(binding) puts content