-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.sh
executable file
·81 lines (69 loc) · 1.7 KB
/
publish.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
#!/bin/sh
set -eu
: ${BLOG_PRIVATE_REPO:="private"}
info() { printf >&2 '%s\n' "$*"; }
die() { info "$*"; exit 1; }
publish() {
local path=''
local date=''
local title=''
local file
for file in "$@" ; do
case "$file" in
(_posts/*.md)
[ -z "$path" ] || die "two posts found, please one at a time!"
local fm="$(sed -ne '2,/^---/{/^---/q;p}' "$file")"
date="$(printf '%s' "$fm" \
| teepee -y - -T '[%= (split m{\s+}mxs, V("date"))[0] %]')"
title="$(printf '%s' "$fm" | teepee -y - -v title)"
path="$file"
;;
esac
done
[ -n "$date" ] || die "no date from <$*>"
[ -n "$title" ] || die "no title from <$*>"
printf >&2 'date <%s>\ntitle <%s>\npath(s) <%s>\nOK? (y|s|*) ' \
"$date" "$title" "$*"
read x
case "$x" in
(y|Y)
git add "$@"
git commit -m "New post: $title"
git tag "$date"
git push "$BLOG_PRIVATE_REPO" devel "$date"
;;
(s|S)
info 'skipping as requested'
;;
(*)
die 'bailing out'
;;
esac
return 0
}
if [ "${1:-"--all"}" = '--all' ]; then
set -- $(git status --short --branch | sed -e '/^#/d;s/^...//')
fi
n_posts=0
n_other=0
for file in "$@" ; do
case "$file" in
(_posts/*md)
n_posts=$((n_posts + 1))
;;
(*)
n_other=$((n_other + 1))
;;
esac
done
if [ $n_posts -eq 0 ] ; then
die "no post in list <$*>"
elif [ $n_posts -eq 1 ] ; then
publish "$@"
elif [ $n_other -eq 0 ] ; then
for file in "$@" ; do
publish "$file"
done
else
die "either one post with ancillaries, or multiple posts <$*>"
fi