blob: 8125bd4c0d3f6e1df63894185ebce96c9cc7e882 (
plain)
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
|
#!/usr/bin/env bash
TITLE="Unorthodox Monolgues"
AUTHOR="Abigail Kelley"
EMAIL="UNMONO@MOHIT.UK"
OUTFILE="unmono"
LANG="en_GB"
# Convert a markdown file to HTML and store it in the OUTFILE
md2html() {
local file=$1
echo "Building $file..." >&2
filename_html=$OUTFILE/${file/%.md/.html}
filename_pdf=$OUTFILE/${file/%.md/.pdf}
local args=(
"--email-obfuscation=references"
"--from=markdown+emoji"
"--metadata=lang:$LANG"
"--shift-heading-level-by=-1"
"--toc-depth=4"
)
local args_html=(
"--css=static/style.css"
"--css=static/document.css"
"--include-before-body=header.html"
"--include-in-header=headerlinks.html"
"--table-of-contents"
)
local args_pdf=(
"--pdf-engine=xelatex"
)
# args+=("--citeproc") # Citations
# args+=("--mathjax") # Mathematical rendering
# args+=("--include-after-body=$goatcounter")
# args+=("--include-in-header=$favicon")
if [[ $file == ????-??-??-* ]]; then
args+=("--metadata=date:$(fmtdate ${file:0:10})")
fi
if [[ $file == 'index.md' ]]; then
args+=("--metadata=pagetitle:$TITLE")
fi
if [[ $file -nt $filename_html ]]; then
pandoc "${args[@]}" "${args_html[@]}" -t html \
--output=$OUTFILE/${file/%.md/.html} "$file" || echo "error while converting $file";
pandoc "${args[@]}" "${args_pdf[@]}" -t pdf \
--output=$OUTFILE/${file/%.md/.pdf} "$file" || echo "error while converting $file";
fi
}
extracttitle() {
local file=$1
sed -n '/^# /{s///p;q}' "$file"
}
extractauthor() {
grep "author" $f | sed 1q | cut -d":" -f 2
}
fmtdate() {
date --date="$1" "+%d %b %Y"
}
# Build all pages
build() {
echo "./make --------------------------------------------------"
echo " Blog builder"
echo " Written by Mohit Agarwal"
echo " FOR INTERNAL USE ONLY"
echo "---------------------------------------------------------"
echo ""
echo "TITLE $TITLE"
# Build index file and convert posts
echo ""
echo "Building index.html and converting posts"
{
echo '<!DOCTYPE html>'
echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en_GB" xml:lang="en_GB">'
echo '<link rel="stylesheet" href="static/style.css">'
echo '<link rel="stylesheet" href="static/document.css">'
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />'
echo "<title> $TITLE </title>"
echo '<head>'
echo '</head>'
echo '<body>'
echo "<h1 style='text-align:center;'> $TITLE </h1>"
local f
for f in ????-??-??-*.md; do
echo '</div>'
echo "$(fmtdate ${f:0:10}) - $(extractauthor "$f")"
echo "<a href=${f/%.md/.html}><h3 class='title'>$(extracttitle "$f")</h3></a>"
echo '<div class="article">'
md2html "$f"
done | tac
} > index.html
./feed.sh
echo ""
echo "COPYING FILES"
cp -v index.html $OUTFILE/
cp -vr static $OUTFILE/
cp -vr images $OUTFILE/
cp -vr feed.xml $OUTFILE/
echo ""
echo "BLOG PUBLISHED"
echo "---------------------------------------------------------"
echo "---------------------------------------------------------"
}
build
|