sbs

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

commit 36fa487109e51fca77ea1fad2864a73ef5c47c9a
parent 984bd9dec1226c8568eac31062c543d37ad15fa2
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Mon, 14 Feb 2022 23:13:37 -0500

Split single printf statements into multiple

Diffstat:
Msbs | 38++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/sbs b/sbs @@ -25,17 +25,47 @@ for key in $options; do fi done +# 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. +# (This was tested with an Intel Core 2 Duo P7550 and an SSD running at SATA-II +# speeds, so unless a user is generating their site on a 386, it should be fine) + # Create a new page or a new site if [ "$1" = "new" ]; then if [ "$2" = "page" ]; then - printf "Title: \nAuthor: \nDate: \nSummary: \n\n# [%%title]\n\n**Author:** [%%author] | **Published:** [%%date]\n\n" > "content/$3" + 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" "$3" elif [ "$2" = "site" ]; then mkdir "$3/content/" "$3/static/" "$3/templates/" touch "$3/static/style.css" - printf "siteURL = https://example.com\nsiteName = $3\nblogDir = blog\nlanguageCode = en\nbuildOptions = -Thtml --html-no-skiphtml --html-no-escapehtml\n" > "$3/config.ini" - printf '<!DOCTYPE html>\n<html lang="">\n<head>\n\t<meta charset="utf-8">\n\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\t<meta name="description" content="">\n\t<link rel="stylesheet" href="/style.min.css">\n\t<link rel="alternate" type="application/rss+xml" title="RSS feed" href="/feed.xml">\n\t<title></title>\n</head>\n<body>\n\t<header></header>\n\t<main>\n' > "$3/templates/header.html" - printf '\t</main>\n\t<footer></footer>\n</body>\n</html>\n' > "$3/templates/footer.html" + # Create template config.ini file + printf "siteURL = https://example.com\n" > "$3/config.ini" + printf "siteName = $3\n" >> "$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" + # 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" + # 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 "Created: %s\n" "$3" fi exit 0