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    published=$(grep -ilr --include \*.md "draft: false" content/posts)
 70
 71    todo=""
 72
 73    # Iterate through all non-drafts
 74    for path in $published
 75    do
 76        filename=$(basename "$path")
 77        name=$(echo "${filename%.*}")
 78        # Check whether target doc is newer than Markdown file
 79        if [ "$path" -nt "public/$name/cover.png" ]
 80        then
 81            todo+="$path "
 82        fi
 83    done
 84
 85    if [ -z "$todo" ]
 86    then
 87        echo "No covers to generate"
 88        exit 0
 89    else
 90        for path in $todo
 91        do
 92            filename=$(basename "$path")
 93            name=$(echo "${filename%.*}")
 94            echo "Generating cover for $name"
 95
 96            p2c -i $path -o public/$name/cover.png
 97        done
 98    fi
 99
100# Run development server
101serve:
102    hugo server -D