aboutsummaryrefslogtreecommitdiff
path: root/generate.sh
blob: af70b333c90d5dc0a3e6c091a76f2bd31b70e839 (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
#! /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
    # 3 - date
    title="$( post_title $1 )"
    echo -ne "
    <details class=\"post\">
        <summary>
            <div class=\"date\">$3</div>
            <span class=\"post-link\">$title</span>
        </summary>
        <div class=\"post-text\">
            $2
            <div class="separator"></div>
        </div>
    </details>
    "
}

# meta
echo "
<!DOCTYPE html>
<html lang=\"en\">
<head>
<link rel=\"stylesheet\" href=\"./style.css\">
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"initial-scale=1\">
<meta content=\"#ffffff\" name=\"theme-color\">
<meta name=\"HandheldFriendly\" content=\"true\">
<meta property=\"og:title\" content=\"nerdypepper\">
<meta property=\"og:type\" content=\"website\">
<meta property=\"og:description\" content=\"a static site {for, by, about} me \">
<meta property=\"og:url\" content=\"https://nerdypepper.tech\">
<title>n</title>
" > ./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);
for f in $posts; do
    file="./posts/"$f
    echo "generating post $file"
    id="${file##*/}"    # ill name my posts just fine

    html=$(lowdown "$file")

    # generate posts
    post_date=$(date -r "$file" "+%d/%m %Y")
    post_div=$(post_wrapper "$id" "$html" "$post_date")
    echo -ne "$post_div" >> docs/index.html
    first_visible="0"
done

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