sbs

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

commit 4bb58b92450d8c162b6335c4dc4b642087089018
parent 4ff916dd83e9241272b4a636266aea3732e1071c
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue, 22 Feb 2022 14:02:40 -0500

Group printf statements

Diffstat:
Msbs | 98+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 53 insertions(+), 45 deletions(-)

diff --git a/sbs b/sbs @@ -22,42 +22,47 @@ fi # Create a new page or a new site if [ "$1" = "new" ]; then if [ "$2" = "page" ]; then - printf "Title: \nSummary: \n\n" > "content/$3" - printf "# [%%title]\n\n" >> "content/$3" + { printf "Title: \nSummary: \n\n" + printf "# [%%title]\n\n" + } > "content/$3" printf "Created: content/%s\n" "$3" elif [ "$2" = "post" ]; then - printf "Title: \nAuthor: \nDate: \nSummary: \n\n" > "content/$3" - printf "# [%%title]\n\n" >> "content/$3" - printf "**Author:** [%%author] | **Published:** [%%date]\n\n" >> "content/$3" - printf "Created: content/%s\n" "$3" + { printf "Title: \nAuthor: \nDate: \nSummary: \n\n" + printf "# [%%title]\n\n" + printf "**Author:** [%%author] | **Published:** [%%date]\n\n" + printf "Created: content/%s\n" "$3" + } > "content/$3" elif [ "$2" = "site" ]; then mkdir "$3" "$3/content/" "$3/static/" "$3/templates/" touch "$3/static/style.css" # Create template config.ini file - printf "siteURL = https://example.com/\n" > "$3/config.ini" - printf "siteName = %s\n" "$3" >> "$3/config.ini" - printf "blogDir = blog/\n" >> "$3/config.ini" - printf "languageCode = en\n" >> "$3/config.ini" - printf "buildOptions = -Thtml --html-no-skiphtml --html-no-escapehtml\n" >> "$3/config.ini" + { printf "siteURL = https://example.com/\n" + printf "siteName = %s\n" "$3" + printf "blogDir = blog/\n" + printf "languageCode = en\n" + printf "buildOptions = -Thtml --html-no-skiphtml --html-no-escapehtml\n" + } > "$3/config.ini" # Create template header.html file - printf '<!DOCTYPE html>\n' > "$3/templates/header.html" - printf '<html lang="">\n' >> "$3/templates/header.html" - printf '<head>\n' >> "$3/templates/header.html" - printf '\t<meta charset="utf-8">\n' >> "$3/templates/header.html" - printf '\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n' >> "$3/templates/header.html" - printf '\t<meta name="description" content="">\n' >> "$3/templates/header.html" - printf '\t<link rel="stylesheet" href="/style.min.css">\n' >> "$3/templates/header.html" - printf '\t<link rel="alternate" type="application/rss+xml" title="RSS feed" href="/feed.xml">\n' >> "$3/templates/header.html" - printf '\t<title></title>\n' >> "$3/templates/header.html" - printf '</head>\n' >> "$3/templates/header.html" - printf '<body>\n' >> "$3/templates/header.html" - printf '\t<header></header>\n' >> "$3/templates/header.html" - printf '\t<main>\n' >> "$3/templates/header.html" + { printf '<!DOCTYPE html>\n' + printf '<html lang="">\n' + printf '<head>\n' + printf '\t<meta charset="utf-8">\n' + printf '\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n' + printf '\t<meta name="description" content="">\n' + printf '\t<link rel="stylesheet" href="/style.min.css">\n' + printf '\t<link rel="alternate" type="application/rss+xml" title="RSS feed" href="/feed.xml">\n' + printf '\t<title></title>\n' + printf '</head>\n' + printf '<body>\n' + printf '\t<header></header>\n' + printf '\t<main>\n' + } > "$3/templates/header.html" # Create template footer.html file - printf '\t</main>\n' > "$3/templates/footer.html" - printf '\t<footer></footer>\n' >> "$3/templates/footer.html" - printf '</body>\n' >> "$3/templates/footer.html" - printf '</html>\n' >> "$3/templates/footer.html" + { printf '\t</main>\n' + printf '\t<footer></footer>\n' + printf '</body>\n' + printf '</html>\n' + } > "$3/templates/footer.html" printf "Created: %s\n" "$3" else printf "Command '%s' not recognized.\n" "$2" @@ -65,6 +70,7 @@ if [ "$1" = "new" ]; then fi exit 0 fi + # Parse the config file options="siteURL siteName blogDir languageCode buildOptions" for key in $options; do @@ -85,15 +91,16 @@ 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>%s</title>\n" "$siteName" >> static/feed.xml - printf "\t<link href=\"%s\" />\n" "$siteURL" >> static/feed.xml - printf "\t<link rel=\"self\" href=\"%sfeed.xml\" />\n" "${siteURL}" >> static/feed.xml - printf "\t<icon>/favicon.png</icon>\n" >> static/feed.xml - printf "\t<updated>%s</updated>\n" "$(date +"%Y-%m-%dT%H:%M:%S%:z")" >> static/feed.xml - printf "\t<id>%s</id>\n" "$siteURL" >> static/feed.xml - printf "\t<generator>sbs</generator>\n\n" >> static/feed.xml + { printf '<?xml version="1.0" encoding="utf-8"?>\n' + printf '<feed xmlns="http://www.w3.org/2005/Atom">\n' + printf "\t<title>%s</title>\n" "$siteName" + printf "\t<link href=\"%s\" />\n" "$siteURL" + printf "\t<link rel=\"self\" href=\"%sfeed.xml\" />\n" "${siteURL}" + printf "\t<icon>/favicon.png</icon>\n" + printf "\t<updated>%s</updated>\n" "$(date +"%Y-%m-%dT%H:%M:%S%:z")" + printf "\t<id>%s</id>\n" "$siteURL" + printf "\t<generator>sbs</generator>\n\n" + } > static/feed.xml numEntries=0 tmp=$(mktemp) @@ -112,14 +119,15 @@ if [ "$1" = "genfeed" ]; then author=$(lowdown -X author "$file") date=$(lowdown -X date "$file") - printf "\t<entry>\n" >> static/feed.xml - printf "\t\t<title>%s</title>\n" "$title">> static/feed.xml - printf "\t\t<author><name>%s</name></author>\n" "$author">> static/feed.xml - printf "\t\t<link href=\"%s%s/%s\" />\n" "$siteURL" "$subDir" "$fileName" >> static/feed.xml - printf "\t\t<id>%s%s/%s</id>\n" "$siteURL" "$subDir" "$fileName" >> static/feed.xml - printf "\t\t<updated>%s</updated>\n" "$(date -d "$date" +"%Y-%m-%dT%H:%M:%S%:z")" >> static/feed.xml - printf "\t\t<content type=\"text\"><![CDATA[\n%s\n\t\t]]></content>\n" "$(lowdown $buildOptions "$file")" >> static/feed.xml - printf "\t</entry>\n\n" >> static/feed.xml + { printf "\t<entry>\n" + printf "\t\t<title>%s</title>\n" "$title" + printf "\t\t<author><name>%s</name></author>\n" "$author" + printf "\t\t<link href=\"%s%s/%s\" />\n" "$siteURL" "$subDir" "$fileName" + printf "\t\t<id>%s%s/%s</id>\n" "$siteURL" "$subDir" "$fileName" + printf "\t\t<updated>%s</updated>\n" "$(date -d "$date" +"%Y-%m-%dT%H:%M:%S%:z")" + printf "\t\t<content type=\"text\"><![CDATA[\n%s\n\t\t]]></content>\n" "$(lowdown $buildOptions "$file")" + printf "\t</entry>\n\n" + } >> static/feed.xml numEntries=$((numEntries+1)) done