blob: 56ea15b6a7682577aca687e3174104d6e1ca9412 (
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
126
127
128
129
130
131
132
133
|
#!/bin/sh
base_template () {
body_file=$(mktemp)
cat > "$body_file"
sed '/<!-- BODY -->/r '"$body_file" base.template.html
}
base_template_link () {
link_href="$1"
case $link_href in
*.css)
link_rel="stylesheet"
link_type="text/css"
;;
*.png)
link_rel="icon"
link_type="image/png"
;;
*)
echo Invalid link file
exit 1
;;
esac
sed "/<!-- HEAD -->/i\
<link rel=\"$link_rel\" type=\"$link_type\" href=\"$link_href\"/>"
}
# Setup
blog_path=blog
mkdir -p "$blog_path"
base_template < index.template.html |
base_template_link 'static/img/favicon.png' |
base_template_link 'static/css/index.css' |
base_template_link 'static/css/style.css' > index.html
base_template < school.template.html |
base_template_link 'static/img/favicon.png' |
base_template_link 'static/css/style.css' > school.html
base_template < about.template.html |
base_template_link 'static/img/favicon.png' |
base_template_link 'static/css/style.css' > about.html
cp rss.template.xml rss.xml
# Generate blog posts
for post_path in "$blog_path"/*.md
do
post_dst_path=$(echo "$post_path" | sed 's_.md_.html_')
pandoc -f markdown -t html < "$post_path" |
sed -e '1i<div class="article">' -e '$a</div>' |
base_template |
base_template_link '../static/img/favicon.png' |
base_template_link '../static/css/blog.css' |
base_template_link '../static/css/style.css' > "$post_dst_path"
# Add blog artcle link to the index.html
title=$(grep '^# .*$' -m 1 "$post_path" | cut -c 2-)
[ -z "$title" ] && echo "post $post_path doesn't have a title" && title=$post_path
sed -i "/<!-- BLOGINDEX -->/ a\
<li><a href=\"$post_dst_path\">$title</a></li>" index.html
post_date=$(date '+%a, %d %b %Y %H:%M:%S %z' -d "$(stat -c '%w' "$post_path")")
sed -i "/<!-- ITEM -->/ a\
<item> \
<title>$title</title> \
<pubDate>$post_date</pubDate> \
<guid>https://cacharle.xyz/$post_dst_path</guid> \
<link>https://cacharle.xyz/$post_dst_path</link> \
<description>Open this entry in your browser to see the content</description> \
</item>" rss.xml
echo "Generated post at $post_dst_path"
done
# Generate utilities
for util_path in utils/*
do
title=$(basename "$util_path" | tr '_' ' ')
sed '$ a <script type="text/javascript" src="script.js"></script>' < "$util_path/index.template.html" |
base_template |
base_template_link '../../static/img/favicon.png' |
base_template_link '../../static/css/style.css' |
base_template_link 'style.css' > "$util_path/index.html"
sed -i'' "/<!-- UTILSINDEX -->/ a\
<li><a href=\"$util_path\">$title</a></li>" index.html
echo "Generated utility at $util_path/index.html"
done
base_template < walks/index.template.html |
base_template_link '/static/img/favicon.png' |
base_template_link '../static/css/style.css' |
base_template_link 'https://unpkg.com/leaflet@1.7.1/dist/leaflet.css' |
base_template_link 'style.css' > walks/index.html
[ ! -d walks/maps ] && mkdir walks/maps
for gpx_path in walks/gpx/*
do
[ ! -f "$gpx_path" ] && continue
map_dst=$(basename "$gpx_path" | cut -d . -f 1 | tr ' ' '-')
map_dst_path="walks/maps/$map_dst.html"
base_template < walks/map.template.html |
base_template_link '/static/img/favicon.png' |
base_template_link '/static/css/style.css' |
base_template_link '/walks/style.css' |
base_template_link 'https://unpkg.com/leaflet@1.7.1/dist/leaflet.css' |
sed "/<!-- GPXLINK -->/ a <a href=\"/$gpx_path\">$(basename "$gpx_path")</a>" > $map_dst_path
sed -i'' "/<!-- MAPINDEX -->/ a\
<li> \
<a href=\"/$map_dst_path\" class=\"view-on-map\">view on map</a> \
<a href=\"/$gpx_path\">$(basename "$gpx_path")</a> \
</li>" walks/index.html
echo "Generated walk at $gpx_path"
done
for notebook_path in notebooks/*.ipynb
do
notebook_dst_path=$(echo "$notebook_path" | sed 's_.ipynb_.html_')
jupyter-nbconvert "$notebook_path"
sed -i'' "/<!-- NOTEBOOKINDEX -->/ a\
<li> \
<a href=\"$notebook_dst_path\">$(basename $notebook_path | cut -d . -f 1 | tr '-' ' ')</a> \
<a href=\"$notebook_path\"> ($(basename $notebook_path))</a> \
</li>" index.html
done
|