Skip to content

Instantly share code, notes, and snippets.

@timgavin
Last active October 10, 2020 00:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timgavin/a08a900946348f33c3ed to your computer and use it in GitHub Desktop.
Save timgavin/a08a900946348f33c3ed to your computer and use it in GitHub Desktop.
Alfred workflow for creating a new Jekyll blog post
#!/bin/bash
# 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
path=/path/to/your/jekyll/_posts/
# get the title from the input
title=({query})
# 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
file="$path""$now"-"$permalink".md
# create the file
touch "$file"
# insert the yaml front matter and add the title, date and permalink
echo "---
layout: post
title: \""{query}"\"
date: "$now"
categories:
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