Skip to main content
stinky.blog

Create New Post script

Quickly create new posts #

Made this little script to generate the front matter for new blog posts and open them in the editor. Estimated to save dozens of seconds over the course of my lifetime

#!/bin/bash

#gather post info

echo "Post title?"
read title

echo "Post description?"
read description

current_date=$(date +%Y-%m-%d)

echo "Post tags? (one or more, comma separated, like, this)"
read tags

#clean up tags

tidytags=$(echo $tags | sed "s/, /\\n  - /g")

#generate post metadata

fmatter="---
title: \"$title\"
description: \"$description\"
date: $current_date
tags:
  - $tidytags
---
"
#convert title to filename

filename=$(echo $title | tr '[:upper:]' '[:lower:]' | tr ' ' '-').md

#write metadata to filename
echo "$fmatter" > "./content/blog/$filename"

#open vim @ filename
vim "./content/blog/$filename"