Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Jekyll tasks/post to help create a new post.
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo "Usage: provide a title argument."
exit -1
else
title="$@"
fi
d=$(date +"%Y-%m-%d")
slug=$(echo $title | tr '[:upper:]' '[:lower:]' | tr '[:space:]' '-')
slug="${slug:0:${#slug}-1}"
post="./_posts/$d-$slug.md"
body=""
read -d '' body <<EOF
---
layout: post
title: $title
categories:
-
---
EOF
echo "$body" > $post
subl . $post

tpitale commented Sep 6, 2013

You could also use thor, if you have other tasks as well: https://github.com/tpitale/tpitale.github.com/blob/master/tasks/post.thor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment