Extremely meta and brief blog post that serves as 1) a reminder to myself how I achieved something and 2) potentially to help someone reading this (though it's unlikely).
I run this website via eleventy, and I create the blog posts as .md-flavoured text files. They all have the following at the start of every file:
---
title: "Creating a 'new blog entry' shortcut for creating blog posts in nano for eleventy"
description: ""
date: "2025-01-29"
---
I always have to check the formatting of this frontmatter when I sit down to write a blog post, which is a pain. So I asked ChatGPT how to set up a shortcut to automatically create a new .md file with pre-populated frontmatter for today's date.
Here's the code it came up with:
newblog() {
file="$(date +%y%m%d).md"
cat > "$file" <<EOF
---
title: "TITLE"
description: ""
date: "$(date +%Y-%m-%d)"
---
EOF
nano +"$(($(wc -l < "$file") + 1))" "$file"
}
And it seems to work well.
I had to add the above code to my /.bashrc file using nano, and then run source /.bashrc.
Once I'd done that, I just go to my eleventy setup's src/blog folder, type newblog and then I'm magically placed into an open text file with a dummy title, today's date, and the filename is also today's date. Perfect!