summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgemtexter5
-rw-r--r--lib/gemfeed.source.sh16
2 files changed, 18 insertions, 3 deletions
diff --git a/gemtexter b/gemtexter
index 1b0aa5f..bdb03dc 100755
--- a/gemtexter
+++ b/gemtexter
@@ -4,6 +4,7 @@
# by Paul Buetow 2021
declare -r ARG="$1"; shift
+declare -r VERSION=1.0
declare DATE=date
declare SED=sed
declare GREP=grep
@@ -41,6 +42,7 @@ $0's possible arguments:
If USE_GIT=yes set, all files will be commited to git too.
If GIT_PUSH=yes is set, all content will be pushed to origin.
--test Only runs some shellcheck and unit tests.
+ --version Prints out the version of gemtexter
--help Prints this retty text.
Example:
USE_GIT=yes GIT_PUSH=yes $0 --generate
@@ -99,6 +101,9 @@ main () {
atomfeed::generate
generate::fromgmi html md
;;
+ --version)
+ echo "This is gemtexter version $VERSION"
+ ;;
--help|*)
help
;;
diff --git a/lib/gemfeed.source.sh b/lib/gemfeed.source.sh
index c842bb1..eba9384 100644
--- a/lib/gemfeed.source.sh
+++ b/lib/gemfeed.source.sh
@@ -26,6 +26,11 @@ gemfeed::updatemainindex () {
git::add gemtext "$index_gmi"
}
+gemfeed::_get_word_count () {
+ local -r gmi_file="$1"; shift
+ sed '/^```/,/^```/d' "$gmi_file" | wc -w | cut -d' ' -f1
+}
+
# Generate a index.gmi in the ./gemfeed subdir.
gemfeed::generate () {
local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed"
@@ -40,11 +45,16 @@ GEMFEED
gemfeed::get_posts | while read -r gmi_file; do
# Extract first heading as post title.
- local title=$($SED -n '/^# / { s/# //; p; q; }' "$gemfeed_dir/$gmi_file" | tr '"' "'")
- # Extract the date from the file name.
+ local title=$($SED -n '/^# / { s/# //; p; q; }' \
+ "$gemfeed_dir/$gmi_file" | tr '"' "'")
+
+ # Extract the date from the file name, and also get the word count.
local filename_date=$(basename "$gemfeed_dir/$gmi_file" | cut -d- -f1,2,3)
- echo "=> ./$gmi_file $filename_date - $title" >> "$gemfeed_dir/index.gmi.tmp"
+ local words=$(printf %04d $(gemfeed::_get_word_count "$gemfeed_dir/$gmi_file"))
+
+ echo "=> ./$gmi_file $filename_date ($words words) - $title" >> \
+ "$gemfeed_dir/index.gmi.tmp"
done
mv "$gemfeed_dir/index.gmi.tmp" "$gemfeed_dir/index.gmi"