Hello! I studied Computer Science, now I live in Bath! I write code, design games, and occasionally tweet. Why not subscribe?

Posts from 2019

How to Make Jekyll Category and Year Pages Without Plugins

Posted March 20, 2019. Jekyll, Text. 346 words.

Jekyll is fantastic, easy to use, and extensible. However, some Jekyll hosts such as GitHub Pages do not allow people to use custom plugins - and I want category and year pages. But rightly so. Allowing custom plugins would require hosts to allow users to run arbitary Ruby code on their build servers and possibly create a mess. This problem is solvable, but it’s ultimately simpler to just ban them entirely.

This constrained environment forces you to get creative. On this blog I use the fantasic jekyll-compress-html template which minifies the very post you are reading. I have written by own template to automatically replace standard markdown or HTML images with lazily loaded ones. And finally, I have written a small (it’s only a hundred or so lines ;) ) Makefile to automatically, among other-things, generate year and category pages:

# Find categories and years
CATTARGETS  = $(shell grep -h '^categories:' -r _posts/ | awk -F ':' \
              '{print $$2}' | tr ' ' '\n' | sed '/^$$/d' | sort | uniq | \
              awk '{print "categories/"$$1".html"}')
YEARTARGETS = $(shell find _posts/ -regextype egrep -regex '.*/[0-9]{4}.[^/]*' \
              -printf '%P\n' | cut -c-4 | sort | uniq | \
              awk '{print "years/"$$1".html"}')

# Generate category pages
cat: cat-clean $(CATTARGETS)
categories/%.html: _templates/category.html
	cp $< $@
	sed -i 's/#####CATEGORY#####/$*/' $@

# Generate year pages
year: year-clean $(YEARTARGETS)
years/%.html: _templates/year.html
	cp $< $@
	sed -i 's/#####YEAR#####/$*/' $@

To use, simply create _templates/category.html and a _templates/year.html templates and run make cat year. The code assumes your posts start with the date and they are stored in the default _posts/. When run #####CATEGORY##### and #####YEAR##### will be replaced with the templated value.

I̵n̵t̵e̵r̵a̵i̵l̵i̵n̵g̵, No Flying into Malaga

Posted March 11, 2019. Photos, Travel. 238 words.

I briefly flew to Malaga.

In The Sky

In The Sky

On The Streets

On The Streets

By The Beach Time To Sleep

By The Beach and Time To Sleep.

The Next Day Buried Remains

The Next Day and Buried Remains.

Hello There Towering Castle

Hello There, a Towering Castle.

Inside Are Gardens A View Of The City

Inside Are Gardens and a View Of The City.

A View Of The Town

A View Of The Town

Ugshot Squirrel Cats

Ugshot. Squirrel? Cats!

Obligatory Photo

Obligatory Photo

Reading Till Dusk Giraffes

Reading Till Dusk. Giraffes.

Watching A Protest Listening To The Drums

Watching A Protest. Listening To The Drums.

In The Market

In The Market

Towering Over Cramped Checking Out

Towering Over. Cramped. Checking Out.

Flying Home

Flying Home, the Question is Where Next?

Let it Snow!

Posted February 1, 2019. Photos, Snow, Text. 24 words.

Let it snow

Not a great photo, still alive. Have an avatar generator.

StatCounter Pixel