Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Nov 26, 2014

This is sweet. Thanks for sharing!

@helenvholmes

This comment has been minimized.

Copy link
Owner Author

commented Dec 1, 2014

@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

This comment has been minimized.

Copy link
Owner Author

commented Dec 14, 2014

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
You can’t perform that action at this time.