summaryrefslogtreecommitdiff
path: root/automation/ab
blob: 8ee1b6b2ce276f45bc3db6f4415324b7a10be178 (plain)
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/bin/bash

# A horribly and overly engineered blog manager for arachnida.blog


blogdir="/home/black/website/arachnida_blog"
imgdir="/home/black/website/arachnida_blog/assets/img"
datafile="/home/black/website/doc/data.txt"
drafts="/home/black/website/doc/drafts"
template="/home/black/website/doc/templates/template.html"
index_template="/home/black/website/doc/templates/index-template.html"
index_tag_template="/home/black/website/doc/templates/index-tag-template.html"
rss_template="/home/black/website/doc/templates/rss-template.xml"
rss_file="/home/black/website/arachnida_blog/rss/rss.xml"

# Colored Output
RED='\033[0;31m'
GREEN='\033[0;32m'
RESET='\033[0m'

# Update
function update () {
	#printf 'Updating: arachnida.blog\n' | dzen2 -bg white -fg black -p 2 -x -375 -y 50 -w 275 -h 50
	rsync -uvrp --delete-after ~/website/arachnida_blog/ root@155.138.154.235:/var/www/arachnida_blog
	printf "\n\n${GREEN}Website has been updated.${RESET}\n\n"
}

# Pick an entry
function listitem () {
	printf "\nContents of %s:\n" "$1"
	case "$(ls --hide "img" "$1" | wc -l)" in
		0) printf "${RED}No drafts made yet.\n\n${GREEN}Redirecting...${RESET}\n\n" && blog ;;
		1) number=1 && printf "Only one draft available.\n" ;;
		*) ls -rc --hide "img" "$1" | awk -F '/' '{print $NF}' | sed 's/\.html$//' | nl # edited
			printf "\nPick and entry by number to %s" "$2: " | sed 's/blog_//g' && read number
	esac
	entry="$(ls --hide "img" -rc "$1" | nl | grep -w " $number" | awk '{print $2}')"
	basefile="$(basename "$entry")" && base="${basefile%.*}"
}

# Confirm a choice
function confirm () { read -p "Really $1 \"$base\"? (y/N) " choice && echo "$choice" | grep -qi "^y$" || exit 1; }

# Create a new blog draft
function blog_draft ()  {
	read -e -p "Give your post a title: " title

	max=0
	while [ $max == 0 ]; do
		read -e -p "Enter a description (50 words limit): " description
		[ $(echo "$description" | wc -w) -ge "50" ] && echo "Description must be less than 50 words." || max=1
	done

	read -e -r -p "Input an image to reflect your post: " img
	while [ ! -e $img ]; do
		read -e -r -p "$img does not exist. Please try another path: " img
	done

	url="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
	( [ -f "$drafts"/$url.html ] || [ -f "$blogdir/blog/$url.html" ] ) &&
		printf "\nThere is already an existing draft or post with the same title.\n\n Redirecting...\n\n" && blog
			$EDITOR "$drafts"/$url.html
	 # Select tags
	 tags=("informative" "care" "rant" "breeding-report" "off-topic" "seller-review")
	 tagged=()
	 menu() {
		 clear
		 echo "Choose a tag(s):"
		 for i in ${!tags[@]}; do
			 printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${tags[i]}"
		 done
		 if [[ "$msg" ]]; then echo "$msg"; fi
	 }

	 prompt="Check an option (again to uncheck, ENTER when done): "
	 while menu && read -rp "$prompt" num && [[ "$num" ]]; do
		 [[ "$num" != *[![:digit:]]* ]] &&
			 (( num > 0 && num <= ${#tags[@]} )) ||
			 { msg="Invalid option: $num"; continue; }
			 ((num--))#; msg="${tags[num]} was ${choices[num]:+un}checked"
			 [[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
		 done
		 for i in ${!tags[@]}; do
			 [[ "${choices[i]}" ]] && { tagged+=(${tags[i]^}); }
		 done
		 TAGS=$(printf "%s, " "${tagged[@]}")

	# image handling
	img=$(echo "$img" | cut -f 1 -d '.' >&1)

	if [[ -e "$drafts"/img/$img.jpg || -e "$blogdir"/assets/img/blog/$img.jpg ]] ; then
		i="2"
		while [[ -e "$drafts"/img/$img-$i.jpg || -e "$blogdir"/assets/img/blog/$img-$i.jpg ]]; do ((i++)); done
		mv "$img.jpg" "$img-$i.jpg" && cp "$img-$i.jpg" "$drafts"/img/ && mv "$img-$i.jpg" "$img.jpg"
		img="$img-$i.jpg"
	else
		cp "$img.jpg" "$drafts"/img/
		img="$img.jpg"
	fi

	printf "Post: %s\nTitle: %s\nDescription: %s\nImage: %s\nTags:\n" "$url" "$title" "$description" "$img" | cat - "$datafile" | sponge "$datafile"
	sed -i "5s/$/ ${TAGS}\n/" "$datafile"
	printf "\n${GREEN}Post was saved as a draft: Publish when you are ready to do so.${RESET}\n\n"
}

# Edit a blog draft. Either title, description, content, or index image
function edit_draft () {
	title() {
		read -e -r -p "Enter a new title: " title
		url="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
		old_url="$(echo $(basename "$basefile" ".html" | sed 's/ /-/g'))"
		old_title="$(awk "/Post: $old_url/{getline; print}" "$datafile" | sed 's/^[^:]*: //')"
		( [ -f "$drafts"/$url.html ] || [ -f "$blogdir/blog/$url.html" ] ) &&
			printf "\nThere is already an existing draft or post with the same title.\n\n Redirecting...\n\n" && title
			mv $drafts/$entry $drafts/$url.html
			sed -i "s/Post: $old_url/Post: $url/g" "$datafile"
			sed -i "s/Title: $old_title/Title: $title/g" "$datafile"
			printf "\n${GREEN}Title has been updated.${RESET}\n\n"
	}

	descr() {
		max=0
		while [ $max == 0 ]; do
			read -e -p "Enter a new description (50 words limit): " descript
			[ $(echo "$descript" | wc -w) -ge "50" ] && echo "Description must be less than 50 words." || max=1
		done
		sed -i "/Post: $(basename "$basefile" ".html")/{n;s/.*/Description: $descript/}" "$datafile"
		sed -i "/Description: $descript/{n;d;}" "$datafile"
		printf "\n${GREEN}Description has been updated.${RESET}\n\n"
	}

	con() { listitem "$drafts" edit && "$EDITOR" "$drafts"/$entry && printf "\nPost's content has been updated.\n\n"; }

	image() {
		entry="$(basename "$entry" ".html")"
		read -e -r -p "Enter the path to a new image: " img
		while [ ! -e "$img" ]; do
			read -e -r -p "$img does not exist. Please try another path: " img
		done

		img=$(echo "$img" | cut -f 1 -d '.' >&1)
		old_img="$(cat "$datafile" | sed -n "/Post: "$entry"/{n;n;n; p}" | sed 's/^[^:]*: //')"
		if [[ -e "$drafts"/img/$img.jpg || -e "$blogdir"/assets/img/blog/$img.jpg ]] ; then
			i="2"
			while [[ -e "$drafts"/img/$img-$i.jpg || -e "$blogdir"/assets/img/blog/$img-$i.jpg ]]; do ((i++)); done
			mv "$img.jpg" "$img-$i.jpg" && cp "$img-$i.jpg" "$drafts"/img/
		else    cp "$img.jpg" "$imgdir"/blog/
		fi
		rm "$drafts"/img/$old_img
		sed -i "s/Image: $old_img/Image: $img.jpg/g" "$datafile"
		printf "\n${GREEN}Index image has been updated.${RESET}\n\n"
	}

	printf "\nEditing %s:\nUsage:\n\tt = Title\n\td = Description\n\tc = Content\n\ti = Image\n\n" "$entry"
	read -p "How would you like proceed? " cmd
	case "$cmd" in
		t) title ;;
		d) descr ;;
		c) con   ;;
		i) image ;;
		*) printf "Exiting..\n\n" && exit 1 ;;
	esac
}

# Delete a draft
function del_draft  ()  {
	printf "${RED}Deleting $entry.${RESET}\n" && rm -f "$drafts"/$entry
	sed -i "/Post: $(basename "$entry" ".html")/,+5d" "$datafile"
}

# Delete a public post
function blog_pub_del ()  {
	title="$(basename $basefile .html | sed 's/-/ /g')"
	post='\<a href="..\/'"$basefile"'">'
	blog_post='\<a href="blog\/'"$basefile"'">'

	sed -i -n '/'"$blog_post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog.html
	sed -i -e '/'"$blog_post"'/,+4d' "$blogdir"/blog.html
	sed -i "/Post: $(basename "$entry" ".html")/,+5d" "$datafile"
	sed -i '/<!-- START: '"$title"'/,/<!-- END: '"$title"'/d' "$rss_file"

	if grep -q "$title" "$blogdir"/index.html; then
		sed -i '/'"$title"'/d' "$blogdir"/index.html
	fi

	if grep -o -q "$title" "$blogdir"/blog/tags/off-topic.html; then
		sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/off-topic.html
		sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/off-topic.html
	fi

	if grep -o -q "$title" "$blogdir"/blog/tags/breeding-reports.html; then
		sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/breeding-reports.html
		sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/breeding-reports.html
	fi

	if grep -o -q "$title" "$blogdir"/blog/tags/care.html; then
		sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/care.html
		sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/care.html
	fi

	if grep -o -q "$title" "$blogdir"/blog/tags/informative.html; then
		sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/informative.html
		sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/informative.html
	fi

	if grep -o -q "$title" "$blogdir"/blog/tags/seller-reviews.html; then
		sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/seller-reviews.html
		sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/seller-reviews.html
	fi

	if grep -o -q "$title" "$blogdir"/blog/tags/rant.html; then
		sed -i -n '/'"$post"'/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/blog/tags/rant.html
		sed -i -e '/'"$post"'/,+4d' "$blogdir"/blog/tags/rant.html
	fi

	printf "${RED}Deleting $entry.${RESET}\n" && rm -f "$blogdir"/blog/$entry && update
}

# Publish a draft
function blog_pub ()  {
	tmpdir=$(mktemp -d)
	rssdate="$(LC_TIME=en_US date '+%a, %d %b %Y %H:%M:%S %z')"
	webdate="$(date '+%Y %b %d')"
	url="$(basename "$basefile" ".html")"
	title="$(awk "/Post: $url/{getline; print}" "$datafile" | sed 's/^[^:]*: //')"
	description="$(awk "/$title/{getline; print}" "$datafile" | sed 's/^[^:]*: //')"
	img="$(awk "/$description/{getline; print}" "$datafile" | sed 's/^[^:]*: //')"
	tags="$(grep -A1 "$img" "$datafile" | grep -v "$img" | sed -e 's/^[^:]*: //' -e 's/\,//g')"
	tagsArr=(${tags})
	post="$(cat "$drafts"/$basefile)"
	recent="$(printf "$(basename $basefile ".html")" | sed "s/^.*$/\<li\>\<a href=\"blog\/&.html\"\>$title\<\/a\>\<\/li\>/g" | awk 'BEGIN{FS=OFS=".html\">"} {gsub(/-/," ",$2)}1')"
	numofrecent="$(sed -n '/<!-- RECENT POSTS -->/,/<!-- END-RECENT POSTS -->/p' "$blogdir"/index.html | wc -l)"

	printf "$(cat "$index_tag_template")\n" "$basefile" "$img" "$img" "$basefile" "$title" "$webdate" "$description" "$basefile" > "$tmpdir/tagindex"
	for i in "${tagsArr[@]}"; do
		case ${i} in
			"Informative")
				printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/informative.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag"
			 	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/informative.html
				;;
			"Care")
				printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/care.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag"
			 	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/care.html
				;;
			"Rant")
				printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/rant.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag"
			 	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/rant.html
				;;
			"Breeding-report")
				printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/breeding-reports.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag"
			 	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/breeding-reports.html
				;;
			"Off-topic")
				printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/off-topic.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag"
			 	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/off-topic.html
				;;
			"Seller-review")
				printf "$i\n" | sed "s/^.*$/<h3><a href=\"tags\/seller-reviews.html\">&<\/a><\/h3>/g" >> "$tmpdir/tag"
			 	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/tagindex" "$blogdir"/blog/tags/seller-reviews.html
			        ;;
			*) ;;
		esac
	done

	printf "$(cat "$template")" "$title" "$description" "$title" "$webdate" > "$blogdir"/blog/"$basefile" # Append draft file to blog directory
	sed -i "/<!-- BLOG CONTENT -->/r $drafts/$basefile" "$blogdir"/blog/"$basefile"                       # Append post in the draft
	sed -i "/<!-- TAGS -->/r $tmpdir/tag" "$blogdir"/blog/"$basefile"                                     # Append respective tags in draft
	printf "$(cat "$index_template")\n" "$basefile" "$img" "$img" "$basefile" "$title" "$webdate" "$description" "$basefile" > "$tmpdir/blogindex"
	sed -i "/<!-- INDEX CONTENT -->/r $tmpdir/blogindex" "$blogdir"/blog.html
	printf "$(cat "$rss_template")\n" "$title" "$title" "$(basename "$basefile" ".html")" "$(basename "$basefile" ".html")" "$rssdate"  "$(echo "$post" | recode "..html")" "$title" > "$tmpdir/rss" # RSS
	sed -i "/<!-- RSS -->/r $tmpdir/rss" "$blogdir/rss/rss.xml" 														       # ↓

	sed -i -e '/<!-- RECENT POSTS -->/a '"$recent"'' "$blogdir"/index.html
	[ "$numofrecent" -ge 7 ] && sed -i -n '/<!-- END-RECENT POSTS -->/{x;d;};1h;1!{x;p;};${x;p;}' "$blogdir"/index.html

	cp $drafts/img/$img "$imgdir"/blog && rm $drafts/img/$img && rm "$drafts"/$basefile
	printf "\n${GREEN}Draft has been published.${RESET}\n\n" && update
}

# Edit or Revise a published blog post
function blog_edit_pub ()  {
	title() {
		read -e -r -p "Enter a new title: " title

		url="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")"
		old_url="$(echo $(basename "$basefile" ".html" | sed 's/ /-/g'))"
		old_title="$(awk "/Post: $old_url/{getline; print}" "$datafile" | sed 's/^[^:]*: //')"
		tags="$(sed -n "/$old_url/{n;n;n;n; p}" "$datafile" | sed -e 's/^[^:]*: //' -e 's/\,//g')"
		tagsArr=(${tags})
	for i in "${tagsArr[@]}"; do
		case ${i} in
			"Informative")
				sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/informative.html
				;;
			"Care")
				sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/care.html
				;;
			"Rant")
				sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/rant.html
				;;
			"Breeding-report")
				sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/breeding-reports.html
				;;
			"Off-topic")
				sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/off-topic.html
				;;
			"Seller-review")
				sed -i -e "s/$old_title/$title/g" -e "s/$old_url/$url/g" "$blogdir"/blog/tags/seller-reivews.html
			        ;;
			*) ;;
		esac
	done
		sed -i -e "s/Post: $old_url/Post: $url/g" -e "s/Title: $old_title/Title: $title/g" "$datafile" # Update URL & Title in data file
		sed -i -e "s/$old_title/$title/g" "$blogdir"/blog/$entry                                       # Rename title & headings in $entry
		sed -i -e "s/$old_title/$title/g" -e "s/$basename/$url/g" "$rss_file"		               # Update RSS title and URL
		sed -i -e "s/"$entry"/"$url.html"/g" -e "s/$old_title/$title/g" "$blogdir"/blog.html           # Update URLS & title in blog.html
		sed -i -e "s/"$entry"/"$url.html"/g" -e "s/$old_title/$title/g" "$blogdir"/index.html          # Update URLS & title in index.html
		mv "$blogdir"/blog/$entry "$blogdir/blog/$url.html"     			               # Rename file in /blog
		printf "\n${GREEN}Title has been updated.${RESET}\n\n" && update
	}

	descr() {
		title="$(awk "/Post: $(basename "$basefile" ".html")/{getline; print}" "$datafile" | sed 's/^[^:]*: //')"
		old_description="$(sed -n "/Title: $title/{ n; p }" $datafile | sed 's/^[^:]*: //')"
		max=0
		while [ $max == 0 ]; do
			read -e -p "Enter a new description (50 words limit): " new_description
			[ $(echo "$new_description" | wc -w) -ge "50" ] && echo "Description must be less than 50 words." || max=1
		done

		tags="$(sed -n "/$(basename "$basefile" ".html")/{n;n;n;n; p}" "$datafile" | sed -e 's/^[^:]*: //' -e 's/\,//g')"
		tagsArr=(${tags})
		for i in "${tagsArr[@]}"; do
			case ${i} in
				"Informative")
					sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/informative.html
					;;
				"Care")
					sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/care.html
					;;
				"Rant")
					sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/rant.html
					;;
				"Breeding-report")
					sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/breeding-reports.html
					;;
				"Off-topic")
					sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/off-topic.html
					;;
				"Seller-review")
					sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/tags/seller-reviews.html
					;;
				*) ;;
			esac
		done
		sed -i "s/Description: $old_description/Description: $new_description/g" "$datafile"
		sed -i "s/$old_description/$new_description/g" "$blogdir"/blog/$entry
		sed -i "s/$old_description/$new_description/g" "$blogdir"/blog.html
		printf "\n${GREEN}Description has been updated.${RESET}\n\n" && update
	}

	content() {

		title="$(basename $basefile .html | sed 's/-/ /g')"
		url="$(echo $title | sed 's/ /-/g')"
		old_rss="$(sed -n '/<!-- BLOG CONTENT -->/,/<!-- END BLOG CONTENT -->/{/<!-- BLOG CONTENT -->/!{/<!-- END BLOG CONTENT -->/!p}}' "$blogdir/blog/$entry" | recode ..html |  sed 's/&/\\&/g')"
		"$EDITOR" "$blogdir"/blog/$entry
		new_rss="$(sed -n '/<!-- BLOG CONTENT -->/,/<!-- END BLOG CONTENT -->/{/<!-- BLOG CONTENT -->/!{/<!-- END BLOG CONTENT -->/!p}}' "$blogdir/blog/$entry" | recode ..html |  sed 's/&/\\&/g')"
		sed -i -e "s~$old_rss~~g" -e '/LETS test RSS FEED/n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n; r'<(printf "$new_rss") "$rss_file"
		printf "\n${GREEN}Description has been updated.${RESET}\n\n" && update
	}

	image() {
		read -e -r -p "Enter the path to a new image: " img
		while [ ! -e "$img" ]; do
			read -e -r -p "$img does not exist. Please try another path: " img
		done

		old_img="$(cat "$datafile" | sed -n "/Post: $(basename "$entry" ".html")/{n;n;n; p}" | sed 's/^[^:]*: //' | cut -f 1 -d '.' >&1)"
		img=$(echo "$img" | cut -f 1 -d '.' >&1)
		if [[ -e "$drafts"/img/$img.jpg || -e "$blogdir"/assets/img/blog/$img.jpg ]] ; then
			i="2"
			while [[ -e "$drafts"/img/$img-$i.jpg || -e "$blogdir"/assets/img/blog/$img-$i.jpg ]]; do ((i++)); done
			mv "$img.jpg" "$img-$i.jpg"
			cp "$img-$i.jpg" "$blogdir"/assets/img/blog/
			rm "$blogdir"/assets/img/blog/$old_img.jpg
			mv "$img-$i.jpg" "$img.jpg"
		else    cp "$img.jpg" "$imgdir"/blog/
		fi

		sed -i "s/Image: $old_img/Image: $img/g" "$datafile"
		sed -i "s/$old_img/$img/g" "$blogdir"/blog.html
		printf "\n${GREEN}Index image has been updated.${RESET}\n\n" && update
	}

	printf "\n\nRevising a public entry: %s:\nUsage:\n\tt = Title\n\td = Description\n\tc = Content\n\ti = Image\n\n" "$entry"
	read -p "How would you like proceed? " cmd
	case "$cmd" in
		t) title ;;
		d) descr ;;
		c) content   ;;
		i) image ;;
		*) printf "Exiting..\n\n" && exit 1 ;;
	esac
}


# Create, Revise, Publish,
function blog () {
	printf "\nEditing arachnida.blog\nUsage:\n\tn = New Draft\n\tp = Publish Draft\n\te = Edit Draft\n\tr = Revise published post\n\tt = Delete draft\n\td = Delete publish post\n\n"
 	read -p "How would you like proceed? " cmd
	case "$cmd" in
		n*) blog_draft ;;
		p*) listitem "$drafts" publish && blog_pub ;;
		e*) listitem "$drafts" edit && edit_draft ;;
		r*) listitem "$blogdir/blog" revise public entry && blog_edit_pub ;;
		t*) listitem "$drafts" delete && confirm delete && del_draft ;;
		d*) listitem "$blogdir/blog" delete && confirm delete && blog_pub_del ;;
		*) printf "Exiting..\n\n" && exit 1 ;;
	esac
}


function shop () {
	$empty
}

function gallery () {
	$empty
}


# Webpick
case "$1" in
	-b*) blog ;;
	-s*) shop ;;
	-g*) gallery ;;
	*) printf "\n\nab blog system by Ben Nagy <ben@arachnida.blog>\n\nUsage:\n  ab -b: blog\n  ab -s: shop\n  ab -g: gallery\n\n" ;;
esac


# TODO

# Allow revision of tags
# calculate article read time