From 00d48233d05c65a74618260bf5bcb619c1cfa9ba Mon Sep 17 00:00:00 2001 From: Cyrille L Date: Fri, 15 Apr 2022 08:50:22 +0200 Subject: [PATCH] New sidebar argument ; readme ; help ; fix www --- README.md | 41 ++++- control | 2 +- usr/local/bin/gsl | 94 ++---------- var/lib/gsl/README.md | 41 ++++- var/lib/gsl/helps/gsl_help | 17 ++- var/lib/gsl/scripts/gsl__page_creator | 211 ++++++++------------------ var/lib/gsl/scripts/gsl__post_makers | 3 - var/lib/gsl/scripts/gsl__post_manager | 5 +- var/lib/gsl/scripts/gsl__sidebar | 141 +++++++++++++++++ 9 files changed, 295 insertions(+), 260 deletions(-) create mode 100644 var/lib/gsl/scripts/gsl__sidebar diff --git a/README.md b/README.md index 95837af..d732ff7 100644 --- a/README.md +++ b/README.md @@ -386,8 +386,8 @@ _book: Esperanza 64 ### Créer des listes -L'arborescence est "infinie". Chaque contenu de la liste -*doit être sur la même ligne* +L'arborescence est "infinie". +- Chaque contenu de la liste *doit être sur la même ligne* Dans l'article... - utilisez ```=``` pour définir l'arborescence d'une liste simple @@ -428,6 +428,26 @@ Retour "forcé" à la ligne ``` +# Comment gérer la sidebar +La gestion de la sidebar est manuelle. Un article doit être convertit +avec make avant de pouvoir l'ajouter à la position ddsirée. Le nombre +d'articles maximum dans la sidebar est configurable dans /etc/gsl/gsl.conf + +Quelques exemples d'utilisations + +``` +# Liste les articles de la sidebar dans l'ordre +gsl sidebar + +# Ajoute monarticle en position 1 +gsl -S add 1 monarticle + +# Enlève monarticle2 de la sidebar +gsl -S remove monarticle2 + +# monarticle5 est en position 3. Le replacer par monarticle4 +gsl -S -A 3 monarticle4 +``` # HELP COMMAND ``` @@ -465,12 +485,7 @@ $ gsl [ARG] make | -M [OPT] [FILE] : Convert Posts from PWD folder or [FILE] to HTML file in server -F : Force Make again - - post-list [OPT] [FILE] : Add post again from [FILE] to Last-Posts List - (When converting new post, it will be added) - Pin : Set Post from [FILE] to first in Last-Posts List - Add : Add Post from [FILE] to last in Last-Posts List - + www [OPT1] [OPT2] : Add/Remove Post from www server [OPT1]: add : Add all/[FILE] to www server @@ -479,6 +494,16 @@ $ gsl [ARG] all : Select all post with wip statuses [FILE] : Select specific post (if wip status) + + sidebar | -S [ARG] [FILE]: Show Posts in list + [ARG]: + add | -A : Must set a Position number before [FILE] + Max posts in list is set in gsl.conf + remove | -R : No Position to set, just [FILE]. + Replace post position if post not exists in list + add/remove will build last-posts-list.html + create | -C : rebuild last-posts-list.html + version | -v : Show local versionn -vv : Shown local and repo Versions ``` diff --git a/control b/control index 08ab10a..08c0aef 100644 --- a/control +++ b/control @@ -1,5 +1,5 @@ Package: egsl -Version: 0.0.23 +Version: 0.0.3 Section: custom Priority: optional Architecture: all diff --git a/usr/local/bin/gsl b/usr/local/bin/gsl index 05f9e46..d6419d6 100755 --- a/usr/local/bin/gsl +++ b/usr/local/bin/gsl @@ -1,5 +1,5 @@ #!/bin/bash -# Version: 0.0.23 +# Version: 0.0.3 # file: gsl # Folder: /usr/local/bin # By echolib @@ -369,91 +369,9 @@ case "$1" in "$PWD" ;; - post-list) - case "$2" in - add) - gsl_post_list="Add" - ;; - pin) - gsl_post_list="Pin" - ;; - *) - echo "! Bad Argument: $2" - exit - ;; - esac - - ! [[ "$3" ]] \ - && echo "! Missing argument: post [FILE]" \ - && exit - - gsl__if_file "$3" post - - gsl__check_nbr_posts - gsl__logs_print \ - "$gsl_log_i" \ - "Starting" \ - "Process" \ - "$1 ; $gsl_post_list $3 from domain $gsl_find_domain" \ - "$gsl_dir_domain_tpl/last-posts-list.html" - - gsl__loop_posts post-list - - gsl__logs_print \ - "$gsl_log_i" \ - "Stopping" \ - "Process" \ - "$1 ; $gsl_post_list $3 from domain $gsl_find_domain" \ - "$gsl_dir_domain_tpl/last-posts-list.html" - ;; - - list|-l) - case "$2" in - add|-A) gsl_listing_process="add" ;; - remove|-R) gsl_listing_process="remove" ;; - ""*) echo "! Bad argument: $2 ? OPT=add|-A/remove|-R";exit ;; - esac - - case "$3" in - 0*) - echo "! Are you serious ?" - exit - ;; - $(( $3 <= $gsl_list_max_posts))) - echo "> $3 is OK" - ;; - *) - echo "! Mysterious number" - exit - ;; - esac - - ! [[ "$4" ]] \ - && echo "! Set post [FILE]" \ - && exit - - gsl__if_file "$4" post - - gsl__logs_print \ - "$gsl_log_i" \ - "Starting" \ - "Process" \ - "$1 ; $2 ; $3 from domain $gsl_find_domain" \ - "$gsl_dir_domain_tpl/last-posts-list.html" - - gsl__loop_posts listing - - gsl__logs_print \ - "$gsl_log_i" \ - "Stopping" \ - "Process" \ - "$1 ; $2 ; $3 from domain $gsl_find_domain" \ - "$gsl_dir_domain_tpl/last-posts-list.html" - ;; - www) ! [[ "$2" ]] \ - && echo "! Missing argument: OPT=add/remove" \ + && echo "! Missing argument: add/remove" \ && exit if__command rsync @@ -488,7 +406,7 @@ case "$1" in ;; esac ;; - =) + *) gsl__if_file "$3" post ;; esac @@ -502,6 +420,7 @@ case "$1" in gsl_srv_www="$gsl_site_server/$gsl_site_ndd/www" gsl__srv_sync "$gsl_srv_www" + gsl__loop_posts www "$2" gsl__logs_print \ @@ -512,6 +431,11 @@ case "$1" in "$gsl_site_server" ;; + sidebar|-S) + gsl__if_file "$gsl_dir_scripts/gsl__sidebar" source + gsl__sidebar $1 $2 $3 $4 + ;; + *) gsl help exit diff --git a/var/lib/gsl/README.md b/var/lib/gsl/README.md index 95837af..d732ff7 100644 --- a/var/lib/gsl/README.md +++ b/var/lib/gsl/README.md @@ -386,8 +386,8 @@ _book: Esperanza 64 ### Créer des listes -L'arborescence est "infinie". Chaque contenu de la liste -*doit être sur la même ligne* +L'arborescence est "infinie". +- Chaque contenu de la liste *doit être sur la même ligne* Dans l'article... - utilisez ```=``` pour définir l'arborescence d'une liste simple @@ -428,6 +428,26 @@ Retour "forcé" à la ligne ``` +# Comment gérer la sidebar +La gestion de la sidebar est manuelle. Un article doit être convertit +avec make avant de pouvoir l'ajouter à la position ddsirée. Le nombre +d'articles maximum dans la sidebar est configurable dans /etc/gsl/gsl.conf + +Quelques exemples d'utilisations + +``` +# Liste les articles de la sidebar dans l'ordre +gsl sidebar + +# Ajoute monarticle en position 1 +gsl -S add 1 monarticle + +# Enlève monarticle2 de la sidebar +gsl -S remove monarticle2 + +# monarticle5 est en position 3. Le replacer par monarticle4 +gsl -S -A 3 monarticle4 +``` # HELP COMMAND ``` @@ -465,12 +485,7 @@ $ gsl [ARG] make | -M [OPT] [FILE] : Convert Posts from PWD folder or [FILE] to HTML file in server -F : Force Make again - - post-list [OPT] [FILE] : Add post again from [FILE] to Last-Posts List - (When converting new post, it will be added) - Pin : Set Post from [FILE] to first in Last-Posts List - Add : Add Post from [FILE] to last in Last-Posts List - + www [OPT1] [OPT2] : Add/Remove Post from www server [OPT1]: add : Add all/[FILE] to www server @@ -479,6 +494,16 @@ $ gsl [ARG] all : Select all post with wip statuses [FILE] : Select specific post (if wip status) + + sidebar | -S [ARG] [FILE]: Show Posts in list + [ARG]: + add | -A : Must set a Position number before [FILE] + Max posts in list is set in gsl.conf + remove | -R : No Position to set, just [FILE]. + Replace post position if post not exists in list + add/remove will build last-posts-list.html + create | -C : rebuild last-posts-list.html + version | -v : Show local versionn -vv : Shown local and repo Versions ``` diff --git a/var/lib/gsl/helps/gsl_help b/var/lib/gsl/helps/gsl_help index 5e81793..45d12eb 100644 --- a/var/lib/gsl/helps/gsl_help +++ b/var/lib/gsl/helps/gsl_help @@ -34,12 +34,7 @@ $ gsl [ARG] make | -M [OPT] [FILE] : Convert Posts from PWD folder or [FILE] to HTML file in server -F : Force Make again - - post-list [OPT] [FILE] : Add post again from [FILE] to Last-Posts List - (When converting new post, it will be added) - Pin : Set Post from [FILE] to first in Last-Posts List - Add : Add Post from [FILE] to last in Last-Posts List - + www [OPT1] [OPT2] : Add/Remove Post from www server [OPT1]: add : Add all/[FILE] to www server @@ -48,6 +43,16 @@ $ gsl [ARG] all : Select all post with wip statuses [FILE] : Select specific post (if wip status) + + sidebar | -S [ARG] [FILE]: Show Posts in list + [ARG]: + add | -A : Must set a Position number before [FILE] + Max posts in list is set in gsl.conf + remove | -R : No Position to set, just [FILE]. + Replace post position if post not exists in list + add/remove will build last-posts-list.html + create | -C : rebuild last-posts-list.html + version | -v : Show local versionn -vv : Shown local and repo Versions diff --git a/var/lib/gsl/scripts/gsl__page_creator b/var/lib/gsl/scripts/gsl__page_creator index 7e85e19..bf92ddb 100644 --- a/var/lib/gsl/scripts/gsl__page_creator +++ b/var/lib/gsl/scripts/gsl__page_creator @@ -56,14 +56,14 @@ case "$gsl_post_type" in gsl_srv_www_page="$gsl_srv_www/$gsl_header_slug/index.html" gsl__check_srv_files "$gsl_srv_wip_page" wip gsl__check_srv_files "$gsl_srv_www_page" www - #gsl_uri=".." + gsl_uri=".." ;; page) gsl_srv_wip_page="$gsl_srv_wip/$gsl_header_slug.html" gsl_srv_www_page="$gsl_srv_www/$gsl_header_slug.html" gsl__check_srv_files "$gsl_srv_wip_page" wip gsl__check_srv_files "$gsl_srv_www_page" www - #gsl_uri="." + gsl_uri="." ;; esac @@ -81,6 +81,7 @@ if [[ -f "$1" ]];then "$2" \ "$gsl_post_type $gsl_post exists" \ "$1" + else gsl__logs_print \ "$gsl_log_w" \ @@ -92,145 +93,6 @@ else fi } -#====================================================================== -# latest Posts listing Manager -#====================================================================== -gsl__page_listing_create() { -# Check if Post is in list ; Status Made -gsl_checker_war=true -gsl_listing_file="$gsl_dir_domain_listings/$gsl_post.list" - -if [[ `ls -1 "$gsl_listing_file"* 2>/dev/null` ]];then - gsl__logs_print \ - "$gsl_log_w" \ - "Post" \ - "Latest" \ - "$gsl_post_list $gsl_post ; already added to Listing" \ - "$gsl_dir_domain_listings/" - return -fi - -case "$gsl_post_list" in - Pin) - gsl_listing_start_n=1 - [[ $gsl_post_pin ]] \ - && sed -i "s|gsl_post_pin.*|gsl_post_pin=$gsl_header_title|" \ - "$gsl_this_conf_domain/$gsl_find_domain.conf" \ - || echo "gsl_post_pin=$gsl_header_title" \ - >> "$gsl_this_conf_domain/$gsl_find_domain.conf" - ;; - Add) - # Check if a post is pinned - [[ $gsl_post_pin ]] \ - && gsl_listing_start_n=2 \ - || gsl_listing_start_n=1 - ;; -esac - -gsl__page_listing_roller -gsl__page_listing_create_file "$gsl_listing_file.$gsl_listing_start_n" - -cat `ls -1r "$gsl_dir_domain_listings/"*.list.*` \ - > "$gsl_dir_domain_tpl/last-posts-list.html" \ - && gsl__logs_print \ - "$gsl_log_w" \ - "Post" \ - "Latest" \ - "Create Listing (Merged .list.*)"\ - "$gsl_dir_domain_tpl/last-post-list.html" -} - -#====================================================================== -# Create HTML List from selected Post -#====================================================================== -gsl__page_listing_create_file() { -# Set HTML Base Link -case "$gsl_post_type" in - post) gsl_bpost_url="$gsl_header_slug/index.html" ;; - page) gsl_bpost_url="$gsl_header_slug.html" ;; -esac - -cat << EOPostSide > "$1" -
  • - $gsl_header_title - - -
  • -EOPostSide - -gsl__logs_print \ - "$gsl_log_w" \ - "Post" \ - "Latest" \ - "$gsl_post_list $gsl_post to Listing" \ - "$1" -} - -#====================================================================== -# latest Posts listing Rolling -#====================================================================== -gsl__page_listing_roller() { - - gsl__page_listing_file_mv() { - for n in `seq $gsl_listing_start_n $(( gsl_listing_last_n )) | sort -r` - do - gsl_listing_this_post=`ls -1 "$gsl_dir_domain_listings/"*".list.$n"` - gsl_listing_tmp_no_n=`echo ${gsl_listing_this_post%.*}` - gsl_listing_new_post="$gsl_listing_tmp_no_n.$(( n + 1 ))" - - mv "$gsl_listing_this_post" \ - "$gsl_listing_new_post" - done - gsl__logs_print \ - "$gsl_log_w" \ - "Post" \ - "Latest" \ - "Roll from Listing" \ - "$gsl_dir_domain_listings/*.list.*" - } - -# search for last listing number -gsl_listing_last=` -ls -1 "$gsl_dir_domain_listings/"*".list."* 2>/dev/null \ - | tail -1` - -if [[ $gsl_listing_last ]];then - - # A Post is Pinned - if [[ $gsl_post_pin ]];then - gsl__logs_print \ - "$gsl_log_w" \ - "Post" \ - "Latest" \ - "Remove Pin $gsl_listing_rm_post_name from Listing" \ - "$gsl_listing_rm_post_uri" - fi - - # Get Last listing number - gsl_listing_last_n=${gsl_listing_last: -1} - # Remove last file - if (( $gsl_listing_last_n == $gsl_list_max_posts ));then - gsl_listing_rm_post_uri=` - ls -1 "$gsl_dir_domain_listings/"*".list.$gsl_list_max_posts"` - gsl_listing_rm_post_name=` - basename "$gsl_listing_rm_post_uri" | awk -F"." '{print $1"."$2}'` - - rm -f "$gsl_dir_domain_listings/"*".list.$gsl_list_max_posts" && \ - gsl__logs_print \ - "$gsl_log_w" \ - "Post" \ - "Latest" \ - "Remove $gsl_listing_rm_post_name from Listing" \ - "$gsl_listing_rm_post_uri" - gsl_listing_last_n=4 - fi - - # Roll each ones + 1 - gsl__page_listing_file_mv - -fi -} - #---------------------------------------------------------------------- # Create Final HTML Post/Page #---------------------------------------------------------------------- @@ -357,7 +219,6 @@ EOFOOTER # Check for files in templates folder #----------------------------------------------------------------------- gsl__check_templates() { -#echo "D> $gsl_dir_domain_tpl" # Create generic HEADER if not exists ! [[ "$gsl_dir_domain_tpl/header.html" ]] \ && gsl__html_header @@ -368,10 +229,68 @@ gsl__check_templates() { } #====================================================================== -# latest Posts listing Manager +# Sidebar Posts list Manager | $1=Process | $2=Position | $3=Post #====================================================================== gsl__page_sidebar() { -gsl_listing_file="$gsl_dir_domain_listings/$gsl_post.list" -echo "> $gsl_listing_file" -ls -1 "$gsl_dir_domain_listings" +gsl_post="$gsl_this_post" +gsl__post_begin +gsl__get_needed_headers +gsl__page_prepare_datas + +if [[ -f "$gsl_srv_wip_page" ]] || + [[ -f "$gsl_srv_www_page" ]];then + gsl__logs_print \ + "$gsl_log_i" \ + "Sidebar" \ + "$gsl_listing_process" \ + "to list, position $2 ; $3 from domain $gsl_find_domain" \ + "$gsl_listing_file.$2" +else + gsl__logs_print \ + "$gsl_log_i" \ + "Sidebar" \ + "$gsl_listing_process" \ + "make $3 from domain $gsl_find_domain first" \ + "$gsl_dir_domain_listings/" + return +fi + +case "$gsl_post_type" in + post) gsl_bpost_url="$gsl_header_slug/index.html" ;; + page) gsl_bpost_url="$gsl_header_slug.html" ;; +esac + +touch "$gsl_listing_file.$2" +cat << EOPostSide > "$gsl_listing_file.$2" +
  • + $gsl_header_title + + +
  • +EOPostSide + +gsl__page_sidebar_create +} + +#====================================================================== +# Sidebar Create from list in X-tra to file last-posts-list.html +#====================================================================== +gsl__page_sidebar_create() { +[[ -f "$gsl_dir_domain_tpl/last-posts-list.html" ]] \ + && rm -f "$gsl_dir_domain_tpl/last-posts-list.html" + +touch "$gsl_dir_domain_tpl/last-posts-list.html" && \ +gsl__logs_print \ + "$gsl_log_w" \ + "Sidebar" \ + "Create" \ + "Build new list" \ + "$gsl_dir_domain_tpl/last-posts-list.html" + +gsl_checker_war=true +while read -r "postroller" +do + cat "$gsl_dir_domain_listings/$postroller" \ + >> "$gsl_dir_domain_tpl/last-posts-list.html" +done < <(ls -1 "$gsl_dir_domain_listings/" | sort -r) } diff --git a/var/lib/gsl/scripts/gsl__post_makers b/var/lib/gsl/scripts/gsl__post_makers index 10c925d..4b68609 100644 --- a/var/lib/gsl/scripts/gsl__post_makers +++ b/var/lib/gsl/scripts/gsl__post_makers @@ -26,9 +26,6 @@ case "$gsl_post_type" in page) gsl_uri="." ;; esac -# Create Listng Page -gsl__page_listing_create Add - gsl__do_italics "make" "$gsl_tmp_post" # First gsl__do_header "make" "$gsl_marker_link" "$gsl_post" gsl__do_header "make" "$gsl_marker_abbr" "$gsl_post" diff --git a/var/lib/gsl/scripts/gsl__post_manager b/var/lib/gsl/scripts/gsl__post_manager index f63cba9..1d10583 100644 --- a/var/lib/gsl/scripts/gsl__post_manager +++ b/var/lib/gsl/scripts/gsl__post_manager @@ -141,12 +141,11 @@ do case "$gsl_listing_process" in add) - echo "> Add $gsl_this_post to listing" gsl__page_sidebar ;; - rem) - echo "> Remove $gsl_this_post to listing" + remove) + gsl__page_sidebar ;; esac ;; diff --git a/var/lib/gsl/scripts/gsl__sidebar b/var/lib/gsl/scripts/gsl__sidebar new file mode 100644 index 0000000..f9b1bc0 --- /dev/null +++ b/var/lib/gsl/scripts/gsl__sidebar @@ -0,0 +1,141 @@ +#!/bin/bash +# file: gsl__sidebar +# Folder: /var/lib/gsl/scripts +# By echolib +# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 + +#====================================================================== +# Sidebar Manager | $1=call | $2=process | $3=POS/Post | $4=Post +#====================================================================== +gsl__sidebar() { +case "$2" in + "") + ls -1 "$gsl_dir_domain_listings" | sort -r + exit + ;; + + create|-C) + ! [[ `ls -1 "$gsl_dir_domain_listings"` ]] \ + && echo "! No post in list: $gsl_dir_domain_listings" \ + && exit + + gsl__page_sidebar_create + ;; + + add|-A) + # $2=process | $3=Position | $4=post + gsl_listing_process="add" + ! [[ "$3" ]] \ + && echo "! Set a number <= $gsl_list_max_posts ; see help" \ + && exit + + ! [[ `expr "x$3" : "x[0-9]*$"` -gt 0 ]] \ + && gsl__list_bad_arg nbr $3 + + ! (( $3 <= $gsl_list_max_posts )) \ + && gsl__list_bad_arg nbr $3 + + ! [[ "$4" ]] \ + && gsl__list_bad_arg file + + gsl__logs_print \ + "$gsl_log_i" \ + "Starting" \ + "Process" \ + "$1 ; $2 ; position $3 ; $4 from domain $gsl_find_domain" \ + "$gsl_dir_domain_tpl/last-posts-list.html" + + gsl__if_file "$4" post + gsl_listing_file="$gsl_dir_domain_listings/$4.list" + gsl_post_old_inlist=`ls -1 "$gsl_dir_domain_listings/" | grep ".list.$3"` + + if [[ `ls -1 "$gsl_listing_file"* 2>/dev/null` ]];then + # Post exists (maybe with different position) + gsl__logs_print \ + "$gsl_log_w" \ + "Sidebar" \ + "Post" \ + "$gsl_listing_process $4 ; already in list !" \ + "$gsl_dir_domain_listings/" + gsl_checker_war=true + + elif [[ "$gsl_post_old_inlist" ]];then + # Another post exists at this position. + # Remove and create new in roller + rm -f "$gsl_dir_domain_listings/$gsl_post_old_inlist" + gsl__logs_print \ + "$gsl_log_w" \ + "Sidebar" \ + "Post" \ + "$gsl_listing_process $4 ; replace $gsl_post_old_inlist !" \ + "$gsl_dir_domain_listings/$gsl_post_old_inlist" + gsl_checker_war=true + gsl__page_sidebar $2 $3 $4 + else + # Not gound in list, create for roller + gsl__page_sidebar $2 $3 $4 + fi + + gsl__logs_print \ + "$gsl_log_i" \ + "Stopping" \ + "Process" \ + "$1 ; $2 ; position $3 ; $4 from domain $gsl_find_domain" \ + "$gsl_dir_domain_tpl/last-posts-list.html" + ;; + + remove|-R) + gsl_listing_process="remove" + ! [[ "$3" ]] \ + && gsl__list_bad_arg file $3 + + gsl__if_file "$3" post + + gsl__logs_print \ + "$gsl_log_i" \ + "Starting" \ + "Process" \ + "$1 ; $2 ; $3 from domain $gsl_find_domain" \ + "$gsl_dir_domain_tpl/last-posts-list.html" + + gsl_post_rm_list=`ls -1 "$gsl_dir_domain_listings/" | grep "$3.list"` + rm -f "$gsl_dir_domain_listings/$gsl_post_rm_list" && \ + gsl__logs_print \ + "$gsl_log_w" \ + "Sidebar" \ + "$2" \ + "$3 from domain $gsl_find_domain in list" \ + "$gsl_dir_domain_listings/$gsl_post_rm_list" + gsl_checker_war=true + + gsl__page_sidebar_create + + gsl__logs_print \ + "$gsl_log_i" \ + "Stopping" \ + "Process" \ + "$1 ; $2 ; $3 from domain $gsl_find_domain" \ + "$gsl_dir_domain_tpl/last-posts-list.html" + ;; + + *) + echo "! Bad argument: add|-A/remove|-R" + exit + ;; +esac +} + +#====================================================================== +# Sidebar Return bad argument +#====================================================================== +gsl__list_bad_arg() { + case "$1" in + nbr) + echo "! $2 is not a number <= $gsl_list_max_posts ; see help" + ;; + file) + echo "! Set post [FILE]" + ;; + esac + exit +}