-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_make.sh
executable file
·62 lines (56 loc) · 1.6 KB
/
page_make.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
#
# Shell script for creating post
# based on jekyll's layout format
# get created date
date=`date +%Y-%m-%d`
datetime=`date "+%Y-%m-%d %H:%M:%S"`
# get file title from command line
# e.g. How to use web worker api
read -p "Post Title: " title
# e.g. programming javascript blog
read -p "Categories: " category
# modify $title for jekyll's default theme
# (small capital with `-`)
# e.g. How to use web worker api > how-to-use-web-worker-api
# 1. convert all to small capital
titleSmallCapital=`tr "[:upper:]" "[:lower:]" <<< $title`
# echo $titleSmallCapital
# 2. split with space
IFS_ORIGINAL="$IFS"
IFS=" "
arr=($titleSmallCapital) #set all words into array
IFS="$IFS_ORIGINAL"
# (debug)
titleFinal=()
count=0
for v in "${arr[@]}"; do
if [ $count -eq 0 ] #you need space before and after blackets
then
titleFinal+=$v
count+=1
else
titleFinal+="-"$v
count+=1
fi
done
# create file title
filetitle=$date-$titleFinal.md
# write default layout to the file
echo '---' >> _posts/$filetitle
echo 'layout: post' >> _posts/$filetitle
echo 'title: '$title >> _posts/$filetitle
echo 'date: "'$datetime'"' >> _posts/$filetitle
echo 'categories: '$category >> _posts/$filetitle
echo 'type: posts' >> _posts/$filetitle
echo 'comments: true' >> _posts/$filetitle
echo '---' >> _posts/$filetitle
echo '' >> _posts/$filetitle
echo '[]()' >> _posts/$filetitle
echo '' >> _posts/$filetitle
echo '---' >> _posts/$filetitle
echo '' >> _posts/$filetitle
echo '### 編集後記' >> _posts/$filetitle
echo '' >> _posts/$filetitle
# open in subilme
vi _posts/$filetitle