# mksite -rw-r--r-- 2.0 KiB View raw
                                                                                
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
#!/usr/bin/env bash
#
# mksite - Create a stupid simple website.
# inspired by Dylan Araps (https://dylan.k1ss.org) old website
# licensed under GNU GPL v3
# https://www.gnu.org/licenses/gpl-3.0.en.html

style=$(<styles.css)
templ='<!DOCTYPE html><html lang=en><head><meta name="description" content="dfr-web"/><meta charset="UTF-8"><link href="data:image/png;base64," rel=icon type="image/png"><title>&#9650;dfr</title><meta name=viewport content="width=device-width"><style>'"$style"'</style></head><body><main>{{content}}</main></body></html>'
webring=$(<logos/webring.svg)
merveilles=$(<logos/merveilles.svg)
github=$(<logos/github.svg)
twitter=$(<logos/twitter.svg)
footer='<footer><a aria-label="Webring" href="https://webring.xxiivv.com/#random" target="_blank" rel="noopener">'"$webring"'</a><a aria-label="Merveilles" rel="me" href="https://merveilles.town/@dfr">'"$merveilles"'</a><a aria-label="Github" href="https://github.com/blayhem">'"$github"'</a><a aria-label="Twitter" href="http://twitter.com/blayhem">'"$twitter"'</a></footer>'

[[ -z $1 ]] && rm -rf .site

mkdir -p .site/images

for md in src/*.md; do
    file_name=${md##*/}

    [[ $file_name != index.md ]] &&
        home="<a href='/'>&#9650;dfr</a>"

    minify --type html \
        <<< "${templ/'{{content}}'/${home}$(pandoc "$md")$footer}" \
        > ".site/${file_name/%.md/.html}"

    home=
done

[[ $1 ]] && exit
cd .site/images || exit

png_flags=(--speed 1 --skip-if-larger --strip -f --verbose --output)

for img in ../../img/*.{jpg,png}; do (
    file_name=${img##*/}
    suffix=${file_name/*.}
    x2=${file_name/%.${suffix}/-2x.${suffix}}

    convert "$img" -resize 600x\>  "$file_name"
    convert "$img" -resize 1200x\> "$x2"

    case $suffix in
        jpg) jpegoptim -s "$file_name" "$x2" ;;
        png)
            pngquant "$file_name" "${png_flags[@]}" "$file_name"
            pngquant "$x2" "${png_flags[@]}" "$x2"
        ;;
    esac

    img2webp -lossy -q 90 "$file_name" -o "${file_name%.${suffix}}.webp"
    img2webp -lossy -q 90 "$x2" -o "${x2%.${suffix}}.webp"
) & done

wait
# styles.css -rw-r--r-- 725 bytes View raw
                                                                                
1
body{overflow-y:scroll;font-family:sans-serif}a{color:#000}a:visited,a:hover{color:#1c1c1c}img,main,pre>code{display:block;margin:25px auto}main{padding:20px;max-width:600px;line-height:1.6;word-wrap:break-word}img{max-width:100%}pre>code{padding:20px;white-space:pre-wrap}code{background:#ddd;padding:2px}blockquote{border-left:7px solid #ddd;padding:0 14px;color:#666;margin:0}h1,h2,h3,h4{line-height:1.2}hr{border:2px solid #ddd}footer svg{fill:#000;width:48px;height:48px;transform:scale(0.5)}footer #webring{stroke:#000}@media(prefers-color-scheme:dark){body{background-color:#030303;color:#fdfdfd}a{color:#f8f8f8}a:visited,a:hover{color:#bdbdbd}code{background:#1c1c1c}footer svg{fill:#fff}footer #webring{stroke:#fff}}