← Back to 11ty notes

Creating an 11ty blog post using Raycast

Speeding up my blog workflow

• 🍿 2 min. read

I've been loving using Raycast recently, and I wanted to see if I could speed up blog post file creation, given I used to create all posts initially using an Alfred workflow.

Raycast has the ability to trigger bash scripts on the local file system, so I figured I could use this to create a new post file.

A quick Google gave me the useful post and bash script example from Sam Warnick.

Combining that with passing in bash params (raycast docs)
and I ended up with the following:

#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title blog
# @raycast.mode compact

# Optional parameters:
# @raycast.icon πŸ€–

# Documentation:
# @raycast.description Create blog post
# @raycast.author alpower
# @raycast.authorURL https://raycast.com/alpower
# @raycast.argument1 { "type": "text", "placeholder": "title" }

today=$(date +%Y-%m-%d)
publish=$(date -v +1H +"%Y-%m-%d %H:00")
filename="${1// /-}"
path="/Users/johnsmith/eleventy/src/blog/$today-$filename.md"
title="${1}"

template="---
title: $title
date: $today
permalink: blog/$filename/index.html
tags:
summary:
---
written on $publish
"


printf -- "$template" >> "$path"

open -a "Visual Studio Code" "$path"

Some notes:

  • The @raycast.title blog is whatever command you want to trigger the script with.
  • The filename variable takes the query param title and hyphenates.
  • The path variable is whereever you store your blog entries on your local file system.
  • The publish variable is not needed - just added incase ever want to use today's date and time.
  • permalink is because I want to start ordering my markdown with the date to find files faster, but not have the dates show in the URLs.
  • I added the date in as YAML frontmatter as I use it in my listing code - this is optional if you include it in your filename.
  • The final open command can be any application you want on your Mac that edits text files - I also tried this with iA Writer and it worked fine.

Usage

Trigger Raycast. Type blog and tab to the title field. Enter a title like my test post gives you a file with a filename of YYYY-MM-DD-my-test-post.md

/TODO Still needed

It's not perfect by any means - I still need to solve escaping single quotes in the title and also lowercasing the file name, but it's a good start to get me blogging faster!

← Back to 11ty notes