~aprates/gempress

gempress/src/append-footer.sh -rwxr-xr-x 1004 bytes
fc494358Antonio Prates Fix html lang bug 11 months ago
                                                                                
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
#!/usr/bin/env bash

# Appends template/footer.gmi to Gemini Capsule gmi files
# 2021, by Antonio Prates <hello@aprates.dev>

footer=$1 # path footer file
gmipath=$2 # path to content folder

# prevent running the script with no defined path or footer
[[ -z $footer ]] \
&& echo "Provide content folder (without final slash) and footer file, like:" \
&& echo "./append-footer.sh ~/gemini ./template/footer.gmi" && exit 1
[[ -z $gmipath ]] \
&& echo "Provide content folder (without final slash) and footer file, like:" \
&& echo "./append-footer.sh ~/gemini ./template/footer.gmi" && exit 1

function appendGeminiFiles() {
    for item in $1/*; do
        if [[ -d $item ]];
        then
            # if it's a directory, search for files in it
            appendGeminiFiles $item
        elif [[ ${item: -4} == ".gmi" ]];
        then
            # else if it's .gmi a file, append footer
            cat $footer >> $item
        fi
    done
}

echo "Appending '$footer'…"
appendGeminiFiles $gmipath