~cadence/bliz

e4313a379f1a178891bc44892423702ecc262e7a — Cadence Ember 11 months ago 0bfdc82
Add some of my functions to the default includes
1 files changed, 23 insertions(+), 2 deletions(-)

M src/script-includes.fish
M src/script-includes.fish => src/script-includes.fish +23 -2
@@ 1,5 1,26 @@
test -f personal/script-includes.fish; and source personal/script-includes.fish

function bliz_word_count
    sed -n '/^%%%/,/^%%%/d;/^% /d;p' $blizfile | wc -w
end

function bliz_hits
    set -l database_path personal/hits.db
    set -l safe_path (string escape --style=var -- $req_path)
    sqlite3 $database_path "\
        create table if not exists Hits (path TEXT, hits INTEGER, primary key (path)); \
        insert into Hits (path, hits) values ('$safe_path', 1) on conflict (path) do update set hits = hits + 1; \
        select hits from Hits where path = '$safe_path' \
        "
end

function gemlog_intro_meta
    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 "> First published on $published."
    echo "> This article has been loaded $hits times."
end

test -f personal/script-includes.fish; and source personal/script-includes.fish