programming (and other) musings
11 Feb 2020

simplicity

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 jao.io 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
  :init
  (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 "https://jao.io/blog/"
        org-static-blog-publish-title "programming musings"
        org-static-blog-posts-directory "~/doc/jao.io/org/"
        org-static-blog-drafts-directory "~/doc/jao.io/org/drafts/"
        org-static-blog-publish-directory "~/doc/jao.io/blog/")

  (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/jao.io/blog" nil "tag-.*")))

  (setq org-static-blog-page-header
        (concat
         "<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\">")

        org-static-blog-page-preamble
        (concat
         "<div class=\"header\">"
         "  <a href=\"https://jao.io\">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>"
         "</div>")

        org-static-blog-page-postamble
        (with-temp-buffer
          (insert-file-contents "~/.emacs.d/postamble.html")
          (buffer-string))))

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

<div id="archive"><a href="/blog/archive.html">Other posts</a></div>
<center>
  <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">
  <img alt="Creative Commons License" style="border-width:0"
       src="https://i.creativecommons.org/l/by-sa/3.0/88x31.png" />
  </a>
  <br />
  <span xmlns:dct="https://purl.org/dc/terms/"
        href="https://purl.org/dc/dcmitype/Text" property="dct:title"
        rel="dct:type">jao.io</span> by
  <a xmlns:cc="https://creativecommons.org/ns#" href="https://jao.io"
     property="cc:attributionName" rel="cc:attributionURL">jao</a>
  is licensed under a
  <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">
    Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.
</center>

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.org $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.

Footnotes:

1

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.

2

The file is actually generated by tangling a SRC block in my init.org 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
jao.io by jao is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.