diff --git a/help/help b/help/help index 2a7726f..4aff942 100644 --- a/help/help +++ b/help/help @@ -34,7 +34,11 @@ add : Create sidebar, add/replace (ARTICLE) at (POSITION) create : (alone argument), (re)Create whole sidebar - sync : Create RSS feed and sync folders from wip to www + stats : Manually generate stats (for statoolinfos) + ! useless with sync argument. + ! Works only for "server" install for now + + sync : Create RSS feed, Stats and sync folders from wip to www rss : Create RSS feed in wip folder log : (Multi-arguments) diff --git a/usr/local/bin/stl b/usr/local/bin/stl index 17dcbe7..b8c2162 100755 --- a/usr/local/bin/stl +++ b/usr/local/bin/stl @@ -103,6 +103,7 @@ case "$1" in edit) edit__OPTIONS "$@" ;; # manage__articles log) log__OPTIONS "$@" ;; # manage__articles db) db__OPTIONS "$@" ;; # manage__db + stats) stats__OPTIONS ;; # manage__stats *) noarg "$1" ;; esac diff --git a/var/lib/stl/help/help b/var/lib/stl/help/help index 2a7726f..4aff942 100644 --- a/var/lib/stl/help/help +++ b/var/lib/stl/help/help @@ -34,7 +34,11 @@ add : Create sidebar, add/replace (ARTICLE) at (POSITION) create : (alone argument), (re)Create whole sidebar - sync : Create RSS feed and sync folders from wip to www + stats : Manually generate stats (for statoolinfos) + ! useless with sync argument. + ! Works only for "server" install for now + + sync : Create RSS feed, Stats and sync folders from wip to www rss : Create RSS feed in wip folder log : (Multi-arguments) diff --git a/var/lib/stl/scripts/check__article b/var/lib/stl/scripts/check__article index 7865583..bb38e3a 100644 --- a/var/lib/stl/scripts/check__article +++ b/var/lib/stl/scripts/check__article @@ -80,6 +80,9 @@ check__dels "$article_tmp_post" ! [[ $stl_error ]] \ && log__add -i -C -A "Content Ok" +# Statistics ; manage__stats +stats__words "$article_tmp_post" + # If no error, write to db db__print @@ -163,6 +166,7 @@ get__content_metas "^abbr: " "$1" check ! [[ $stl_error ]] \ && log__add -i -C -M "Optional Metas Ok" + } @@ -192,6 +196,8 @@ if ! [[ `grep "_$header_f1" "$article_tmp_post"` ]];then "Line $ln. No content: '_$header_f1'" return fi + +((stat_links++)) } diff --git a/var/lib/stl/scripts/manage__HTML b/var/lib/stl/scripts/manage__HTML index d0c3c2e..b9752fe 100644 --- a/var/lib/stl/scripts/manage__HTML +++ b/var/lib/stl/scripts/manage__HTML @@ -256,11 +256,20 @@ domain__get && return create__RSS_feed -rsync -a --exclude ".*" "$domain_dir_wip/" "$domain_dir_www/" # Create www hash status in DB db__get_wip_articles "set_www_hash" # manage__db +# Statistics +if [[ $domain_stats == "yes" ]];then + stats__init + db__get_wip_articles "stats" + stats__statoolinfos +fi + +# Sync wip to www +rsync -a --exclude ".*" "$domain_dir_wip/" "$domain_dir_www/" + # Log this_article="$domain_dir_www" log__add -i -M WWW "Synced WIP server to WWW server" diff --git a/var/lib/stl/scripts/manage__db b/var/lib/stl/scripts/manage__db index d11e08f..65b4842 100644 --- a/var/lib/stl/scripts/manage__db +++ b/var/lib/stl/scripts/manage__db @@ -117,8 +117,10 @@ $( ) # Statistics +article_words=$article_words article_titles=$stat_titles article_paragraphs=$stat_paragraphs +article_links=$stat_links article_quotes=$stat_quotes article_lists=$stat_lists article_bolds=$article_bolds @@ -189,6 +191,7 @@ rm -f "$db_rmp_list" exit } + #====================================================================== # Get articles from database, with wip status # Generic function to : @@ -199,24 +202,54 @@ exit db__get_wip_articles() { while IFS=: read -r 'file' 'article_wip' do - echo "> $article_wip" - [[ `awk -F= '{print $2}' <<<"$article_wip"` -gt 0 ]] \ - || continue - + [[ `awk -F= '{print $2}' <<<"$article_wip"` -gt 0 ]] || continue + source "$file" - - # From sync_wip_to_www() ; manage__HTML + case "$1" in + # From sync_wip_to_www() ; manage__HTML set_www_hash) if ! [[ $article_www_hash == $article_wip_hash ]];then - sed -i "s^article_www_hash=.*^article_www_hash=$article_wip_hash^" "$file" - + sed -i "s^article_www_hash=.*^article_www_hash=$article_wip_hash^" \ + "$file" + # Log this_article="$domain_dir_www$article_uri_srv" log__add -i -W -A "Added online: $article_title" fi ;; + + # Generate statistics + stats) + case "$stl_install" in + server) + [[ $article_www_hash -gt 0 ]] || continue + + ((stat_articles_www++)) + article_words_www=$((article_words + article_words_www)) + article_titles_www=$((article_titles + article_titles_www)) + article_paragraphs_www=$((article_paragraphs + article_paragraphs_www)) + article_links_www=$(( article_links + article_links_www)) + article_quotes_www=$((article_quotes + article_quotes_www)) + article_lists_www=$((article_lists + article_lists_www)) + article_bolds_www=$((article_bolds + article_bolds_www)) + article_strongs_www=$((article_strongs + article_strongs_www)) + article_emphasis_www=$((article_emphasis + article_emphasis_www)) + article_icodes_www=$((article_icodes+ article_icodes_www)) + article_cross_www=$((article_cross + article_cross_www)) + article_dels_www=$((article_dels + article_dels_www)) + files_images_www=$((files_images + files_images_www)) + files_links_www=$((files_links + files_links_www)) + files_codes_www=$((files_codes + files_codes_www)) + files_bruts_www=$((files_bruts + files_bruts_www)) + ;; + + local) + ((stat_articles_wip++)) + ;; + esac + ;; esac - + done < <(grep -H "article_wip_hash" "$domain_db_articles/"*.db) } diff --git a/var/lib/stl/scripts/manage__logs b/var/lib/stl/scripts/manage__logs index 9fc5334..762ac20 100644 --- a/var/lib/stl/scripts/manage__logs +++ b/var/lib/stl/scripts/manage__logs @@ -85,6 +85,7 @@ case "$3" in -Mlt) log_f3="link:" ;; -M) log_f3="Metas" ;; -A) log_f3="Article" ;; + -S) log_f3="Stats" ;; *) log_f3="$3" esac diff --git a/var/lib/stl/scripts/manage__stats b/var/lib/stl/scripts/manage__stats index adae360..9429f42 100644 --- a/var/lib/stl/scripts/manage__stats +++ b/var/lib/stl/scripts/manage__stats @@ -11,5 +11,109 @@ # Argument: stats #====================================================================== stats__OPTIONS() { -echo "! Working in progress" +domain__get + +# Init stats +stats__init + +db__get_wip_articles "stats" +stats__statoolinfos +} + + +#====================================================================== +# Stats initialization +#====================================================================== +stats__init() { +article_words_www=0 +article_titles_www=0 +article_paragraphs_www=0 +article_links_www=0 +article_quotes_www=0 +article_lists_www=0 +article_bolds_www=0 +article_strongs_www=0 +article_emphasis_www=0 +article_icodes_www=0 +article_cross_www=0 +article_dels_www=0 +files_images_www=0 +files_links_www=0 +files_codes_www= +files_bruts_www=0 +} + + +#====================================================================== +# Create stl.properties for statoolinfos +#====================================================================== +stats__statoolinfos() { +case "$stl_install" in + server) + cat < "$domain_dir_www/stl.properties" +stl.articles = $stat_articles_www + +stl.articles.titles = $article_titles_www +stl.articles.words = $article_words_www +stl.articles.paragraphs = $article_paragraphs_www +stl.articles.links = $article_links_www +stl.articles.bolds = $article_bolds_www +stl.articles.strongs = $article_strongs_www +stl.articles.emphasis = $article_emphasis_www +stl.articles.inlinecodes = $article_icodes_www +stl.articles.cross = $article_cross_www +stl.articles.dels = $article_dels_www +stl.articles.quotes = $article_quotes_www +stl.articles.lists = $article_lists_www + +# Files +stl.articles.filelinks = $files_links_www +stl.articles.images = $files_images_www +stl.articles.filecodes = $files_codes_www +stl.articles.filebruts = $files_bruts_www +EOSTATS + ;; +esac + +this_article="$domain_dir_www/stl.properties" +log__add -i -W -S "Statoolinfos file generated" +} + + +#====================================================================== +# Count words in article +# Called from checkers() ; check_article +# $1: $article_tmp_post +#====================================================================== +stats__words() { +article_words=`cat "$1" | wc -w` + +content_stats_images=`grep "_image:" "$1" | wc -l` +content_stats_fcodes=`grep "_code:" "$1" | wc -l` +content_stats_fbruts=`grep "_brut:" "$1" | wc -l` +content_stats_slists=`grep "<<" "$1" | wc -w` +content_stats_clists=`grep ">>" "$1" | wc -l` +content_stats_olists=`grep "^+" "$1" | wc -l` +content_stats_ulists=`grep "^=" "$1" | wc -l` +content_stats_commts=`grep "^# " "$1" | wc -w` +content_stats_titles=`grep "^#[1-6] " "$1" | wc -l` +content_stats_mquots=`grep "^---" "$1" | wc -l` +content_stats_oparas=`grep "^(" "$1" | wc -w` +content_stats_cparas=`grep "^)" "$1" | wc -l` + +article_words=\ +$(( article_words \ + - content_stats_images \ + - content_stats_fcodes \ + - content_stats_fbruts \ + - content_stats_slists \ + - content_stats_clists \ + - content_stats_olists \ + - content_stats_ulists \ + - content_stats_commts \ + - content_stats_titles \ + - content_stats_mquots \ + - content_stats_oparas \ + - content_stats_cparas +)) }