-
Notifications
You must be signed in to change notification settings - Fork 0
/
jekyll.plugins.bash
executable file
·284 lines (241 loc) · 6.16 KB
/
jekyll.plugins.bash
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# shellcheck shell=bash
cite about-plugin
about-plugin 'Manage your jekyll site'
function editpost() {
about 'Edit a post'
group 'Jekyll'
local SITE site POST DATE TITLE POSTS
local -i COUNTER=1 POST_TO_EDIT ret
if [[ -z "${1:-}" ]]; then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
for site in "${SITES[@]:-}"; do
if [[ "${site##*/}" == "$1" ]]; then
SITE="${site}"
break
fi
done
if [[ -z "${SITE:-}" ]]; then
echo "No such site."
return 1
fi
pushd "${SITE}/_posts" > /dev/null || return
for POST in *; do
DATE="$(echo "${POST}" | grep -E -o "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
TITLE="$(grep -E -o "title: (.+)" < "${POST}")"
TITLE="${TITLE/title: /}"
echo "${COUNTER}) ${DATE} ${TITLE}"
POSTS[COUNTER]="$POST"
COUNTER="$((COUNTER + 1))"
done > >(less)
read -rp "Number of post to edit: " POST_TO_EDIT
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
}
function newpost() {
about 'Create a new post'
group 'Jekyll'
local SITE site FNAME_POST_TITLE FNAME YAML_DATE
local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
local -i loc=0 ret
if [[ -z "${1:-}" ]]; then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
if [[ -z "${SITE}" ]]; then
echo "No such site."
return 1
fi
for site in "${SITES[@]}"; do
if [[ "${site##*/}" == "$1" ]]; then
SITE="$site"
JEKYLL_FORMATTING="${MARKUPS[loc]}"
break
fi
loc=$((loc + 1))
done
# Change directory into the local jekyll root
pushd "${SITE}/_posts" > /dev/null || return
# Get the date for the new post's filename
FNAME_DATE="$(date "+%Y-%m-%d")"
# If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
OPTIONS=('Text' 'Quote' 'Image' 'Audio' 'Video' 'Link')
if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then
select OPTION in "${OPTIONS[@]}"; do
POST_TYPE="${OPTION}"
break
done
fi
# Get the title for the new post
read -rp "Enter title of the new post: " POST_TITLE
# Convert the spaces in the title to hyphens for use in the filename
FNAME_POST_TITLE="${POST_TITLE/ /-}"
# Now, put it all together for the full filename
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
# And, finally, create the actual post file. But we're not done yet...
{
# Write a little stuff to the file for the YAML Front Matter
echo "---"
# Now we have to get the date, again. But this time for in the header (YAML Front Matter) of the file
YAML_DATE="$(date "+%B %d %Y %X")"
# Echo the YAML Formatted date to the post file
echo "date: $YAML_DATE"
# Echo the original post title to the YAML Front Matter header
echo "title: $POST_TITLE"
# And, now, echo the "post" layout to the YAML Front Matter header
echo "layout: post"
# Close the YAML Front Matter Header
echo "---"
echo
} > "${FNAME}"
# Generate template text based on the post type
if [[ $JEKYLL_FORMATTING == "markdown" ]]; then
case $POST_TYPE in
"Text")
true
;;
"Quote")
echo "> Quote"
echo
echo "— Author"
;;
"Image")
echo "![Alternate Text](/path/to/image/or/url)"
;;
"Audio")
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
;;
"Video")
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
;;
"Link")
echo "[link][1]"
echo
echo "> Quote"
echo
echo "[1]: url"
;;
esac
elif [[ $JEKYLL_FORMATTING == "textile" ]]; then
case $POST_TYPE in
"Text")
true
;;
"Quote")
echo "bq. Quote"
echo
echo "— Author"
;;
"Image")
echo "!url(alt text)"
;;
"Audio")
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
;;
"Video")
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
;;
"Link")
echo "\"Site\":url"
echo
echo "bq. Quote"
;;
esac
fi >> "${FNAME}"
# Open the file in your favorite editor
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${FNAME}"
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
}
function testsite() {
about 'Launches local jekyll server'
group 'Jekyll'
local SITE site
local -i ret
if [[ -z "${1:-}" ]]; then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
for site in "${SITES[@]}"; do
if [[ "${site##*/}" == "$1" ]]; then
SITE="$site"
break
fi
done
if [[ -z "${SITE}" ]]; then
echo "No such site."
return 1
fi
pushd "${SITE}" > /dev/null || return
jekyll --server --auto
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
}
function buildsite() {
about 'Builds site'
group 'Jekyll'
local SITE site
local -i ret
if [[ -z "${1:-}" ]]; then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
for site in "${SITES[@]}"; do
if [[ "${site##*/}" == "$1" ]]; then
SITE="$site"
break
fi
done
if [[ -z "${SITE}" ]]; then
echo "No such site."
return 1
fi
pushd "${SITE}" > /dev/null || return
rm -rf _site
jekyll --no-server
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
}
function deploysite() {
about 'rSyncs site to remote host'
group 'Jekyll'
local SITE site REMOTE
local -i loc=0 ret
if [[ -z "${1:-}" ]]; then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
for site in "${SITES[@]}"; do
if [[ "${site##*/}" == "$1" ]]; then
SITE="$site"
# shellcheck disable=SC2153 # who knows
REMOTE="${REMOTES[loc]}"
break
fi
loc=$((loc + 1))
done
if [[ -z "${SITE}" ]]; then
echo "No such site."
return 1
fi
pushd "${SITE}" > /dev/null || return
rsync -rz "${REMOTE?}"
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
}
# Load the Jekyll config
if [[ -s "$HOME/.jekyllconfig" ]]; then
source "$HOME/.jekyllconfig"
fi