Add script to generate skeleton files for blog posts

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2019-05-31 23:53:05 +05:30
parent 5a62fe7817
commit 3d32b0e7ad
1 changed files with 25 additions and 0 deletions

25
generate_post_skeleton.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
set -euo pipefail
base_template="
+++
date = \"%s\"
title = \"%s\"
slug = \"%s\"
tags = []
categories = []
+++
"
function create_post() {
local title filename postslug postdate
title="${1}"
postdate="$(date +"%Y-%m-%d")"
postslug="$(echo ${title:?} | tr -dc '[:alnum:][:space:]\n\r' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
filename="${postslug}.md"
printf "${base_template}" "${postdate}" "${title}" "${postslug}" > content/posts/"${filename}"
}
create_post "${@}"