-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.sh
executable file
·109 lines (96 loc) · 2.48 KB
/
render.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
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
#!/bin/sh
usage() {
echo "usage: render.sh [-t TYPE]"
}
title=""
created=""
while case "$1" in
"") false;;
-t) type="$2"; shift 1;;
*)
echo "Unrecognized option $1" >&2
usage
exit 1
;;
esac; do shift; done
meta() {
echo "$1" |sed 's/<[^>]*>//g'
}
prettydate() {
if [ $# -lt 1 ]; then read date; else date=$1; fi
y=$(echo "$date" |cut -d'-' -f1)
m=$(echo "$date" |cut -d'-' -f2)
d=$(echo "$date" |cut -d'-' -f3)
m=$(printf "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec\n" |sed -n ${m}p)
d=$(echo "$d" |sed 's/^0//')
echo "$y $m $d"
}
while { if [ -z "$nometa" ]; then read line; else false; fi; } do
case "$line" in
'<pmeta id="title">'*) title=$(meta "$line") ;;
'<pmeta id="created">'*) created=$(meta "$line") ;;
'<pmeta id="updated">'*) updated=$(meta "$line") ;;
"<pmeta"*) echo ">> some other pmeta: $(meta "$line")" >&2 ;;
*) nometa=1;;
esac
done
if [ -n "$updated" ]; then modified=$updated; else modified=$created; fi
cat <<HEADER
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="/f/Nunito.css" rel="stylesheet">
<link href="/feed.xml" type="application/atom+xml" rel="alternate" title="Blog Atom feed" />
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🤔</text></svg>">
<link rel="stylesheet" type="text/css" href="/post.css" >
HEADER
case "$type" in
person)
cat <<LDJSON
<script type="application/ld+json">
{ "@context": "http://schema.org"
, "@type": "Person"
, "name": "Joshua Lloret"
}
</script>
LDJSON
;;
post)
cat <<NAV
<a href="/">🏡 home</a>
NAV
cat <<LDJSON
<script type="application/ld+json">
{ "@context": "http://schema.org"
, "@type": "BlogPosting"
, "headline": "$title"
, "author": {"@type": "Person", "name": "Joshua Lloret"}
, "datePublished": "$created"
, "dateModified": "$modified"
}
</script>
LDJSON
;;
esac
[ -n "$title" ] && echo "<title>$title</title>"
cat <<HEADER
</head>
<body>
<div class="$type">
HEADER
echo "<header>"
if [ -n "$created" ]; then
echo -n " <created>$(prettydate "$created")"
[ -n "$updated" ] && echo -n "<br/><i>updated: $(prettydate "$updated")</i>"
echo "</created>"
fi
[ -n "$title" ] && echo " <ptitle><h1>> $title</h1></ptitle>"
echo "</header>"
signature='**-<a href="https://isthisa.website" rel="author">JD</a>**'
(echo "$line"; cat; [ "$type" = "post" ] && printf "\n%s" "$signature") |pulldown-cmark
cat <<FOOTER
</div>
</body>
</html>
FOOTER