-
Notifications
You must be signed in to change notification settings - Fork 4
/
publish
executable file
·67 lines (56 loc) · 1.68 KB
/
publish
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
#!/usr/bin/env bash
if [[ $# < 1 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $0 <path-to-post>"
exit 1
fi
file="$1"
title="$(./getPostTitle < "$file")"
#Gets the blurb for the post.
#* Skip the title line
#* Filter out empty lines
#* Remove all sets of '=' or '-' longer than 4 characters, as those are
# probably part of the title
#* Convert links to text
#* Replace newlines with spaces
#* Take the first 200 characters
#* Remove the last word to prevent partial words
#* Add "..."
blurb="$(tail -n +2 < "$file" \
| awk '/[^\s]+/' \
| sed -r 's/===[=]+//g' \
| sed -r 's/---[-]+//g' \
| sed -r 's/\[([^]]*)\]\([^)]*\)/\1/g' \
| tr '\n' ' ' \
| head -c 200 \
| sed -r 's/\s[^[:space:]]+\s*$//g')..."
date="$(date '+%b %d, %Y')"
#Replace spaces with dashes in the title, and lowercase it
postid="$(echo $title | ./getPostID)"
echo "ID: $postid"
echo "Title: $title"
echo "Date: $date"
echo ""
if grep "$postid" "source/post_list" &> /dev/null; then
echo -n "Post exists with ID '$postid'. Update post? [y/N] "
read confirm_post
if [[ "$confirm_post" != "y" ]]; then
exit 1
fi
else
echo -n "Are you sure you want to post '$title'? [y/N] "
read confirm_post
if [[ "$confirm_post" != "y" ]]; then
exit 1
else
echo -n $title > "source/post_title/$postid"
echo -n $date > "source/post_date/$postid"
echo $postid >> "source/post_list"
fi
fi
#Regenerate blurb when editing posts
echo -n $blurb > "source/post_blurb/$postid"
./generatePostHtml "$file" "$postid"
POST="source/post_content/$postid.html" \
TITLE="$title"
./makePost > "./public/posts/$postid.html"
./makeIndices