You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gemtexter/gemtexter

148 lines
3.7 KiB

#!/usr/bin/env bash
#
# The Gemtexter blog engine and static site generator
# by Paul Buetow 2021, 2022
declare -r ARG="$1"; shift
declare -r CONTENT_FILTER="$1"; shift
declare -r VERSION=1.1.1
declare -r VERSION_DESCR=release
declare DATE=date
declare SED=sed
declare GREP=grep
which gdate &>/dev/null && DATE=gdate
which gsed &>/dev/null && SED=gsed
which ggrep &>/dev/null && GREP=ggrep
readonly DATE
readonly SED
readonly GREP
set -e
if [[ -n "$CONFIG_FILE_PATH" ]]; then
source "$CONFIG_FILE_PATH"
elif [[ -f ~/.config/gemtexter.conf ]]; then
source ~/.config/gemtexter.conf
else
source ./gemtexter.conf
fi
source ./lib/assert.source.sh
source ./lib/atomfeed.source.sh
source ./lib/gemfeed.source.sh
source ./lib/generate.source.sh
source ./lib/git.source.sh
source ./lib/html.source.sh
source ./lib/log.source.sh
source ./lib/md.source.sh
source ./lib/notes.source.sh
help () {
cat <<HELPHERE
$0's possible arguments:
--feed Generates Gemtext Atom feed and Gemfeed.
--generate Generates all known output formats (html, md, ...).
--test Only runs some shellcheck and unit tests.
--version Prints out the version of gemtexter
--git-add Add all files to Git
--git-sync Sync all files with the remote origin
--git Both of above
--help Prints this pretty text.
Example:
$0 --generate
HELPHERE
}
# Make sure that there are the correct versions of the dependencies installed.
check_dependencies () {
# At least, Bash 5 is required
local -i required_version=5
IFS=. read -ra version <<< "$BASH_VERSION"
if [ "${version[0]}" -lt $required_version ]; then
log ERROR "ERROR, \"bash\" must be at least at major version $required_version!"
exit 2
fi
# These must be the GNU versions of the commands
for tool in $DATE $SED $GREP; do
if ! $tool --version | grep -q GNU; then
log ERROR "ERROR, \"$tool\" command is not the GNU version, please install!"
exit 2
fi
done
}
setup () {
if [ ! -d "$CONTENT_BASE_DIR" ]; then
cat <<END
The content base directory, does not exist. Run the following to create it, it
also adds some sample Gemtext content:
mkdir -p $CONTENT_BASE_DIR/{meta,md,html}
git clone --branch content-gemtext https://codeberg.org/snonux/foo.zone $CONTENT_BASE_DIR/gemtext
rm -Rf $CONTENT_BASE_DIR/gemtext/.git
Once done, you are ready to edit the files in $CONTENT_BASE_DIR/gemtext. Every
time you want to generate other formats from Gemtext (e.g. HTML, Markdown), run
$0 --generate
again.
For a list of other available arguments run
$0 --help
END
exit 1
fi
}
main () {
check_dependencies
setup
case $ARG in
--test)
LOG_VERBOSE=yes
assert::shellcheck
html::test
md::test
;;
--feed)
gemfeed::generate
atomfeed::generate
;;
--generate)
log INFO 'Generating feeds - this may will take a while'
gemfeed::generate &
atomfeed::generate &
notes::generate &
wait
generate::fromgmi html md
;;
--git)
git::add_all "$GIT_COMMIT_MESSAGE"
git::sync_all
;;
--git-add)
git::add_all "$GIT_COMMIT_MESSAGE"
;;
--git-sync)
git::sync_all
;;
--version)
echo "This is gemtexter version $VERSION $VERSION_DESCR"
;;
--publish)
$0 --generate
$0 --git
;;
--help|*)
help
;;
esac
return 0
}
main
exit $?