Just released - The Imposter's Roadmap! Go Get It

Buy or Subscribe

You can access this course in just a minute, and support my efforts to rid the world of crappy online courses!

Buy Standalone  Subscribe

I use the static site generator Jekyll to write my blog. I store the site at Github, who then translates and hosts it all for me for free. Jekyll is simple to use and I like it a lot. There's only one problem: it's a bit manual.

Every post that you create has to have a very specific filename in the form of year-month-day-post-slug.md. Not that big of a problem, just a mere annoyance. In addition, every post you have must have a blob of text at the top called the front matter. Again: not a huge problem, just kind of time consuming. The perfect candidate for a little help from a shell script.

#!/bin/bash
# a Jekyll post creator, which creates a new file, adds frontmatter,
# and opens the editor and starts Jekyll
new_post() {
  JEKYLL_ROOT=~/Documents/Sites/conery-io-jekyll
  JEKYLL_POSTS=$JEKYLL_ROOT/_posts
  TITLE=$1
  SLUGIFIED="$(echo -n "$TITLE" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)"
  NEW_POST_FILE=$JEKYLL_POSTS/$(date +%Y-%m-%d-$SLUGIFIED.md)

  cat <<frontmatter > $NEW_POST_FILE
---
layout: post-minimal
title: "$TITLE"
image: ''
comments: false
categories:
summary: ""
---
frontmatter

  echo "New post created, opening in Atom, starting Jekyll"
  atom $NEW_POST_FILE
  jekyll serve -s $JEKYLL_ROOT
}