justfile

 1# Build everything then deploy
 2default: site (docs "pdf") (docs "epub") (docs "txt") images deploy
 3
 4# Deploy website
 5deploy:
 6    # Deploying website ...
 7    rsync -qavmzz public/ hel1:/var/www/secluded/
 8    # Website deployed
 9
10# Build website
11site:
12    # Building website ...
13    hugo --quiet
14
15# Build documents of filetype ext
16docs ext:
17    #!/usr/bin/env bash
18
19    echo -e '\033[1m# Checking whether there are new {{uppercase(ext)}}s to generate ...\033[0m'
20
21    export WEBROOT=public
22
23    published=$(grep -ilr --include \*.md "draft: false" content/posts)
24
25    todo=""
26
27    # Iterate through all non-drafts
28    for path in $published
29    do
30        filename=$(basename "$path")
31        name=$(echo "${filename%.*}")
32        # Check whether target doc is newer than Markdown file
33        if [ "$path" -nt "public/$name/$name.{{ext}}" ]
34        then
35            todo+="$path "
36        fi
37    done
38
39    if [ -z "$todo" ]
40    then
41        echo "No {{uppercase(ext)}}s to generate"
42        exit 0
43    else
44        for path in $todo
45        do
46            filename=$(basename "$path")
47            name=$(echo "${filename%.*}")
48            echo "Generating $name.{{ext}}"
49
50            if [ "{{ext}}" == "pdf" ]
51            then
52                pandoc --quiet -f markdown -t pdf --lua-filter=pandoc_config/images.lua --pdf-engine=xelatex -V 'linkcolor:blue' --listings -H pandoc_config/styles.tex $path -o public/$name/$name.pdf
53            elif [ "{{ext}}" == "epub" ]
54            then
55                pandoc --quiet -f markdown -t epub3 --lua-filter=pandoc_config/images.lua --pdf-engine=xelatex -V 'linkcolor:blue' --listings -H pandoc_config/styles.tex $path -o public/$name/$name.epub
56            elif [ "{{ext}}" == "txt" ]
57            then
58                pandoc --quiet -f markdown -t plain --lua-filter=pandoc_config/images.lua $path -o public/$name/$name.txt
59            fi
60        done
61    fi
62
63# Generate cover images
64images:
65    #!/usr/bin/env bash
66
67    echo -e '\033[1m# Checking whether there are cover images to generate ...\033[0m'
68
69    echo -e '\033[1m# \033[4mTODO\033[0m\033[1m: Generate covers for posts that have changed or that have no cover\033[0m'
70    # wkhtmltoimage -f png --width 1200 --height 630 /tmp/file.html /tmp/file.png
71    # optipng -o4 file.png
72
73# Run development server
74serve:
75    hugo server -D