~cadence/bliz

4a5ec63ec0db33d4070adeb3838f6192f282a48c — Cadence Ember 2 years ago 7efd8ef
Add paragraph count to gemlog intro
1 files changed, 19 insertions(+), 1 deletions(-)

M src/script-includes.fish
M src/script-includes.fish => src/script-includes.fish +19 -1
@@ 2,6 2,18 @@ function bliz_word_count
    sed -n '/^%%%/,/^%%%/d;/^% /d;p' $blizfile | wc -w
end

function bliz_paragraph_count
    perl -00e '
        $count = 0;
        while (<>) {
            if ($_ =~ /^[^%#=]/) {
                $count++;
            }
        }
        print $count;
    ' $blizfile
end

function bliz_hits
    set -l database_path personal/hits.db
    set -l safe_path (string escape --style=var -- $req_path)


@@ 13,12 25,18 @@ function bliz_hits
end

function gemlog_intro_meta
    set -l paragraphs (bliz_paragraph_count)
    set -l words (bliz_word_count)
    set -l minutes (expr \( $words + 150 \) / 300)
    set -l hits (bliz_hits)
    set -l base (basename $blizfile)
    set -l published (string match -r -- '^(?:[0-9]+-){2}[0-9]+' $base)
    echo "> $words words, about $minutes minutes to read at a reasonable 300 wpm."
    echo -n "> $words words, $paragraphs paragraphs, about "
    if test $minutes -gt 1
         echo "$minutes minutes to read (300 wpm)."
    else
        echo "a minute to read."
    end
    echo "> First published on $published."
    echo "> This article has been loaded $hits times."
end