Site Atom Generator
The following code generates the Atom feed of my website. It is composed of two parts:
- the first part reads the metadata of all the posts
- the second part uses
templatel
to build the ../site.atom file.
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
"atom.org"
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/metadata.org") ;; get metadata of all the files from notes (setq metadata (files-metadata "notes" "." "https://ict4g.net/adolfo")) ;; 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=\"http://www.w3.org/2005/Atom\"> <title>{{title}}</title> <link href=\"{{url}}/site.atom\" rel=\"self\" type=\"application/rss+xml\" /> <link href=\"{{url}}\"/> <updated>{{today}}</updated> <author><name>{{author}}</name></author> <id>{{url}}</id> {% for page in pages %} <entry> <title>{{ page.TITLE }}</title> <link href=\"{{page.ABSOLUTE_URL}}\"/> <id>{{page.ABSOLUTE_URL}}</id> <updated>{{ page.DATE_ISO8601 }}</updated> {% if page.DESCRIPTION %} <summary> {{ page.DESCRIPTION }} </summary> {% endif %} </entry> {% endfor %} </feed>") (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" "https://ict4g.net/adolfo") (cons "email" "adolfo@ict4g.net") (cons "pages" metadata)))