dctrud's Random Road

Occasional unimportant nonsense.

2020-05-12 - How this gets published - an org-publish config

EDIT - This applied to when my blog was only the web, written in and published from Emacs with org-mode. These days I just created and edit gemtext files in whatever editor is to hand.

I've seen a few other people doing the #100DaysToOffload who are using Emacs to write. It seems that of among those who are, using ox-hugo is common. It's an exporter from org format into markdown with the front matter that Hugo expects. Hugo is a very nice, fast static site engine but I've taken a different route, and am using a simple elisp configuration calling 'org-html-publish-to-html'. This actually publishes all of dctrud.sdf.org, so there are three components to the org-publish project named 'site':

  (defun spacelite/init-org-publish ()
    ;; Blog publishing
    (require 'ox-publish)
    (setq org-publish-project-alist
             :components ("content" "static" "blog"))

The first 'content' component takes care of some non-blog pages which live in

the root of the site. It's pretty simple with just a few aspects of the

default output disabled, and a stylesheet added. That stylesheet is a stripped

down and customized version of org-css:


             :base-directory "'/Org/www/pages/"
             :base-extension "org"
             :publishing-directory "/ssh:dctrud@ma.sdf.org:/meta/www/d/dctrud/"
             :publishing-function org-html-publish-to-html
             :recursive t
             :timestamp t
             :with-sub-superscript nil
             :section-numbers: nil
             :with-headline-numbers nil
             :style "<link rel=\"stylesheet\" href=\"/static/org-css/stylesheet.css\" type=\"text/css\" />")

The 'static' component pushes up any static files I have locally, so they are

available to use or link to in pages and posts.

             :base-directory "'/Org/www/static/"
             :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|otf"
             :publishing-directory "/ssh:dctrud@ma.sdf.org:/meta/www/d/dctrud/static/"
             :recursive t
             :publishing-function org-publish-attachment)

Then the 'blog' posts component... this is pretty much the same as for the normal pages in the 'content' component, but with the addition of a sitemap. This sitemap is just the simple index page to the posts. It's automatically written out to an 'index.org' file when I call 'org-publish-all' and then that goes through 'org-html-publish-to-html' to become 'index.html' in the '/blog' section of the website.

             :base-directory "'/Org/www/blog/"
             :base-extension "org"
             :publishing-directory "/ssh:dctrud@ma.sdf.org:/meta/www/d/dctrud/blog/"
             :publishing-function org-html-publish-to-html
             :makeindex nil
             :auto-sitemap t
             :sitemap-filename "index.org"
             :sitemap-title "dctrud@sdf :: Blog"
             :sitemap-function spacelite/blog-sitemap-function
             :sitemap-sort-files anti-chronologically
             :recursive t
             :timestamp t
             :with-sub-superscript nil
             :section-numbers: nil
             :with-headline-numbers nil

The 'sitemap-function' is used to customize the generation of the sitemap 'index.org'. It's very simple and ugly, and should probably include header / footer stuff from files rather than just concatenating a bunch of strings, but I'm lazy and it works for now.

A 'sitemap-function' has to operate over the 'list' that it receives. Here '(org-list-to-org list)' is just creating a normal (bullet) list containing a link to each post, under the '* Recent Posts' top level section.

(defun spacelite/blog-sitemap-function (title list)
  (concat "#+TITLE: dctrud@sdf :: Blog\n"
          "#+HTML_HEAD: <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/org-css/stylesheet.css\" />\n\n"
          "[ [[file:../index.org][Home]] | [[file:../cv.org][About Me]] | [[file:index.org][Blog]] | [[file:../selfhosting.org][Self Hosting]] | [[file:../vinyl.org][Vinyl]] ]\n"
          "Welcome to my blog... I'm currently taking part in the [[https://100daystooffload.com/][#100DaysToOffload]] challenge\n"
          "so there should be something insignificant and uninteresting added here every day :-)\n\n"
          "Expect a mix of various things... computing, music, bbq, and other topics.\n\n"
          "* Recent Posts\n"
          (org-list-to-org list)

And that's all there is to it. Whenever I create a new post (I'm doing a single org file per post) I can call 'org-publish-all' and my site will get updated. It's not as fast to publish the site as hugo would be, but it's fast enough for me. At some point I will revisit it to sort out a couple more things that are common:

Index of Posts