sbs

A Simple Blogging System.
git clone https://git.sr.ht/~jbauer/sbs
Log | Files | Refs | README | LICENSE

commit 9fa7c63b3ae42202d84927d51c2743a1f52c95e7
parent 65ab9ca6dcc03e2ef24f7237403dd5c648b65468
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue, 15 Feb 2022 01:02:47 -0500

Fix new site and page generation

Config parsing was done too early so the code had to be refactored to
allow new site and post creation without worrying about the contents of
the config file since neither of them depend on it.

Diffstat:
Msbs | 41+++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/sbs b/sbs @@ -13,24 +13,6 @@ if [ ! -x "$(command -v lowdown)" ]; then exit 1 fi -# Parse the config file -options="siteURL siteName blogDir languageCode buildOptions" -for key in $options; do - value=$(grep "$key" config.ini | cut -d'=' -f2 | xargs) - if [ -n "$value" ]; then - eval "$key='$value'" - else - printf "Error: %s not configured." "$key" - exit 1 - fi -done - -# Validate configuration -if ! echo "$siteURL" | grep -qE '^https?://.*\..*/$'; then - echo "Error: siteURL should be in canonical form (e.g. https://example.com/)" - exit 1 -fi - # Note: The script does not run measurably faster if files are written to using # one versus many printfs. Therefore, I use many printf statements to ease # reading, understanding, and modification of the code. @@ -75,8 +57,27 @@ if [ "$1" = "new" ]; then printf "Created: %s\n" "$3" fi exit 0 -# Construct a complete atom feed -elif [ "$1" = "genfeed" ]; then +fi +# Parse the config file +options="siteURL siteName blogDir languageCode buildOptions" +for key in $options; do + value=$(grep "$key" config.ini | cut -d'=' -f2 | xargs) + if [ -n "$value" ]; then + eval "$key='$value'" + else + printf "Error: %s not configured." "$key" + exit 1 + fi +done + +# Validate configuration +if ! echo "$siteURL" | grep -qE '^https?://.*\..*/$'; then + echo "Error: siteURL should be in canonical form (e.g. https://example.com/)" + exit 1 +fi + +# Construct a complete atom feed if requested +if [ "$1" = "genfeed" ]; then printf '<?xml version="1.0" encoding="utf-8"?>\n' > static/feed.xml printf '<feed xmlns="http://www.w3.org/2005/Atom">\n' >> static/feed.xml printf "\t<title>$siteName</title>\n" >> static/feed.xml