~cadence/bliz

ref: 4a5ec63ec0db33d4070adeb3838f6192f282a48c bliz/src/script-includes.fish -rw-r--r-- 1.4 KiB
4a5ec63eCadence Ember Add paragraph count to gemlog intro 1 year, 11 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)
    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 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 -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

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