Skip to content

Instantly share code, notes, and snippets.

@helenvholmes
Last active October 26, 2015 01:11
Show Gist options
  • Save helenvholmes/04a8c2bc909ffcd8334b to your computer and use it in GitHub Desktop.
Save helenvholmes/04a8c2bc909ffcd8334b to your computer and use it in GitHub Desktop.
Create Jekyll posts with their YAML matter quickly from the command line.
#!/bin/bash
echo "Title of post:"
read title
echo "Description of post:"
read description
echo "Tag post:"
read tags
dateStr=$(date +%Y'-'%m'-'%d'-') # Current date
blogFolder=~/boondoggles/thoughts/_posts # _posts folder of Jekyll blog
YAML=$'---
layout: post
title: '$title'
description: '$description'
tags: ['$tags']
---' # YAML matter at top of blog post
lowercase=$(echo "$title" | tr '[:upper:]' '[:lower:]')
formattedTitle=${lowercase// /-}
echo $formattedTitle
newFile=$dateStr$formattedTitle'.md'
echo "$YAML" > $blogFolder/$newFile # Create post in correct folder
vim $blogFolder/$newFile
@daneden
Copy link

daneden commented Nov 26, 2014

This is sweet. Thanks for sharing!

@helenvholmes
Copy link
Author

@daneden thanks for liking it!

Should mention, I've updated it since you commented - before I was opening the file in the wrong place, creating a post in whatever directory you were in... whoops.

@helenvholmes
Copy link
Author

Updates, 12/14/14:

I wrote a blog post about what's happening in this script here. Also looks like this has inspired a new companion gem for Jekyll called Jekyll Compose that's worth keeping an eye on as it matures. Awesome!

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