-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstitch
executable file
·133 lines (122 loc) · 4.72 KB
/
stitch
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
#!/usr/bin/env bash
set -euo pipefail
post_mathjax=0
attr_showtitle="-a showtitle"
supdoc() {
sed 's/^\\begin{code}/[.hs,haskell]\n--------/;s/^\\end{code}/--------/' \
| asciidoctor $attr_showtitle -s -
}
doctitlepre=""
cssfile=""
bodypre=""
bodypost=""
footer='<a href="/~blynn/">Ben Lynn</a> <i>[email protected]</i> <span id="lightswitch" onclick="lights();">💡</span>
<script>
var darkcss=document.createElement("style");
darkcss.innerHTML="html{background-color:black;color:#aaaaaa;};body{background-color:black;color:#aaaaaa;}textarea{color:#e6e1dc;background-color:#232323;}pre{color:#e6e1dc;background-color:#232323;}svg{filter:invert(100%);}";
function lights() {
if ("out" == sessionStorage.getItem("lights")) {
sessionStorage.removeItem("lights");
document.body.removeChild(darkcss);
} else sessionStorage.setItem("lights", "out");
checklights();
}
function checklights() {
if ("out" == sessionStorage.getItem("lights")) document.body.appendChild(darkcss);
}
checklights();
</script>
'
mathjax() {
echo '<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>'
}
fulldoc() {
echo '<!DOCTYPE html><html lang="en"><head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-G56YW5RFXN"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "G-G56YW5RFXN");
</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="/~blynn/b.png" type="image/png">
<link href="https://fonts.googleapis.com/css?family=Open+Sans%7CInconsolata%7CMuli" rel="stylesheet" type="text/css">'
[[ "$post_mathjax" == "1" ]] || mathjax
echo '<link rel="stylesheet" title="Default" type="text/css" href="/~blynn/css/'$cssfile'">'
[[ -z ${MERC+x} ]] || echo '<link rel="stylesheet" title="Default" type="text/css" href="/~blynn/compiler/merc.css">'
doctitle=$(grep '^==* ' $1 | sed 1q | sed 's/^==* *//' | sed 's/ *=*=$//')
echo "<title>$doctitlepre$doctitle</title>"
echo '</head><body>'$bodypre
cat $1 | supdoc
[[ "$post_mathjax" != "1" ]] || mathjax
echo '<script>
var darkcss=document.createElement("style");
darkcss.innerHTML="html{background-color:black;color:#aaaaaa;};body{background-color:black;color:#aaaaaa;}textarea{color:#e6e1dc;background-color:#232323;}pre{color:#e6e1dc;background-color:#232323;}svg{filter:invert(100%);}";
</script>'
echo $bodypost'</body></html>'
}
slidedoc() {
echo '<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Open+Sans%7CInconsolata%7CMuli" rel="stylesheet" type="text/css">
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>'
doctitle=$(grep '^==* ' $1 | sed 1q | sed 's/^==* *//' | sed 's/ *=*=$//')
echo "<title>$doctitle</title>"
echo '</head><body>'$bodypre
cat $1 | supdoc
echo $bodypost'</body></html>'
}
tohref() {
if [[ $1 == "index" ]]
then echo "."
else echo $1.html
fi
}
if [[ -z ${1+x} ]]
then supdoc
else
case $1 in
slide)
slidedoc $2 > ${2%.*}.html
;;
solo)
cssfile=solo.css
bodypost="<hr>"$footer
fulldoc $2 > ${2%.*}.html
;;
menu)
sed '/^\\/s/^.\(.*\)/\1/
s/\(.*\),\(.*\)/- link:\1.html[\2]/' $2 | sed 's/index.html/./' | asciidoctor -s - > ${2%.*}.html
;;
book)
if [[ ! -z ${MERC+x} ]]
then
post_mathjax=1
attr_showtitle=""
fi
cssfile=book.css
prevline=$( (echo ; cat $2) | grep -B1 "^${3%.*}," | sed -n 1p | grep , || :)
nextline=$( (cat $2 ; echo) | grep -A1 "^${3%.*}," | sed -n 2p | grep , || :)
prev=""
next=""
[[ -z $prevline ]] || prev="<span class='link-prev'><a href='$(tohref ${prevline%%,*})'>⏴ ${prevline#*,}</a></span>"
[[ -z $nextline ]] || next="<span class='link-next'><a href='$(tohref ${nextline%%,*})'>${nextline#*,} ⏵</a></span>"
menu=$(cat ${2%.*}.html)
navbar='<div class="navbar">'$prev$next'<div class="link-contents"><a href="#contents">Contents</a></div></div> <!-- navbar -->'
bodypre='<div class="main"><div class="plump"><div class="menu">'$menu'</div></div><!-- menu, plump --><div class="rside">'$navbar
doctitlepre=$(sed 1q $2 | sed 's/^[^,]*,//')" - "
#bodypost=bookfootermenuinc AND NAVBAR
bodypost=$navbar'<hr><div class="skinny" id="contents"><div class="menu">
<h2>Contents</h2>'$menu'[<a href="#">back to top</a>]</div> <!-- "menu" -->
<br>
<br>
<br>
</div> <!-- "skinny" -->'$footer'</div> <!-- "rside" --></div> <!-- "main" -->'
fulldoc $3 > ${3%.*}.html
;;
esac
fi