~aprates/gempress

gempress/src/lib.sh -rwxr-xr-x 2.1 KiB
fc494358Antonio Prates Fix html lang bug 10 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
#!/usr/bin/env bash

# publish utilities lib
# 2021, by Antonio Prates <hello@aprates.dev>

# how many entries from feed to copy into home
maxHomeEntries=5

# set target folder within current folder
capsule=$PWD/capsule
website=$PWD/website # if you change here also change capsule-to-website.sh

# set absoluteFeedDir
if [[ -z $absoluteFeedDir ]];
then
    absoluteFeedDir=$feedDir
fi

# takes a clean copy of gmi folder ot capsule folder
function takeCleanCopyOfLocalBaseDir() {
    if [[ -d $capsule ]];
    then
        rm -r $capsule
    fi
    cp -r $localBaseDir $capsule
}

# append feed
function appendFeedToHome() {
    echo -e "Appending last $maxHomeEntries entries to home…"
    echo "" >> $capsule/index.gmi
    cat $capsule/$feedDir/index.gmi | grep "=> " > $capsule/$feedDir/feed.gmi
    for feed in $capsule/$feedDir/feed.gmi; do
        head -$maxHomeEntries $feed
    done > $capsule/index.gmi.feed
    sugar src/absolute.c $capsule/index.gmi.feed $absoluteFeedDir \
    >> $capsule/index.gmi
    rm $capsule/index.gmi.feed
}

# resets feed (to remove footer) and add link to home
function linkFeedToHome() {
    echo -e "Appending home link to feed…"
    cp -f $localBaseDir/$feedDir/index.gmi $capsule/$feedDir/index.gmi
    echo -e "\n$gmiLinkHome" >> $capsule/$feedDir/index.gmi
}

function generateAtomFeedGemini() {
    echo "Generating atom feed as gemini/gmi…"
    sugar src/atom.c $configFile $capsule/$feedDir/feed.gmi
    rm $capsule/$feedDir/feed.gmi
}

function generateAtomFeedHttps() {
    echo "Generating atom feed as https/html…"
    sugar src/atom.c $configFile https $capsule/$feedDir/feed.gmi
    rm $capsule/$feedDir/feed.gmi
}

function cleanUp() {
    echo
    echo "Cleaning up…"
    [[ -d $capsule ]] && rm -r $capsule
    [[ -f capsule.tar.gz ]] && rm capsule.tar.gz
    [[ -d $website ]] && rm -r $website
    [[ -f website.tar.gz ]] && rm website.tar.gz
    sync
}

echo "  ____                ____                   "
echo " / __/  ___ _ ___ __ |  _ \ _ __ ___ ,___ ___"
echo "/ / __ / _ \ \`_  \`_ \`| |_) | '__/ _ \ __/ __/"
echo "\ \_| |  --| | | | | |  __/| | |  --|__ |__ |"
echo " \__,_|\___\_| |_| |_|_|   |_|  \___\___/___/"