tldr; I created an Apple Shortcut that generates frontmatter for my Eleventy blog posts. Here’s the link if you want to remix it yourself
This website is built with Eleventy and my blog posts are written in markdown. Each blog post has uses frontmatter to set the title, summary, permalink, date and tags. To avoid having to manually write this out with each blog post, I’ve set up a Shortcut that I can trigger once I’m ready to publish the post, that generates all the frontmatter for me. Here’s how it works
When I trigger the shortcut, it asks for the blog post title. I then use Change Case
to set the title to lowercase, followed by a series of Replace Text
actions that replace punctuation like :
or &
with a blank space
This is followed by a URL Encode
action that takes that formatted text string and makes it URL friendly - from what I can see it just replaces all the blank spaces with %20
although it might do other things that I just haven’t noticed yet. Because I don’t want my URLs to be full of %20
, I follow this up with another Replace Text
to replace %20
with -
All of this takes a blog post title like "Need for Speed: Hot Pursuit: A (sort of) review" and creates a string that looks like need-for-speed-hot-pursuit-a-sort-of-review
I’ve then got two more Ask for Input
actions; one that asks for a Summary, and one that asks for Tags. After that, I get the current date and then assemble the frontmatter
I’ve got a text block that looks as follows
---
title: "Title"
summary: "Summary"
permalink: /blog/Formatted link/index.html
date: Date
tags:
Tags
---
title
and summary
pull the un-formatted title and summary provided at the beginning of the shortcut. They’re wrapped in " "
so that the frontmatter treats them as plain text, even if they contain punctuation or special characters
permalink
includes /blog/ followed by the formatted link followed by /index.html
date
pulls the current date and time in ISO 8601 format. I generate the frontmatter just before publishing so pulling the current date and time is fine for now. I could add a date picker earlier in the shortcut if I needed to be able to select a different date though
And finally tags
pulls the text from the Tags action. When I enter the Tags I include hyphen on the front like -Life
and when I paste this frontmatter into my file, I indent them manually because I can’t work out how to do that in Shortcuts
The final step copies this text to clipboard where I can then paste it into the top of my Bear notes file before copying the whole thing into a new markdown file
If you want to use the shortcut for yourself, here you go