Post

Bash script for Chirpy Jekill post template

There is a principle of shifting work to others “ Let someone else do the hard part but faithful adherence to this principle creates new dependencies.
There is a ruby gem to generate post template.
But I prefer to do it myself, although this often doesn’t justify it.

if the script had been written in powershell or nodejs it would have been clearer, but I wanted to write bash.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
title=${1^} # $1 - title has to start with uppercase
F=$(date +"%F|%T|%z")
d=$(echo $F | cut -d'|' -f 1) # date
t=$(echo $F | cut -d'|' -f 2) # time
z=$(echo $F | cut -d'|' -f 3) # timezone
name=$d-${title// /-}.md #  replaces whitespace with underscore in title

md='../_posts/'$name
if [[ ${PWD##*/} = "KosarevDmitry.github.io" ]]; then
md='./_drafts/'$name
fi 

cat >$md <<EOF
---
title: ${1^}
date: $d $t $z
categories: [${2}]
tags: [${3}]
---
EOF

notepad $md

#use ./post.sh mytitle categorie1,categorie2 mytag

# Legend
# tags: [authorisation] # tags names should always be lowercase
# categories: [Csharp, microservise] are designed to contain up to two elements

This post is licensed under CC BY 4.0 by the author.