Site Atom Generator


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

Part of the magic is made possible by the evaluation parameters of the source block. More in details, the output of the evaluation is directed to the file ../site.atom with the file and :file "" directives.

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).

(require 'templatel)
(org-babel-load-file "project-specification/")

;; get metadata of all the files from notes
(setq metadata (files-metadata "notes" "." ""))
;; remove files in this directory (which are index files)
(setq metadata (seq-filter (lambda (x) (< 2 (length (split-string (cdr (assoc "FILENAME" x)) "/")))) metadata))
;; sort by date
(setq metadata (sort-metadata metadata "DATE_ISO8601" 'string-greaterp))

(setq atom-template  "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<feed xmlns=\"\">
  <link href=\"{{url}}/site.atom\" rel=\"self\" type=\"application/rss+xml\" />
  <link href=\"{{url}}\"/>
  {% for page in pages %}
    <title>{{ page.TITLE }}</title>
    <link href=\"{{page.ABSOLUTE_URL}}\"/>
    <updated>{{ page.DATE_ISO8601 }}</updated>
    {% if page.DESCRIPTION %}
       {{ page.DESCRIPTION }}
    {% endif %}
  {% endfor %}

(templatel-render-string atom-template
                         (list (cons "title" "Adolfo Villafiorita's Homepage")
                               (cons "author" "Adolfo Villafiorita")
                               (cons "today" (format-time-string "%Y-%m-%dT%H%M%S%z"))
                               (cons "description" "Homepage of Adolfo Villafiorita")
                               (cons "url" "")
                               (cons "email" "")
                               (cons "pages" metadata)))