| paulcapewell.com
| Snippets!
Posted on 16 March 2023

For a while I've been wondering how to quickly create the short piece of metadata that has to go at the top of every blog post's .md file.

It looks a bit like this:

And it tells the eleventy engine the title, description, and date of each blog post. I could add more stuff like labels, tags, permalink slugs, etc, but this appears to be the bare minimum.

But when I was creating a new blog post, I was going into a previous blog file, copying the metadata block from that, pasting it in, and then making the changes. No more!

Now, using Visual Studio Code's snippets, I have created a snippets file with the following block:

This allows me to create a new .md file in the ~/eleventy/src/blog/ directory, which is empty, and then press ctrl+space to bring up the command palette, then start typing bl... which brings up the 'blog metadata' snippet, press enter, and it pastes in the following:

What this is doing is pasting the whole block, grabbing today's date, and inserting the cursor into the title tag. So then I just start typing that, then enter a description if I want, and then start typing the content of the blog post under all that. Easy!

I am concerned that this means I have some reliance on VS Code, and this local environment. But I think there are ways to 'sync' my VS Code setup, and the entire local environment, if that was important to me. But for now it's fine and it can all live on this machine. I'll worry about portability another day.

I'm chalking this one up as a win.