blob: 25579fa4390742b5f4d848516b0bf723bedcdcac (
plain) (
blame)
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
|
#!/bin/sh -eu
# shellcheck source=/dev/null
. "$DOTFILES/bash/colors.sh"
missing() {
red "Missing argument <${1}>.\n"
}
usage() {
cat <<EOF
Usage:
$0 <TYPE> <FULL_TITLE>
Arguments:
TYPE The type of the article: article, til, slides, podcast, screencast
FULL_TITLE Full title of the pastebin
Examples:
$0 til 'I just learned this'
$0 article 'My example article title'
EOF
}
TYPE="${1:-}"
[ -z "$TYPE" ] && {
missing 'TYPE'
usage
exit 2
}
case "$TYPE" in
article | til | podcast | screencast)
LAYOUT=post
DIR="_${TYPE}s"
;;
slides)
LAYOUT=slides
DIR=_slides
;;
*)
red "Invalid type '$TYPE'"
usage
exit 2
;;
esac
FULL_TITLE="${2:-}"
[ -z "$FULL_TITLE" ] && {
missing 'FULL_TITLE'
usage
exit 2
}
# Derived from:
# https://stackoverflow.com/questions/4009281/how-can-i-generate-url-slugs-in-perl/4009519#4009519
slugify() {
echo "$1" | \
tr '[:upper:]' '[:lower:]' | \
perl -ne 'tr/\000-\177//cd;
s/[^\w\s-]//g;
s/^\s+|\s+$//g;
s/[-\s]+/-/g;
print;'
}
SLUG_TITLE="$(slugify "$FULL_TITLE")"
PASTE_DATE="$(date -I)"
OUT="$DIR/$PASTE_DATE-$SLUG_TITLE.md"
cd ~/dev/libre/website
[ -f "$OUT" ] && {
red "Pastebin named $OUT already exists."
exit 1
}
if [ "$LAYOUT" = 'slides' ]; then
cat<<EOF > "$OUT"
---
title: $FULL_TITLE
date: $PASTE_DATE
layout: $LAYOUT
lang: en
ref: $SLUG_TITLE
---
---
## Thank you!
References:
1. these slides: [{{ site.tld }}/slides.html]({% link slides.md %})
2. [prose version of this presentation]({% link _articles/$PASTE_DATE-$SLUG_TITLE.md %})
EOF
"$0" article "$FULL_TITLE"
else
cat <<EOF > "$OUT"
---
title: $FULL_TITLE
date: $PASTE_DATE
layout: $LAYOUT
lang: en
ref: $SLUG_TITLE
---
EOF
fi
|