-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbythew3i.sh
executable file
·148 lines (133 loc) · 3.61 KB
/
bythew3i.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
init_post() {
# $1: name
# $2: title
# $3: date
# $4: header_image
file="_posts/$3-$1.md"
touch $file
echo "---" >> $file
echo "layout: post" >> $file
echo "title: $2" >> $file
echo "subtitle: XXX" >> $file
echo "date: $3" >> $file
echo "author: bythew3i" >> $file
mkdir -p "assets/$3-$1"
echo "assets-path: /assets/$3-$1/" >> $file
if [[ $4 -eq 1 ]]; then
echo "header-img: assets/$3-$1/XXX" >> $file
echo "header-mask: 0.5" >> $file
else
echo "header-style: text" >> $file
fi
echo "catalog: true" >> $file
echo "tags:" >> $file
echo " - A" >> $file
echo " - B" >> $file
echo "---" >> $file
echo "$file is created successfully!"
code $file >> /dev/null 2>&1
}
init_keynote() {
# $1: name
# $2: title
# $3: date
file="_posts/$3-$1.md"
touch $file
echo "---" >> $file
echo "layout: keynote" >> $file
echo "title: $2" >> $file
echo "subtitle: XXX" >> $file
echo "date: $3" >> $file
echo "author: bythew3i" >> $file
echo "iframe: Slides Path" >> $file
echo "navcolor: invert" >> $file
echo "tags:" >> $file
echo " - A" >> $file
echo " - B" >> $file
echo "---" >> $file
echo "$file is created successfully!"
code $file >> /dev/null 2>&1
}
init_page() {
# $1: name
# $2: title
file="$1.html"
touch $file
echo "---" >> $file
echo "layout: page" >> $file
echo "title: $2" >> $file
echo "description: XXX" >> $file
echo "header-img: XXX" >> $file
echo "header-mask: 0.5" >> $file
echo "hide-in-nav: true" >> $file
echo "---" >> $file
echo "$file is created successfully!"
code $file >> /dev/null 2>&1
}
init_default() {
# $1: name
# $2: title
file="$1.html"
touch $file
echo "---" >> $file
echo "layout: default" >> $file
echo "title: $2" >> $file
echo "description: XXX" >> $file
echo "header-img: XXX" >> $file
echo "header-mask: 0.5" >> $file
echo "hide-in-nav: true" >> $file
echo "---" >> $file
echo "$file is created successfully!"
code $file >> /dev/null 2>&1
}
echo "Layouts:"
echo " - [P]OST"
echo " - [T]EXT"
echo " - [K]EYNOTE"
echo " - [PA]GE"
echo " - [D]EFAULT"
read -p 'Please choose a layout (p): ' btw_type
read -p 'Please enter a title: ' btw_title
if [[ -z "$btw_title" ]]; then
echo "Error: Title can not be empty"
exit 1
fi
btw_name=$(tr -d [:punct:] <<< $btw_title)
btw_name=$(tr [A-Z] [a-z] <<< $btw_name)
btw_name=${btw_name// /-}
# echo $btw_name
prompt_date() {
read -p 'Please enter a date YYYY-MM-DD: ' btw_date
if [[ -z "$btw_date" ]]; then
btw_date=$(date +'%Y-%m-%d')
fi
date -f "%Y-%m-%d" -j $btw_date >/dev/null 2>&1
if [ $? != 0 ]; then
echo "Error: Date $btw_date is not a valid YYYY-MM-DD date"
exit 1
fi
}
btw_type="$(tr [A-Z] [a-z] <<< "$btw_type")"
case $btw_type in
"k" | "keynote")
echo "keynote"
prompt_date
init_keynote "$btw_name" "$btw_title" "$btw_date"
;;
"pa" | "page")
init_page "$btw_name" "$btw_title"
;;
"d" | "default")
init_default "$btw_name" "$btw_title"
;;
"t" | "text")
prompt_date
echo $btw_date
init_post "$btw_name" "$btw_title" "$btw_date" 0
;;
*)
prompt_date
init_post "$btw_name" "$btw_title" "$btw_date" 1
;;
esac