-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·86 lines (72 loc) · 2.3 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
#!/bin/bash
# a script to generate a website from markdown files
# convert all markdown files to 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>
'
options=(--template=static/template.html)
genhtml(){
for file in ./blog/posts/*.md; do
[ -e "$file" ] || continue
pandoc static/metadata.yaml "${options[@]}" -s "$file" -o blog/"$(basename "$file" .md)".html
done
}
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/posts/index.md
items=()
for file in ./blog/*.html; do
[ -e "$file" ] || continue
link="$(basename "$file" )"
items=(${items[@]} $link)
done
IFS=$'\n'
items=($(sort -nr <<< "${items[*]}"))
for value in "${items[@]}"; do
title=$(pup -f "./blog/$value" title text{})
date=$(pup -f "./blog/$value" "p.date" text{})
prefix="https://www.lawrencelogoh.com/blog/"
printf "[$title]($prefix$value) \n\n" >> blog/posts/index.md
done
}
genothers(){
pandoc static/metadata.yaml "${options[@]}" -s index.md -o index.html
pandoc static/metadata.yaml "${options[@]}" -s learning/index.md -o learning/index.html
pandoc static/metadata.yaml "${options[@]}" -s about/index.md -o about/index.html
}
genrss(){
rm -f rss.xml
printf "$rss_include_before" >> rss.xml
for value in "${items[@]}"; do
title=$(pup -f "./blog/$value" title text{})
date=$(pup -f "./blog/$value" "p.date" text{})
date=$(date -d "$date" +"%a, %d %b %Y %T %Z")
prefix="https://www.lawrencelogoh.com/blog/"
article=$(pup -i 0 -f "./blog/$value" article)
post="<item>
<title>$title</title>
<link>"$prefix""$value"</link>
<pubDate>"$date"</pubDate>
<guid>"$prefix""$value"</guid>
<description><![CDATA["${article//$'\n'/}"]]></description>
</item>"
printf "$post" >> rss.xml
done
printf "$rss_include_after" >> rss.xml
}
rm -f ./blog/*.html
genhtml
genblogindex
genhtml # shouldn't be doing this twice
genothers
genrss