commit e132234c2e5521b0848a88efe88bd578f77bbd35
parent 197b62fd34881f5d5b7432a60c01b2ea454181ad
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Wed, 8 Mar 2023 19:11:05 -0500
Silence output and add verbosity flag
There are two levels of verbosity: -v and -vv. The first prints out
command feedback where sbs would normally not print out anything and the
latter prints out each file as it is being built by the build
subcommand.
sbs has been modified to be silent by default as a result.
Diffstat:
M | sbs | | | 47 | +++++++++++++++++++++++++++++++++++++++-------- |
M | sbs.1 | | | 10 | ++++++++++ |
2 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/sbs b/sbs
@@ -40,13 +40,17 @@ new()
{ printf "Title: \nSummary: \n\n"
printf "# [%%title]\n\n"
} > "$3"
- printf "Created: %s\n" "$3"
+ if [ "$verbosity" -gt 0 ]; then
+ printf "Created: %s\n" "$3"
+ fi
elif [ "$2" = "post" ]; then
{ printf "Title: \nAuthor: \nDate: \nSummary: \n\n"
printf "# [%%title]\n\n"
printf "**Author:** [%%author] | **Published:** [%%date]\n\n"
} > "$3"
- printf "Created: %s\n" "$3"
+ if [ "$verbosity" -gt 0 ]; then
+ printf "Created: %s\n" "$3"
+ fi
elif [ "$2" = "site" ]; then
mkdir "$3" "$3/content/" "$3/static/" "$3/templates/"
# Create config.ini
@@ -89,7 +93,9 @@ new()
printf "\tmax-width: 100%%;\n"
printf "}\n"
} > "$3/static/style.css"
- printf "Created: %s\n" "$3"
+ if [ "$verbosity" -gt 0 ]; then
+ printf "Created: %s\n" "$3"
+ fi
else
printf "Subcommand '%s' not recognized. See sbs(1) for documentation.\n" "$2"
exit 1
@@ -160,7 +166,9 @@ genfeed()
numEntries="$(wc -l "$tmp" | cut -d' ' -f1)"
printf '</feed>\n' >> static/feed.xml
- printf "Created: static/feed.xml with %s entries.\n" "$numEntries"
+ if [ "$verbosity" -gt 0 ]; then
+ printf "Created: static/feed.xml with %s entries.\n" "$numEntries"
+ fi
rm "$tmp"
exit 0
}
@@ -190,7 +198,9 @@ build()
subDir=$(dirname "$file" | sed "s/.*\/content//")
mkdir -p "static/$subDir"
- printf "Creating: static%s/%s.html...\n" "$subDir" "$fileName"
+ if [ "$verbosity" -gt 1 ]; then
+ printf "Creating: static%s/%s.html...\n" "$subDir" "$fileName"
+ fi
# Extract metadata from markdown doc (if not converted from gmi)
title=${title:-$(lowdown -X title "$file")}
@@ -209,6 +219,7 @@ build()
-e "s/lang=\"\"/lang=\"$languageCode\"/" \
-e "s/content=\"\"/content=\"$description\"/" \
> "static/$subDir/$fileName".html
+ count=$(($count + 1))
done
}
@@ -252,6 +263,21 @@ walk_back()
fi
}
+verbosity=0
+
+if [ "$#" -gt 1 ]; then
+ case "$1" in
+ "-v" )
+ verbosity=1
+ shift
+ ;;
+ "-v"* )
+ verbosity=2
+ shift
+ ;;
+ esac
+fi
+
if [ "$#" -lt 1 ]; then
echo "Please provide a command. See sbs(1) for documentation."
exit 1
@@ -264,15 +290,20 @@ case "$1" in
cwd="$(pwd)"
walk_back
parse_configuration
- mkdir -p /tmp/sbs/
# Allows simply running "sbs build" without path(s)
+ count=0
+ start_s=$(date +%s)
if [ $# -eq 0 ]; then
cwd=""
build ./content/*
else
build "$@"
fi
- rm -rf /tmp/sbs/
+ end_s=$(date +%s)
+ if [ "$verbosity" -gt 0 ]; then
+ printf "Built %d files in %d seconds.\n" \
+ $count "$(($end_s - $start_s))"
+ fi
;;
"genfeed")
walk_back
@@ -291,7 +322,7 @@ case "$1" in
echo "v1.0.0" ;
;;
*)
- echo "Usage: sbs <command> [FILE ...]"
+ echo "Unknown command. See sbs(1) for documentation."
;;
esac
diff --git a/sbs.1 b/sbs.1
@@ -6,6 +6,7 @@
.Nd A simple blogging system
.Sh SYNOPSIS
.Nm sbs
+.Op Fl v
.Cm command
.Sh DESCRIPTION
.Nm
@@ -15,6 +16,15 @@ Markdown files into HTML using
.Xr lowdown 1
with some additional processing and capabilities.
.Pp
+Arguments are as follows:
+.Bl -tag -width Ds
+.It Fl v
+Increase verbosity.
+Specify once for command feedback and twice to see each file being built by the
+.Cm build
+subcommand.
+.El
+.Pp
Commands are as follows:
.Bl -tag -width Ds
.It Cm build Ar