aboutsummaryrefslogtreecommitdiff
path: root/generate.sh
blob: a8384d29ba5fcd4e480dd028a5cd7864090cdaec (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p eva pandoc esh

INDEX_BLOG_LIMIT=3
INDEX_BLOG_COUNT=0
INDEX_ART_LIMIT=1
INDEX_ART_COUNT=0

source ./scripts.sh

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>
    "
}

more_links() {
    # 1 - sub page
    cat << EOF
    <tr><td><a href="/$1" class="post-end-link">More ⟶ </a></td></tr>
EOF
}

recent_link() {
    # 1 - sub page
    cat << EOF
    <tr><td class="recent-heading"><span class="recent-heading">Recent $1</span></td></tr>
EOF
}

art_block() {
    # 1 - filename
    # 2 - title
    # 3 - date
    echo -ne "
    <tr>
        <td class="table-post">
            <div class=\"date\">
                $3
            </div>
            <a href=\"/art/$1\" class=\"post-link\">
                <span class=\"post-link\">$2</span>
            </a>
        </td>
        <td class=\"table-stats\">
            <a href=\"/art/$1\">
                <img src=\"/art/$1\" height=\"50px\">
            </a>
        </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>
        </div>
        <p>I'm Akshay, programmer and pixel-artist.</p>
        <p>
        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/about\">scientifica</a>, 
        <a href=\"https://git.peppe.rs/fonts/curie/about\">curie</a>.
        </p>
        <p>Send me a mail at [email protected] or a message at [email protected].</p>
    </div>
    "
}

breadcrumbs() {
    # 1 - path
    cat << EOF
    <a href="/" class="post-end-link">Home</a>
    <span>/</span>
    <a class="post-end-link">$1</a>
EOF
}

n_logo() {
    cat << EOF
    <h1 class="heading">n</h1>
    <h4 class="subheading">nerdypepper's μsings</h4>
EOF
}

# setup dirs

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

art=$(ls -t ./art)
rm -rf "./docs/art/"
mkdir -p docs/art
cp -r ./art/* docs/art/


cat << EOF | tee ./docs/posts/index.html ./docs/index.html > /dev/null
<!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>
EOF

# index
echo
echo "[+] INDEX"
echo "$(n_logo)" >> ./docs/index.html

for p in Posts Art; do
    cat << EOF | tee -a ./docs/${p,,}/index.html > /dev/null
    <body>
        <div class="posts">
        <div class="post">
        $(breadcrumbs $p)
EOF
done

cat << EOF >> ./docs/index.html
    <body>
    <div class="posts">
    <div class="post">
    $(intro)
    <table>
    $(recent_link "Posts")
EOF

# posts
echo -ne "
    <h1>Posts</h1>
    <div class=\"separator\"></div>
    <table>
    " >> ./docs/posts/index.html

echo
echo "[+] 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/posts/index.html

    if [[ $INDEX_BLOG_COUNT -lt $INDEX_BLOG_LIMIT ]]; then
        echo -ne "$post_link" >> ./docs/index.html
    fi
    ((INDEX_BLOG_COUNT+=1))

    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

echo "$(more_links posts)" >> ./docs/index.html
echo "$(recent_link Art)" >> ./docs/index.html

# art

echo
echo "[+] ART"

esh  \
    -o "docs/art/index.html" \
    art.esh

for f in $art; do
    if [[ $INDEX_ART_COUNT -lt $INDEX_ART_LIMIT ]]; then
        file="./art/"$f
        id="${file##*/}"
        art_title=$(title_wrapper "$id")
        art_date=$(date -r "$file" "+%d/%m — %Y")
        art_post=$(art_block "$f" "$art_title" "$art_date")
        echo "[~] $art_title"
        echo -ne "$art_post" >> ./docs/index.html
        ((INDEX_ART_COUNT+=1))
    fi
done

echo "$(more_links art)" >> ./docs/index.html 

# generate rss feeds
echo
echo "[+] Generating RSS feeds ..."
esh  \
    -o "./docs/index.xml" \
    "rss.esh"

cat << EOF | tee -a ./docs/posts/index.html ./docs/index.html > /dev/null
    </table>
    <div class="separator"></div>
    <div class="footer">
        <a href="https://git.peppe.rs">Code</a> · 
        <a rel="me" href="https://merveilles.town/@nerdypepper">Fediverse</a> ·
        <a href="mailto:[email protected]">Mail</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