Emacs as a Static Site Generator
I’ve been hosting my website on GitHub Pages since 2014. Over the years I have tended to rewrite my website whenever I was learning a new programming language.
I started out with a “pure” HTML+CSS website and eventually moved on to Python, where I used the Frozen-Flask package to bundle my Flask app into a set of static files. As time went on, I started writing my own static site generators: first in Bash+Pandoc, then Common-Lisp, and later Go(lang).
Overall I have enjoyed writing my own static site generators and think it’s a great project for exploring a new programming language. In fact, whenever I’ve tried migrating to one of the popular options like Hugo, I ultimately went back to doing it myself because I hated dealing with auto-generated files, customizing themes, and digging through incomplete documentation.
I have been using Emacs and Org Mode for a long time but never
org-publish functionality. It’s far from perfect, but
it’s incredibly convenient. Like most things Emacs,
be configured to do just about anything. So far I only use it to
generate this website, but my configuration can be easily extended to
handle several different projects.
This website is generated from Emacs using
(defvar my/website-org-path "~/anschwa.github.io")
(defvar my/website-org-base-directory (concat my/website-org-path "/org/"))
(defvar my/website-org-publishing-directory (concat my/website-org-path "/public_html/"))
(let ((viewport "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />"))
(concat viewport "\n")))
(setq org-html-metadata-timestamp-format "%Y-%m-%d")
(setq org-html-htmlize-output-type 'inline-css) ; Uses current theme for syntax highlighting
("website" :components ("website-content" "website-static"))
;; Disable some defaults
;; Custom options
:with-emphasize t ; *:t
:with-smart-quotes t ; *:t
:with-sub-superscript nil ; ^:nil
:with-toc nil ; toc:nil
:section-numbers nil ; num:nil
:html-preamble "<p>Published: %d</p>"
:html-postamble "<p>Last updated: %C</p>"