This website is suitable for a lazy engineer:
The first draft of this website used Emacs’ Org mode to write the content in. That was ok, but eventually fell apart - remembering the keyboard shortcuts to generate html (org-export if anyone was wondering) and move files around was an unnecessary roadblock when publishing. Building a deploy pipeline that wants to run Emacs in batch mode also just seems like a bad idea, I long ago got tired of any project where I might have to start using Elisp.
sudo apt install pandoc
)./install --dir /home/owen/bin
- version 1.3.182)I set up a file directory like so:
owen@persistance:11:53:06:~/web$ tree
.
├── bb.edn
├── html
│ └── index.html
├── markdown
│ └── index.md
└── update.clj
With the files:
bb.edn
;; Not needed, makes Emacs' CIDER happier
{}
update.clj
#!/usr/bin/env bb
;; Run Clojure using Babashaka.
;; This file generates and uploads my website content. Inputs are stored in the
;; `markdown` folder. They are converted to HTML files by pandoc and put in the
;; `html` folder which is then uploaded to the web server with rsync.
ns web.update
(:require
(:as sh]
[babashka.process :as io]
[clojure.java.io :as string]
[clojure.string :as log]))
[taoensso.timbre
:info)
(log/set-level!
defn get-markdown-files
("
List all the files in ~/web/markdown. We assume that everything in that folder
is a markdown file - pandoc will get confused if anything else is there.
"
[]->> "/home/owen/web/markdown" io/file .listFiles (map #(.getPath %))))
(
defn to-html-path
("
Translate, eg, /home/owen/web/markdown/index.md ->
/home/owen/web/html/index.html
"
[md-path]-> md-path
("markdown" "html")
(string/replace-first #".md$" ".html")))
(string/replace
defn to-markdown
("
This command runs `pandoc`. Notes:
- If we don't flag the output file with `-o` then there is an error, eg,
openBinaryFile: does not exist (No such file or directory)
- `--toc` adds a table of contents
- `--standalone` adds HTML headers & footers
"
[md-path]"Processing" md-path)
(log/debug let [pandoc-options
("--standalone"
["--toc"
"--highlight-style=zenburn"
"-o" (to-html-path md-path)
md-path]]apply sh/shell (into ["pandoc -f markdown -t html"] pandoc-options))))
(
defn sync-site
("Relies on ssh being configured"
[]"rsync --delete -v -r html/ [email protected]:/var/www/html/"))
(sh/shell
do
(;; `map` is lazy, so we prefer `mapv` to stop this silently failing as Clojure
;; assumes there are no side effects and silently optimises this out.
->> (get-markdown-files) (mapv to-markdown))
( (sync-site))
--css
flag to the pandoc invocation. This was
mainly to move the Table of Contents off to the side, away from the main
page.