-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_create_post.sh
More file actions
executable file
·32 lines (27 loc) · 897 Bytes
/
_create_post.sh
File metadata and controls
executable file
·32 lines (27 loc) · 897 Bytes
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
31
32
#!/bin/bash
cd ~/Development/clockworkpc.github.io
ymlTemplate=$(cat _front_matter_template.yml)
targetTimezone="America/New_York"
currentDate=`TZ=$targetTimezone date`
dateStamp=`TZ=$targetTimezone date +"%Y"-%m-%d-`
myTitle=$1
myTags=$2
# Generate YAML front matter by sub-string replacement
myYml="${ymlTemplate/MY_TITLE/\"$myTitle\"}"
myYml="${myYml/MY_DATE/\"$currentDate\"}"
myYml="${myYml/MY_TAGS/$myTags}"
myBasename="${myTitle}"
myBasename=`echo $myBasename | sed 's/[^a-zA-Z0-9]/_/g' | sed -e 's/\([_]\)\1\+/\1/g'`
# filePath="`pwd`/_posts/${dateStamp}${myBasename}.md"
filePath="`pwd`/_posts/${dateStamp}${myBasename}.md"
if [[ -z "$myTitle" ]] ; then
echo "No title provided"
elif [[ -z "$myTags" ]] ; then
echo "No tags provided"
else
nvim "${filePath}"
glow "${filePath}"
echo -e "${myYml}\n$(cat $filePath)" > $filePath
git add .
git commit -m "${myBasename}"
fi