aboutsummaryrefslogtreecommitdiff
path: root/generate.sh
blob: 338619810d360e6d4028eed7e73e581fba87b282 (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
#! /usr/bin/env bash


post_title() {
    # remove extension
    # snake to title case
    echo "$1" | sed -E -e "s/\..+$//g"  -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g"
}

post_wrapper() {
    # 1 - post id
    # 2 - post content
    title="$( post_title $1 )"
    d="none";
    if [ "$4" = "1" ]; then
        d="block"
    fi
    echo -ne "
    <div class=\"post\">
        <div class=\"date\">$3</div>
        <a href=\"#$1\" class=\"post-link\" onClick=\"showPost('$1')\">$title</a>
        <div id=\"$1\" class=\"post-text\" style=\"display: $d\">
            $2
            <a href=\"#$1\" class=\"post-end-link\" onClick=\"showPost('$1')\">↑ Collapse</a>
            <div class="separator"></div>
        </div>
    </div>
    "
}
# meta
echo "
<!DOCTYPE html>
<html lang=\"en\">
<head>
<link rel=\"stylesheet\" href=\"./style.css\">
<meta charset=\"UTF-8\">
<title>n</title>
" > ./docs/index.html

# script
echo '<script>' >> docs/index.html
for s in ./script/*; do
    cat "$s" >> docs/index.html
done
echo '</script> </head>' >> docs/index.html

# body
echo "
<body>
<h1 class=\"heading\">n</h1>
" >> docs/index.html


# begin posts
echo "
<div class=\"posts\">
" >> docs/index.html

# posts
posts=$(ls -t ./posts);
first_visible="1"
for f in $posts; do
    file="./posts/"$f
    echo "generating post $file"
    id="${file##*/}"    # ill name my posts just fine
    html=$(lowdown "$file")
    post_date=$(date -r "$file" "+%d/%m %Y")
    post_div=$(post_wrapper "$id" "$html" "$post_date" "$first_visible")
    echo -ne "$post_div" >> docs/index.html
    first_visible="0"
done

echo "
</div>
</body>
</html>
" >> docs/index.html