~aprates/gempress

gempress/publish -rwxr-xr-x 2.4 KiB
fc494358Antonio Prates Fix html lang bug 9 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash

# Publish Capsule and Webpage to [SourceHut Pages](gemini://srht.site/)
# 2021, by Antonio Prates <hello@aprates.dev>
# see provided README.md for more information

############## SOURCE CONFIG

configFile="capsule.conf"
if [[ $# == 2 ]];
then
    configFile="$2"
fi
if [[ -f $configFile ]];
then
    . $configFile
fi

############## SOURCE GEMPRESS LIB

orginalDir=$PWD
cd "$(dirname "${BASH_SOURCE[0]}")"
. ./src/lib.sh

############## CLEAN UP

if [[ $1 == "clean" ]];
then
    cleanUp
    cd $orginalDir
    exit 0
fi

############## CHECK CONFIG

echo
echo "Using config: $configFile"
if [[
        -z $localBaseDir ||
        -z $templateDir ||
        -z $gmiLinkHome  ||
        -z $feedDir
]];
then
    echo
    echo "Please, provide configurations (see capsule-example.conf)"
    cd $orginalDir
    exit 1
fi

############## CHECK ARGUMENTS

if [[
        -z $1 ||
        $1 != "local" &&
        $1 != "srht" &&
        $1 != "clean" &&
        $1 != "auto"
]];
then
    echo
    echo "Please, provide option as argument:"
    echo "./publish local  -> exports to local folders"
    echo "./publish srht   -> exports local folders to sr.ht"
    echo "./publish clean  -> cleans local folders"
    echo "./publish auto   -> local + srht + clean"
    cd $orginalDir
    exit 2
fi

############## PUBLISH LOCAL SCRIPT

if [[ $1 == "local" || $1 == "auto" ]];
then
    echo
    echo "Buidling HTTPS/HTML Website…"
    takeCleanCopyOfLocalBaseDir
    appendFeedToHome
    generateAtomFeedHttps
    ./src/append-footer.sh $templateDir/web-footer.gmi $capsule
    linkFeedToHome
    ./src/capsule-to-website.sh $configFile $capsule
    echo
    echo "Buidling GEMINI Capsule…"
    takeCleanCopyOfLocalBaseDir
    appendFeedToHome
    generateAtomFeedGemini
    ./src/append-footer.sh $templateDir/gmi-footer.gmi $capsule
    linkFeedToHome
fi

############## PUBLISH TO SRHT SCRIPT

if [[ $1 == "srht" || $1 == "auto" ]];
then
    echo
    echo "Publishing HTTPS/HTML Website…"
    tar -czf website.tar.gz -C $website .
    curl --oauth2-bearer $srhtToken \
    -Fcontent=@website.tar.gz \
    -Fprotocol=HTTPS $srhtSendUrl
    echo
    echo "Publishing GEMINI Capsule…"
    tar -czf capsule.tar.gz -C $capsule .
    curl --oauth2-bearer $srhtToken \
    -Fcontent=@capsule.tar.gz \
    -Fprotocol=GEMINI $srhtSendUrl
fi

############## CLEAN UP ON AUTO

if [[ $1 == "auto" ]];
then
    cleanUp
fi

############## REVERT TO USER DIR

cd $orginalDir
echo
echo "Done"
exit 0