ssg and org-mode

ssg is a small shell script for generating static sites using Markdown. It's major claim to fame is being small and simple. While simplicity is good, Markdown is not super expressive and one has to drop to HTML to do complicated things. org-mode on the other hand is simple and expressive.

org-mode already has a way to turn org-mode files into HTML but it can be a pain to setup and it also generates complicated HTML. But org-mode can export to Markdown.

To do this, a Makefile will be used to convert .org files to .md files. Then ssg will be run on the .md files. Because ssg just does a blind rsync of the generated content the .org files are deleted from the output. This isn't strictly necessary.

Directory Structure

Below is the directory structure of the project. The src directory .org files and the html directory is the generated output, in this case.

.
├── Makefile
├── bin
│   └── ssg
├── html
│   ├── index.html
│   ├── rss.xml
│   ├── sitemap.xml
│   └── ssg-and-org-mode
│       └── index.html
└── src
    ├── _ssg.conf
    ├── _styles.css
    ├── index.org
    └── ssg-and-org-mode
        └── index.org

Makefile

This Makefile assumes that there is an index.org in the src directory and that all other content is one directory deeper, named index.org as well.

.PHONY: all clean

posts=$(wildcard src/*/index.org)
md_posts=$(posts:%.org=%.md)

export DOCS=$(PWD)/html

all: src/index.html

src/index.html: src/index.md $(md_posts)
    mkdir -p "$(DOCS)"
    cd src && ../bin/ssg build
    find "$(DOCS)" -name '*.org' -delete
    find "$(DOCS)" -name '*~' -delete

%.md: %.org
    emacs $< --batch -f org-md-export-to-markdown --kill

_ssg.conf

#!/bin/sh

ROOT='https://articles.nhmtech.com'
WEBSITE_TITLE='NHM Tech Articles'
RSS_AUTHOR='SWIM'
RSS_DESCRIPTION='NHM Tech Articles'

index.org

Finally, when using the HTML publishing feature of org-mode one can link to other .org files and they will be automatically published. That is not the case here, so any links to generated content must link to the .html file.

For example, index.org:

#+OPTIONS: toc:nil

* Articles

- [[file:ssg-and-org-mode/index.html][ssg and org-mode]]