-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakeIndex
executable file
·62 lines (59 loc) · 1.7 KB
/
makeIndex
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
#!/usr/bin/env bash
if [[ $# < 1 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $0 <num-posts>"
exit 1
fi
indexLength="$1"
if [[ -z "$indexLength" ]]; then
indexLength=5
fi
if [[ "$indexLength" = "all" ]]; then
indexLength="$(wc -l < source/post_list)"
fi
function postList() {
#Get post list in reverse order and retrieve the last $indexLength posts
#Generates HTML for them with the title and blurbs
#Then removes the last two lines of the output to delete the extra <hr/>
cat source/post_list \
| perl -e 'print reverse <>' \
| head -n "$indexLength" \
| while read postid; do
#Escape single quotes
link="$(echo "posts/$postid.html" | sed "s/'/\\'/g")"
echo "
<h2 class='post-title'>
<a href='$link'>
$(cat "source/post_title/$postid")
</a>
</h2>
<h5>$(cat "source/post_date/$postid")</h5>
<p class='post-blurb'>
<a href='$link'>
$(cat "source/post_blurb/$postid")
</a>
</p>
<hr/>
"
done \
| head -n '-2'
}
echo "
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Noven</title>
<style>
$(cat source/css/site.css)
$(cat source/css/index.css)
</style>
</head>
<body>
$(cat source/header.html)
<div class='content-body'>
$(postList)
</div>
$(cat source/footer.html)
</body>
</html>
"