-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_post.sh
158 lines (137 loc) · 4.06 KB
/
create_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
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
149
150
151
152
153
154
155
156
157
158
#!/bin/sh
# Create a post file at current directory
# File format: YYYY-MM-DD-title.md
current=`date -u`
current_date=`date -u --date="$current" +'%Y-%m-%d'`
current_iso8601=`date -u --date="$current" +'%Y-%m-%dT%H:%M:%S%Z'`
current_iso8601_short=`date -u --date="$current" +'%Y-%m-%dT%H%M%S%Z'`
# hashids.org
# hashids C implementation https://github.com/tzvetkoff/hashids.c
current_seconds=`date -u +%s`
hashid=`hashids --salt "rmaicle" --min-length 15 $current_seconds`
filename_prefix="$current_date"
filename=""
function show_usage {
echo "create_post"
echo " Create a jekyll post file in current directory with the format 'YYYY-MM-DD-.md'."
echo "Usage: create_post [option]"
echo ""
echo "Options:"
echo " -p, --post Post file"
echo " -h, --help Show usage"
}
function add_yaml_bar {
echo "---" >> $filename
}
function add_yaml_categories {
echo "categories: [post, c++, d_language, database, linux, jekyll, git, other]" >> $filename
}
function add_yaml_image {
echo "image:" >> $filename
echo " layout: auto_width" >> $filename
echo " source: " >> $filename
echo " attribution: " >> $filename
}
function add_yaml_video {
echo "video:" >> $filename
echo " source: " >> $filename
echo " attribution: " >> $filename
echo " layout: top" >> $filename
}
function add_yaml_videos {
echo "videos:" >> $filename
echo " - source: " >> $filename
echo " attribution: " >> $filename
echo " layout: " >> $filename
}
function add_yaml_sources {
echo "sources:" >> $filename
echo " - label: article title (source)" >> $filename
echo " link:" >> $filename
}
function add_yaml_related {
echo "related:" >> $filename
}
function add_default {
if [ $# -eq 0 ]; then
echo "title: " >> $filename
else
echo "title: $1" >> $filename
fi
echo "excerpt: " >> $filename
echo "date: $current_iso8601" >> $filename
echo "updates:" >> $filename
echo " - date: run currdate.sh" >> $filename
echo " message: Edits and corrections" >> $filename
echo "layout: post" >> $filename
}
function add_empty {
echo >> $filename
echo "Download: [](){:target='_blank'}" >> $filename
echo "Ñ ñ" >> $filename
echo "■ ▪ ▲ ▴ ◆ ▶ ▸ ► ● •" >> $filename
echo " dash-" >> $filename
echo "en dash–" >> $filename
echo "em dash—" >> $filename
echo " open single quote ‘" >> $filename
echo "close single quote ’" >> $filename
echo " open double quote “" >> $filename
echo "close double quote ”" >> $filename
echo "ellipses …" >> $filename
echo "Empty." >> $filename
echo "●" >> $filename
}
function add_content {
if [ $# -gt 0 ]; then
echo >> $filename
echo "$1" >> $filename
fi
}
function create_post {
filename="$filename_prefix-new_post.md"
if [ -e $filename ]; then
echo "File ($filename) already exists."
else
touch $filename
add_yaml_bar
add_default "Post Title"
add_yaml_categories
echo "tags: []" >> $filename
echo "draft: true" >> $filename
if [ $# -eq 0 ]; then
echo "published: true" >> $filename
else
if [ "$1" = "draft" ]; then
echo "published: false" >> $filename
else
echo "published: true" >> $filename
fi
fi
echo "permalink: /posts/$hashid" >> $filename
echo "thumbnail:" >> $filename
add_yaml_image
add_yaml_video
add_yaml_videos
add_yaml_sources
add_yaml_related
add_yaml_bar
add_empty
echo "New post file created on $current: $filename"
fi
}
##########
if [ $# -eq 0 ]; then
show_usage
exit
fi
case $1 in
-p | --post ) create_post "draft"
exit
;;
-h | --help ) show_usage
exit
;;
* ) show_usage
exit
;;
esac