diff options
| author | Paul Buetow <git@mx.buetow.org> | 2021-05-29 10:11:39 +0100 |
|---|---|---|
| committer | Paul Buetow <git@mx.buetow.org> | 2021-05-29 10:11:39 +0100 |
| commit | 8512f249f4b1f475e21ad0221c14ea5453f1c1e5 (patch) | |
| tree | 8eef0366eb6a2a0112678cd01a54eadf5d2117e5 /lib/gemfeed.source.sh | |
| parent | 8a5d508dbce091d84b67902694e718f1c15cdbd1 (diff) | |
add word count to gemfeed
Diffstat (limited to 'lib/gemfeed.source.sh')
| -rw-r--r-- | lib/gemfeed.source.sh | 16 |
1 files changed, 13 insertions, 3 deletions
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" |
