-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·88 lines (72 loc) · 2.1 KB
/
build
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
#!/usr/bin/env bash
# a script to generate a website from markdown files
shopt -s extglob
dirs=("." "blog" "about")
options=(--template=static/template.html)
rss_include_before='<rss version="2.0">
<channel>
<title>Lawrence Logoh'\''s blog</title>
<link>https://www.lawrencelogoh.com</link>
<description>Blog posts on Lawrence Logoh'\''s blog</description>
<generator></generator>
'
rss_include_after='
</channel>
</rss>
'
genblogindex(){
rm -f blog/index.html
title=" Lawrence Logoh's Blog"
include_after="include-after: '<a href=\"https://www.lawrencelogoh.com\"><- Back to home</a>'"
printf "%s\n" "---" "title: > " "$title" "$include_after" "---" > blog/src/index.md
posts=()
prefix="https://www.lawrencelogoh.com/blog/"
for file in blog/src/!(index).md; do
[ -e "$file" ] || continue
title=$(head -n 4 "$file" | yq ".title")
date=$(head -n 4 "$file" | yq ".date")
filename="$(basename "$file" ".md")"
ext=".html"
link="[$title]($prefix$filename$ext)"
posts=("${posts[@]}" "$link")
done
IFS=$'\n'
posts=($(sort -n <<< "${posts[*]}"))
unset IFS
echo "$posts" >> blog/src/index.md
}
gensite(){
for dir in "${dirs[@]}"; do
rm -f "$dir"/*.html
for file in "$dir"/src/*.md; do
[ -e "$file" ] || continue
pandoc static/metadata.yaml "${options[@]}" -s "$file" -o "$dir"/"$(basename "$file" .md)".html
done
done
}
genrss(){
rm -f rss.xml
prefix="https://www.lawrencelogoh.com/blog/"
printf "$rss_include_before" >> rss.xml
for file in blog/src/!(index).md; do
[ -e "$file" ] || continue
title=$(head -n 4 "$file" | yq ".title")
date=$(head -n 4 "$file" | yq ".date")
filename="$(basename "$file" ".md")"
ext=".html"
link="$prefix$filename$ext"
article=$(awk "/<article>/, /<\/article>/" blog/"$filename$ext")
post="<item>
<title>"$title"</title>
<link>"$link"</link>
<pubDate>"$date"</pubDate>
<guid>"$link"</guid>
<description><![CDATA["${article//$'\n'/}"]]></description>
</item>"
printf "$post" >> rss.xml
done
printf "$rss_include_after" >> rss.xml
}
genblogindex
gensite
genrss