~aprates/gempress

gempress/src/capsule-to-website.sh -rwxr-xr-x 2.4 KiB
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
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
#!/usr/bin/env bash

# Converts Gemini Capsule folder to a HTML Website folder
# 2021, by Antonio Prates <hello@aprates.dev>

# Note: this script assumes you have Sugar C in yor system
# (see provided README.md for more information)

configFile=$1
gmipath=$2 # path to content folder
. $configFile

# set script globals
website=$PWD/website # if you change here also change on lib.sh
filePaths=""

# prevent running the script with no defined paths
[[ -z $templateDir ]] \
&& echo "Provide template and contents paths (without final slash), like:" \
&& echo "./src/capsule-to-website.sh ~/gemini/template ~/gemini/contents" \
&& exit 1
[[ -z $gmipath ]] \
&& echo "Provide template and contents paths (without final slash), like:" \
&& echo "./src/capsule-to-website.sh ~/gemini/template ~/gemini/contents" \
&& exit 1

function getFilePaths() {
    for item in $1/*; do
        if [[ -d $item ]];
        then
            # if it's a directory
            # then copy favicon.ico and styles.css to it as well
            cp -ux $templateDir/favicon.ico $item
            cp -ux $templateDir/styles.css $item
            # and get list of files in it
            getFilePaths $item
        elif [[ ${item: -4} == ".gmi" ]];
        then
            # else if it's .gmi a file, append to the conversion list
            filePaths="$filePaths $item"
        fi
    done
}

echo "Convering './capsule' to './website'…"

# take a clean copy of gmi folder (delete old copy if exists)
if [[ -d $website ]];
then
    rm -r $website
fi
cp -r $gmipath $website

# copy/update favicon.ico and styles.css to root folder
cp -ux $templateDir/favicon.ico $website
cp -ux $templateDir/styles.css $website

# colect all file paths in contents and run the conversion tool
getFilePaths $website
if [[ -n $extraMarkup ]];
then
    if [[ $extraMarkup == "enabled" ]];
    then
        echo "Using extra markup conversion: yes"
        conversionArgs="extraMarkup"
        
    fi
else
    echo "Using extra markup conversion: no"
fi
if [[ -n $langCode ]];
then
    if [[ -n $conversionArgs ]];
    then
        echo "Using language code: $langCode"
        conversionArgs="$conversionArgs lang:$langCode"
    else
        echo "Using language code: $langCode"
        conversionArgs="lang:$langCode"
    fi
fi
if [[ -n $conversionArgs ]];
then
    conversionArgs="$conversionArgs $filePaths"
else
    conversionArgs=$filePaths
fi
sugar src/gmi-to-html.c $conversionArgs

# clean up
rm $filePaths