-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.sh
executable file
·45 lines (29 loc) · 970 Bytes
/
post.sh
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
33
34
35
36
37
38
#!/bin/bash
# post.sh; generating new markdown posts with metadata
# Baoyi Chen 2017
TARGET_FOLDER=~/Github/blog/_posts # specify the target folder
#TARGET_FOLDER=. # or you can choose current folder
#
# generate a new post
#
post() {
NOW=$(date "+%Y-%m-%d %H:%M") # get the date info
DAY=$(date "+%Y-%m-%d")
DASHEDTITLE="$1" # get date connected with dashes
if [[ "$@" != "$1" ]]
then
for WORD in ${@:2}
do DASHEDTITLE+="-$WORD"
done
fi
echo "---
title: $@
author: Baoyi Chen
updated: $NOW
---" > $TARGET_FOLDER/$DAY-$DASHEDTITLE.md # add metadata
OPENORNOT=true # Set the value to false if automatically openning is not desired
if [ "$OPENORNOT" = true ]
then
open $TARGET_FOLDER/$DAY-$DASHEDTITLE.md
fi
}