aboutsummaryrefslogtreecommitdiff
path: root/generate.sh
blob: b246d61cd19335fbc773bb82b247a27a606bec41 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p eva pandoc esh

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

read_time() {
    minu="$(eva -f 1 $1/150 | xargs)"
    echo "$minu"
}

height() {
    cm="$(eva -f 2 $1*18*0.0222 | xargs)"
    echo "$cm"
}

link_wrapper() {
    # 1 - id
    # 2 - title
    # 3 - date
    # 4 - read time
    echo -ne "
    <tr>
        <td class="table-post">
            <div class=\"date\">
                $3
            </div>
            <a href=\"/posts/$1\" class=\"post-link\">
                <span class=\"post-link\">$2</span>
            </a>
        </td>
        <td class="table-stats">
            <span class=\"stats-number\">
                $4
            </span>
            <span class="stats-unit">min</span>
        </td>
    </tr>
    "
}

intro() {
    echo -ne "
    <div class="intro">
        Hi. 
        <div class="hot-links">
            <a href="https://peppe.rs/index.xml" class="feed-button">Subscribe</a>
            <a href="https://liberapay.com/nerdypepper/donate" class="donate-button">Donate</a>
        </div>
        <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p>
        <p>
        I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer.
        I write <a href="https://git.peppe.rs">open-source stuff</a> to pass time. 
        I also design fonts: 
        <a href="https://git.peppe.rs/fonts/scientifica">scientifica</a>, 
        <a href="https://git.peppe.rs/fonts/curie">curie</a>.
        </p>
        <p>Send me a mail at [email protected] or a message at [email protected].</p>
    </div>
    "
}

cat > ./docs/index.html << EOF
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<link rel="alternate" type="application/atom+xml" title="nerdypepper's micro musings" href="./index.xml">
<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="nerdypepper's micro musings">
<meta property="og:url" content="https://peppe.rs">
<link rel="icon" type="image/x-icon" href="/favicon.png">
<title>peppe.rs</title>
<body>
    <h1 class="heading">n</h1>
    <h4 class="subheading">nerdypepper's μsings</h4>
    <div class="posts">
    <div class="post">
EOF

echo -ne "$(intro)<table>" >> ./docs/index.html

# posts
posts=$(ls -t ./posts)
mkdir -p docs/posts
rm -rf "./docs/posts/"

for f in $posts; do
    file="./posts/"$f
    id="${file##*/}"    # ill name my posts just fine

    # generate posts
    stats=$(wc "$file")
    words="$(echo $stats | awk '{print $2}')"
    lines="$(echo $stats | awk '{print $1}')"

    r_time="$(read_time $words)"
    height="$(height $lines)"

    post_title=$(title_wrapper "$id")
    echo "[~] $post_title"
    post_date=$(date -r "$file" "+%d/%m — %Y")
    post_link=$(link_wrapper "${id%.*}" "$post_title" "$post_date" "$r_time" "$height")
    echo -ne "$post_link" >> docs/index.html

    id="${id%.*}"
    mkdir -p "docs/posts/$id"
    esh  \
        -o "docs/posts/$id/index.html" \
        "./post.esh" \
        file="$file" \
        date="$post_date" \
        title="$post_title" \
        read_time="$r_time" \
        height="$height" \
        intro="$(intro)"
done

# generate rss feeds
echo "generating RSS feeds ..."
esh  \
    -o "./docs/index.xml" \
    "rss.esh"

cat >> ./docs/index.html << EOF
    </table>
    <div class="separator"></div>
    <div class="footer">
        <a href="https://github.com/nerdypepper">Github</a> · 
        <a rel="me" href="https://freeradical.zone/@NerdyPepper">Mastodon</a> ·
        <a href="mailto:[email protected]">Mail</a> · 
        <a href="https://linkedin.com/in/nerdypepper">LinkedIn</a> · 
        <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
            <img class="footimgs" src="https://d33wubrfki0l68.cloudfront.net/94387e9d77fbc8b4360db81e72603ecba3df94a7/632bc/static/cc.svg">
        </a>
    </div>
    </div>
</div>
</body>
</html>
EOF