How This Site is Built

2019-08-15 Homepage

This is the first entry on I put together this blog / website so I have some place to record what I learn and create on a day-to-day basis. I would like to spend more time engaging with the world in a way I find meaningful. Right now I am unemployed, and it’s becoming pretty apparent that I need some artificial contrivances to keep me on task, and I think this personal learning journal will serve that function pretty well. And I might as well make it anonymous and public, since I have this otherwise unused domain name sitting around.

This site consists of a collection (sparse, at the moment) of markdown files in a source tree. GNU make is used in conjunction with a couple awk heavy bash scripts in order to turn the markdown files into a website and generate the main index page at Pandoc is used to do the markdown -> html heavy lifting.

I do not have any previous experience with make and very little with awk, so this solution turned out to be very unsophisticated. There are 3 main files used in the generation of the website: makefile (of course),, which creates the main index based on YAML meta-data blocks at the beginning of each markdown file in its search path, and, which simply creates a markdown file within the blog directory with the naming scheme ‘’. If this file already exists, simply opens it for editing in vim.

At the time of writing this, the directory structure looks like this:

├── src
│   ├── blog
│   │   ├──
│   │   └── folderinfo.yaml
│   ├── buildres
│   │   ├──
│   │   ├──
│   │   └──
│   ├──
│   └── res
│       └── style.css
├── makefile
└── deploy
    ├── blog
    │   └── 2019-08-15.html
    ├── index.html
    └── res
        └── style.css

If the deploy directory were empty, one could rebuild the site by running make. Running make will do 3 things:

  1. If any file within src/res/ has changed, it will be copied into deploy/res/

  2. Any new or modified *.md files within the src/blog directory are converted into .html files using pandoc and placed in the deploy/blog directory. The makefile is designed such that adding more directories in the future alongside blog, such as stories or other categories, is trivially easy. The and files are automatically included with the creation of each file.

  3. creates an index of the markdown posts within a list of directories. The script extracts title, date, and abstract metadata from a YAML metadata block at the beginning of each post. The script uses folderinfo.yaml at the root of each directory to get the proper title for the directory. Currently, the only directory it searches is blog, but this can be easily changed in the future.

Since the posts are named according to the date of their creation, it is easy to correctly order the index. uses the file names to order the index for each subdirectory it indexes. Since the intended use of this blog is as a journal, I will not be writing posts over a long period of time or revisiting past posts often, so the inadequacies of a non-descriptive name are not an issue. It is a primitive solution, but it is easy and straight-forward.

There are a number of very obvious shortcomings to the site at the moment, including that only the main /index.html is generated. I will be making small improvements as I run into issues, but overall am happy with how the site generation process works at the moment. Despite its simplicity, this will serve my purposes for the time being.

I am including the source for each of 3 main files as they are today. I will not be updating these in the future, but may host the living files on github or gitlab or a similar service at some point.

#!/usr/bin/env bash

if [ ! -e src/blog/$(date -I).md ]; then
  printf "%s\n%s\n%s\n%s\n%s\n" \
    "title: $(date -I)" \
    "date: $(date -I)" \
    "abstract: |" "---" \
    > src/blog/$(date -I).md
vim src/blog/$(date -I).md

#!/usr/bin/env bash

if [ $# -gt 1 ]; then
  if [ -d $1 ]; then
    cd $1
    for dirname in "${@:2}"; do
      if [ -d "$dirname" ]; then
        if [ -e "$dirname/folderinfo.yaml" ]; then
          echo "## $(awk -F: '/title:/ {print $2;exit;}' $dirname/folderinfo.yaml)"
          echo "## $dirname"
        for filename in $(find "$dirname" -name "*.md" | sort -r); do
          title=$(awk -F: '/title:/ {print $2;exit;}' "$filename")
          date=$(awk '/date:/ {print $2;exit;}' "$filename")
          abstract=$(awk \
            '/abstract: \|/,/---/{if(/---|abstract: \|/) next; print}' \
          htmlfn=$(echo $filename | sed 's/.md$/.html/')
          printf "### [%s](%s)\n" "$title" "$htmlfn"
          printf "Created: %s\n\n" "$date"
          printf "Summary: %s\n\n" "$abstract" 
    echo "$1 is not a directory"
  echo "Correct usage: ./ <src dir> [<subdirectories with .md files> ...]" 


srcdir := src
subdirs := blog

resdir := $(srcdir)/res
reslist = $(shell find $(resdir) -type f)
outreslist = $(reslist:$(srcdir)/%=$(outdir)/%)
stylesheet := /res/style.css

buildresdir := $(srcdir)/buildres
buildress = $(wildcard $(buildresdir)/*)

panoptions := -s -w html --css=$(stylesheet)

outdir := deploy

srcs = $(foreach dir,$(subdirs),$(wildcard $(srcdir)/$(dir)/*.md))
objs = $(srcs:$(srcdir)/$(outdir)/%.html)

$(outdir)/%.html : $(srcdir)/ $(buildress)
    mkdir -p $(@D)
    pandoc $(panoptions) -o $@ $(buildresdir)/ $< $(buildresdir)/

all : resources html index

resources : $(outreslist)

$(outreslist) : $(reslist)
    mkdir -p $(@D)
    cp $< $@

html : $(objs)

index : $(outdir)/index.html
$(outdir)/index.html : $(srcs) $(buildress)
    @rm -f $(buildresdir)/
    ./ $(srcdir) $(subdirs) >> $(buildresdir)/
    pandoc $(panoptions) --toc --toc-depth=2 -o $(outdir)/index.html \
    $(buildresdir)/ $(buildresdir)/ $(buildresdir)/
    @rm -f $(buildresdir)/

clean : 
    rm -rfv $(outdir)/*
    rm -fv $(buildresdir)/