Hi there!

You need to be logged in to view this course.

Hands On: Creating a Useful Shell Script

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.

# a Jekyll post creator, which creates a new file, adds frontmatter,
# and opens the editor and starts Jekyll
new_post() {
  SLUGIFIED="$(echo -n "$TITLE" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)"

  cat <<frontmatter > $NEW_POST_FILE
title: "$TITLE"
image: ''
comments: false
summary: ""

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