Skip to content

Instantly share code, notes, and snippets.

Last active October 10, 2020 00:28
What would you like to do?
Alfred workflow for creating a new Jekyll blog post
# In Alfred, create a new Blank Workflow and add a Keyword Input (Argument Required/uncheck With Space), mine is "new blog:" (without the quotes)
# Add a Run Script Action and make sure /bin/bash is selected in the Language dropdown
# Copy this Gist into the Run Script action (replacing the default text)
# Connect the Keyword action to the Run Script action
# Open an Alfred prompt and enter "new blog:My New Blog" without the quotes
# Watch the magic happen...
# enter the path to our jekyll directory
# then skip to the very last line and edit it
# get the title from the input
# replace spaces with hyphens
permalink=$(echo "{query}" | tr " " "-")
# convert permalink to lowercase
permalink=$(echo "$permalink" | tr '[:upper:]' '[:lower:]')
# today's date
now=$(date +'%Y-%m-%d')
# build link to file and filename
# create the file
touch "$file"
# insert the yaml front matter and add the title, date and permalink
echo "---
layout: post
title: \""{query}"\"
date: "$now"
permalink: /blog/"$now"/"$permalink"/
" >> "$file"
# open file in our markdown editor and start writing!
# change "Markdown Pro" to your preferred Markdown or text editor
open -a "Markdown Pro" "$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment