Last active
October 26, 2015 01:11
-
-
Save helenvholmes/04a8c2bc909ffcd8334b to your computer and use it in GitHub Desktop.
Create Jekyll posts with their YAML matter quickly from the command line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 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.
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
This is sweet. Thanks for sharing!