programming (and other) musings
11 Feb 2020


I like simple things. As simple as possible, but not simpler: they should live well in my little emacs universe. Bastian Bechtold's org-static-blog, a static site generator using org-mode, is the latest star in that virtual world.

You are looking at the result. It retrospect, it took me an absurdly long time to do something as natural as incorporating blogging to the platform where i spend most of my computer time, using the most flexible markup language i know. Well, better late than never, i suppose!

Revamping to this new incarnation took little time. Converting exisiting markdown posts to org was straghtforward with pandoc, and org-static-blog needs very little boilerplate after the conversion Org's exporting capabilities are all but amazing, so it's easy to build on them: one can do it right, like Bastian, or get carried away and create a complex monster.

For the record, this is all the configuration that was required, where it is perhaps worth mentioning how i extract the list of tags from the list of HTML files pointing to them1::

(use-package org-static-blog
  :ensure t
  (setq org-static-blog-use-preview t
        org-static-blog-preview-convert-titles t
        org-static-blog-preview-ellipsis "..."
        org-static-blog-enable-tags t
        org-static-blog-publish-url ""
        org-static-blog-publish-title "programming musings"
        org-static-blog-posts-directory "~/doc/"
        org-static-blog-drafts-directory "~/doc/"
        org-static-blog-publish-directory "~/doc/")

  (setq jao-org-blog-tags
        (mapcar (lambda (f)
                  (string-match "tag-\\(.+\\)\\.html" f)
                  (format "<a href=\"/blog/%s\">%s</a>"
                          f (match-string 1 f)))
                (directory-files "~/doc/" nil "tag-.*")))

  (setq org-static-blog-page-header
         "<meta name=\"author\" content=\"jao\">"
         "<meta name=\"referrer\" content=\"no-referrer\">"
         "<link href= \"/static/style.css\" rel=\"stylesheet\"
                type=\"text/css\" />"
         "<link rel=\"icon\" href=\"static/favicon.ico\">")

         "<div class=\"header\">"
         "  <a href=\"\">programming musings</a>"
         "  <div class=\"sitelinks\">"
         "    <a href=\"/blog/about.html\">about</a>"
         "    | <a href=\"/blog/hacking.html\">hacking</a>"
         "    | <a href=\"/blog/archive.html\">archive</a>"
         "    | <div class=\"dropdown\">"
         "       <a href=\"/blog/tags/html\" class=\"dropbtn\">tags</a>"
         "       <div class=\"dropdown-content\">"
         (mapconcat #'identity jao-org-blog-tags "")
         "       </div>"
         "      </div>"
         "    | <a href=\"/blog/rss.xml\">rss</a>"
         "  </div>"

          (insert-file-contents "~/.emacs.d/postamble.html")

with ~/.emacs.d/blog-postamble.html containing mostly license boilerplate2:

<div id="archive"><a href="/blog/archive.html">Other posts</a></div>
  <a rel="license" href="">
  <img alt="Creative Commons License" style="border-width:0"
       src="" />
  <br />
  <span xmlns:dct=""
        href="" property="dct:title"
        rel="dct:type"></span> by
  <a xmlns:cc="" href=""
     property="cc:attributionName" rel="cc:attributionURL">jao</a>
  is licensed under a
  <a rel="license" href="">
    Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.

Then i remembered my old WordPres blogs (programming musings, minor emacs wizardry, and physics musings), collecting dust for more than a decade now, and wondered what would it take to rescue those posts. Turns out one of those other blogging tools, pelican, has an importer, pelican-import, that knows about the XML one can export from WordPress. With that, i had a collection or .rst files that i knew how to move to org files from the comfort of my eshell:

$ for f in *.rst { pandoc -f rst -t org -o $ $f }

And then i started writing a bit of elisp to add the blog headers, but didn't go too far: how many of those posts where worth converting? Well, i started skimming over them, and was pleased to discover that my little self fiteen years ago was rather clueless (so i've either learnt something these years or, at least, gained some confidence), and only a handful of them were both salvaging: no elisp needed! If you're curious, you can find them under the tags auld, emacs, and physics, or just looking for the really old entries in the archive.



So this list can be generated only after the set of tags is decided (in my case, by exporting the existing posts once), and has the drawback of having to re-regenerate all the HTML if one ever adds a new tag (remember that these pages are static). But org-static-blog is so much faster doing it than i writing posts that i'm not going to worry.


The file is actually generated by tangling a SRC block in my file, and using variable interpolation one wouldn't even need to use an external file, but that's for another post.

Tags: emacs
Creative Commons License by jao is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.