Shell Script for Creating Markdown Templates

Image of Author
March 14, 2022 (last updated September 11, 2023)
  • The below script assumes a directory called repo inside of which is a folder called ./content/ which contains arbitrary markdown content.

  • The markdown file is prepended with yaml, in between the --- syntax.

  • After creating the file it is immediately opened in vim.

    nn "New Note" new-note
    
function nn() {
  cd ~/w/g/repo
  local filename="./content/$2.md"
  local datestring="$(date +%F)"
  touch $filename
  cat << DELIMIT > $filename
---
title: $1
slug: $2
published: $datestring
updated: $datestring
---

# $1

DELIMIT

  vim $filename
}