" +gsl_html_par_o2="
" +gsl_html_par_o3="
" +gsl_html_par_c="
" + +while read -r "gsl_content_line_nbr" "gsl_content_line" +do +case "$gsl_content_line" in + ")") + sed -i "${gsl_content_line_nbr}s,.*,$gsl_html_par_c," \ + "$gsl_uri_tmp_post" + ;; + "("|"( 1") + sed -i "${gsl_content_line_nbr}s,.*,$gsl_html_par_o1," \ + "$gsl_uri_tmp_post" + ;; + "( 2") + sed -i "${gsl_content_line_nbr}s,.*,$gsl_html_par_o2," \ + "$gsl_uri_tmp_post" + ;; + "( 3") + sed -i "${gsl_content_line_nbr}s,.*,$gsl_html_par_o3," \ + "$gsl_uri_tmp_post" + ;; + *) + continue + ;; +esac +done < <(cat -n "$gsl_uri_tmp_post") +} + #======================================================================= # Replace gsl_mark_code #======================================================================= -gsl__post_maker_bcode() { +gsl__make_bcode() { # Get mark line nbr gsl_line_nbr=` @@ -146,36 +285,47 @@ gsl_file_tmp_code=`mktemp` # Set gsl_post_header_field_1 gsl_post_header_field_2 gsl__get_header_fields "$gsl_marker_code" +# Create tmp file from block-code, adding span to get number lines in css +gsl_file_bcode=`mktemp` +while read -r "gsl_bcode_line" +do + echo "$gsl_bcode_line" >> "$gsl_file_bcode" +done < <(cat "$gsl_dir_domain_files/$gsl_post_header_field_2") + printf '%s %s\n%b\n%s\n' \ "" \ - "$(cat -n "$gsl_dir_domain_files/$gsl_post_header_field_2")" \ + "$(cat "$gsl_file_bcode")" \ "" \ > "$gsl_file_tmp_code" sed -i "${gsl_line_nbr}r $gsl_file_tmp_code" "$gsl_uri_tmp_post" sed -i "${gsl_line_nbr}d" "$gsl_uri_tmp_post" rm -f "$gsl_file_tmp_code" +rm -f "$gsl_file_bcode" } +#----------------------------------------------------------------------- +# #======================================================================= -# Convert & replace this blockquote +# Replace and Convert this blockquote #======================================================================= -gsl__post_maker_cite() { -echo "Block: $gsl_cite_line_start > $gsl_cite_line_stop" +gsl__make_cite() { -# Put Blockquote in a file and get DATAS -gsl_file_tmp_cite=`mktemp` -# Put Blockquote CONTENT only in this file -gsl_file_tmp_cite_content=`mktemp` -# Put HTML blockquote in this file -gsl_file_tmp_cite_html=`mktemp` +gsl_file_tmp_cite=`mktemp` # File to Put whole Blockquote +gsl_file_tmp_cite_content=`mktemp` # File to Put Blockquote CONTENT only +gsl_file_tmp_cite_html=`mktemp` # File to Put final HTML blockquote +# Put whole blockquote in file awk -v o="$gsl_cite_line_start" -v c="$gsl_cite_line_stop" \ 'NR >= o && NR <= c' \ "$gsl_uri_tmp_post" \ > "$gsl_file_tmp_cite" +# No more DATAS needed for next if any +unset ${!gsl_bq_@} ${!gsl_html_cite_@} + +# Get DATAS from blockquote while read -r "gsl_content_line" do case "$gsl_content_line" in @@ -190,53 +340,46 @@ do ;; _lang*) gsl_bq_lang=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` + gsl_html_cite_lang=" lang=\"$gsl_bq_lang\"" ;; _year*) gsl_bq_year=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` ;; _link*) gsl_bq_link=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` + gsl_html_cite_link=" cite=\"$gsl_bq_link\"" ;; *) - echo " $gsl_content_line" >> "$gsl_file_tmp_cite_content" + [[ "$gsl_bq_author" ]] \ + && echo " $gsl_content_line" >> "$gsl_file_tmp_cite_content" \ + || echo " $gsl_content_line" >> "$gsl_file_tmp_cite_content" ;; esac done < <(cat "$gsl_file_tmp_cite") -#echo "D> Auteur: $gsl_bq_author" -#echo "D> Book : $gsl_bq_book" -#echo "D> lang : $gsl_bq_lang" -#echo "D> year : $gsl_bq_year" -#echo "D> link : $gsl_bq_link" -rm -f "$gsl_file_tmp_cite" +[[ "$gsl_bq_book" ]] \ + && gsl_bq_ref=" - $gsl_bq_book" -# Convert DATAS and put HTML code in a file -gsl_file_tmp_cite=`mktemp` -if [[ "$gsl_bq_author" ]];then - gsl_css_class="class=\"${gsl_site_css}_quote\"" - -# In a function... -[[ "$gsl_bq_lang" ]] \ - && gsl_html_cite_lang=" lang=\"$gsl_bq_lang\"" +[[ "$gsl_bq_year" ]] \ + && gsl_bq_ref+=" ($gsl_bq_year)" -[[ "$gsl_bq_link" ]] \ - && gsl_html_cite_link=" cite=\"$gsl_bq_link\"" - -cat << EOCITE > "$gsl_file_tmp_cite_html" - -EOCITE +[[ "$gsl_bq_book" ]] \ + && gsl_html_cite_book=" title=\"Book:$gsl_bq_ref\"" -# Insert blockquote file +! [[ "$gsl_bq_link" ]] && [[ "$gsl_bq_book" ]] \ + && gsl_html_cite_link=" cite=\"$gsl_bq_book$gsl_bq_year\"" + +rm -f "$gsl_file_tmp_cite" # No more whole blockquote file needed +gsl_file_tmp_cite=`mktemp` # File to put Converted HTML DATAS + +# Advanced or simple blockquote +[[ "$gsl_bq_author" ]] \ + && gsl__make_cite_advanced \ + || gsl__make_cite_simple + +# Insert html blockquote file in Post sed -i "${gsl_cite_line_stop}r $gsl_file_tmp_cite_html" "$gsl_uri_tmp_post" + # Remove useless lines gsl_cite_total_lines=$(( $gsl_cite_line_stop - gsl_cite_line_start )) for i in `seq 0 $gsl_cite_total_lines` @@ -244,15 +387,41 @@ do sed -i "${gsl_cite_line_start}d" "$gsl_uri_tmp_post" done -# No more BLOCKQUOTE CONTENT needed -rm -f "$gsl_file_tmp_cite_content" - -# No more html blockquote file needed -rm -f "$gsl_file_tmp_cite_html" -else - gsl_css_class="${gsl_site_css}_simple-quote" -fi - -# No more DATAS needed for next if any -unset ${!gsl_bq_@} +rm -f "$gsl_file_tmp_cite_content" # No more blockquote CONTENT needed +rm -f "$gsl_file_tmp_cite_html" # No more html blockquote file needed } + +#======================================================================= +# from gsl__post_maker_cite : ADVANCED blockquote +#======================================================================= +gsl__make_cite_advanced() { +gsl_css_class="class=\"${gsl_site_css}_quote\"" + +cat << EOCITE > "$gsl_file_tmp_cite_html" + +EOCITE +} + +#======================================================================= +# from gsl__post_maker_cite : SIMPLE blockquote +#======================================================================= +gsl__make_cite_simple() { +gsl_css_class="${gsl_site_css}_simple-quote" + +cat << EOCITE > "$gsl_file_tmp_cite_html" +
+$(cat "$gsl_file_tmp_cite_content") ++EOCITE +} +# +#----------------------------------------------------------------------- diff --git a/var/lib/gsl/scripts/gsl__post_manager b/var/lib/gsl/scripts/gsl__post_manager index 7d657f2..709619a 100644 --- a/var/lib/gsl/scripts/gsl__post_manager +++ b/var/lib/gsl/scripts/gsl__post_manager @@ -4,28 +4,11 @@ # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 -#======================================================================= -# Check NAME post from [OPT] ; should be from autocompletion -#======================================================================= -gsl__check_opt_post() { -[[ `ls -1 *.gsl | grep "$1"` ]] \ - && gsl_this_post="$1" -} - -#======================================================================= -# Check if posts from PWD folder -#======================================================================= -gsl__check_nbr_posts() { -gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l` - -! (( $gsl_nbr_posts >= 1 )) \ - && echo "! No Posts found with .gsl extension" \ - && exit 1 -} - -#======================================================================= -# Read from Post list -#======================================================================= +#----------------------------------------------------------------------- +# ----------------------------------------------------------- +# MAIN LOOP. Read from Post list. Do according to Post Status +# ----------------------------------------------------------- +#----------------------------------------------------------------------- gsl__loop_posts() { gsl__logs_print \ "$gsl_log_i" \ @@ -53,6 +36,7 @@ do continue fi + # From COMMAND [OPT] case "$1" in check) if ! [[ "$gsl_force_check" ]];then @@ -66,7 +50,7 @@ do "$gsl_post" \ "${PWD}" gsl_process="Checked" - gsl__post_all_checkers + gsl__all_checkers ;; make) @@ -75,7 +59,7 @@ do case "$gsl_db_post_status" in Checked) gsl__post_compare_hash || continue - gsl__post_all_makers + gsl__all_makers ;; Made) @@ -102,13 +86,29 @@ done && echo "# Check already done" } +#----------------------------------------------------------------------- +# -------------------- +# Doing some checkings +# -------------------- +#----------------------------------------------------------------------- + #======================================================================= -# Get Post Hash +# Check NAME post from [OPT] ; should be from autocompletion #======================================================================= -gsl__post_hash_size() { -gsl_post_csum=`cksum "$gsl_post"` -gsl_post_hash=`awk '{print $1}' <<< "$gsl_post_csum"` -gsl_post_size=`awk '{print $2}' <<< "$gsl_post_csum"` +gsl__check_opt_post() { +[[ `ls -1 *.gsl | grep "$1"` ]] \ + && gsl_this_post="$1" +} + +#======================================================================= +# Check if posts from PWD folder +#======================================================================= +gsl__check_nbr_posts() { +gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l` + +! (( $gsl_nbr_posts >= 1 )) \ + && echo "! No Posts found with .gsl extension" \ + && exit 1 } #======================================================================= @@ -158,13 +158,12 @@ case "$gsl_process" in if ! [[ "$gsl_db_file_hash" == "$gsl_file_hash" ]];then gsl__logs_print \ - "$gsl_log_e" \ + "$gsl_log_w" \ "File" \ "Hash" \ "$gsl_content_filename has changed. $gsl_db_file_hash $gsl_file_hash" \ "$gsl_file_db_files" - unset gsl_check_done - gsl_checker_err=true + gsl_checker_war=true return 1 fi done < <(grep "$gsl_post" "$gsl_file_db_posts" \ @@ -174,118 +173,6 @@ case "$gsl_process" in esac } -#----------------------------------------------------------------------- -# -# TOOLS. Getting line, markers, fields in headers... -# -#----------------------------------------------------------------------- -#======================================================================= -# Get line nbr from Post... $1: TERM | $2: File -#======================================================================= -gsl__get_line() { -awk -v s="$1" \ - 'match($0,s) {print NR}' \ - "$2" -} - -#======================================================================= -# Get everything after the marker... $1: marker | $2: File -#======================================================================= -gsl__get_header() { -awk -F"$1" -v marker="$1" -v l="$gsl_post_begin" \ - 'NR < l && $0 ~ marker {print $2}' \ - "$2" 2>/dev/null -} - -#======================================================================= -# Get fields from variable... $1: field | $2: variable -#======================================================================= -gsl__get_header_field() { -awk -F" : " -v f="$1" \ - 'NFS=f {print $NFS}' \ - <<< "$2" -} - -#======================================================================= -# Get line nbr from CONTENT Post... $1: TERM | $2: File -#======================================================================= -gsl__get_content_line() { -awk -v line="$gsl_post_begin" -v s="$1" \ - 'NR >= line && $0 ~ s {print NR}' \ - "$2" || return -} - -#======================================================================= -# Check CONTENT Post with markers... $1: Open Marker | $2: Close Marker -#======================================================================= -gsl__get_content_with_markers() { -gsl__get_content_finder \ - -o "$1" \ - -b "$gsl_post_header_field_1" \ - -c "$2" \ - -f "$gsl_post" \ - | tail -1 \ - || return -} - -#======================================================================= -# Get CONTENT with marks | ! find from ONE line content -#======================================================================= -gsl__get_content_finder() { -# Get [OPTs] -while (( "$#" )) - do - case "$1" in - -o) mk_o="$2" ;; # Open marker - -c) mk_c="$2" ;; # Close Marker - -b) mk_b="$2" ;; # Between markers - -f) file="$2" ;; # In whole file - -v) ivar="$2" ;; # In variable - -n) line="n" ;; # Give found line number - esac - shift -done - -! [[ "$file" ]] && ! [[ "$ivar" ]] && return 1 -! [[ "$mk_o" ]] && ! [[ "$mk_c" ]] && return 1 -! [[ "$mk_b" ]] && mk_b='.*' - -if [[ "$file" ]];then - grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" "$file" && return -elif [[ "$ivar" ]];then - grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" <<< "$ivar" && return -fi -} - -#======================================================================= -# Check & get NEEDED HEADERS | $1 VAR CONTENT $2 LOG Proc $3 LOG Act -#======================================================================= -gsl__check_needed_headers() { -! [[ "$1" ]] \ - && gsl__logs_print \ - "$gsl_log_e" \ - "Post" \ - "Header $2" \ - "Missing: POST TITLE" \ - "${PWD}/$gsl_post" \ - && gsl_checker_err=true -} - - -#======================================================================= -# Get Fields and line nbr from header from marker -#======================================================================= -gsl__get_header_fields() { -gsl_post_header_field_1=` -gsl__get_header_field 1 "$gsl_header_content_line"` -gsl_post_header_field_2=` -gsl__get_header_field 2 "$gsl_header_content_line"` -gsl_post_header_field_3=` -gsl__get_header_field 3 "$gsl_header_content_line"` -gsl_post_header_line_nbr=` -gsl__get_line "$1$gsl_post_header_field_1" "$gsl_post"` -} - #======================================================================= # Check NEEDED Fields from HEADER #======================================================================= @@ -331,3 +218,125 @@ if ! [[ "$gsl_post_header_field_3" ]];then esac fi } + +#----------------------------------------------------------------------- +# -------------- +# Tools for Post +# -------------- +#----------------------------------------------------------------------- + +#======================================================================= +# Get Post Hash +#======================================================================= +gsl__post_hash_size() { +gsl_post_csum=`cksum "$gsl_post"` +gsl_post_hash=`awk '{print $1}' <<< "$gsl_post_csum"` +gsl_post_size=`awk '{print $2}' <<< "$gsl_post_csum"` +} + +#======================================================================= +# Get line nbr from Post... $1: TERM | $2: File +#======================================================================= +gsl__get_line() { +awk -v s="$1" \ + 'match($0,s) {print NR}' \ + "$2" +} + +#======================================================================= +# Get everything after the marker... $1: marker | $2: File +#======================================================================= +gsl__get_header() { +awk -F"$1" -v marker="$1" -v l="$gsl_post_begin" \ + 'NR < l && $0 ~ marker {print $2}' \ + "$2" 2>/dev/null +} + +#======================================================================= +# Get fields from variable... $1: field | $2: variable +#======================================================================= +gsl__get_header_field() { +awk -F" : " -v f="$1" \ + 'NFS=f {print $NFS}' \ + <<< "$2" +} + +#======================================================================= +# Get line nbr from CONTENT Post... $1: TERM | $2: File +#======================================================================= +gsl__get_content_line() { +awk -v line="$gsl_post_begin" -v s="$1" \ + 'NR >= line && $0 ~ s {print NR}' \ + "$2" || return +} + +#======================================================================= +# Get CONTENT Post with markers... $1: Open Marker | $2: Close Marker +#======================================================================= +gsl__get_content_with_markers() { +gsl__get_content_finder \ + -o "$1" \ + -b "$gsl_post_header_field_1" \ + -c "$2" \ + -f "$gsl_post" \ + | tail -1 \ + || return +} + +#======================================================================= +# Get CONTENT with marks | ! find from ONE line content +#======================================================================= +gsl__get_content_finder() { +# Get [OPTs] +while (( "$#" )) + do + case "$1" in + -o) mk_o="$2" ;; # Open marker + -c) mk_c="$2" ;; # Close Marker + -b) mk_b="$2" ;; # Between markers + -f) file="$2" ;; # In whole file + -v) ivar="$2" ;; # In variable + -n) line="n" ;; # Give found line number + esac + shift +done + +! [[ "$file" ]] && ! [[ "$ivar" ]] && return 1 +! [[ "$mk_o" ]] && ! [[ "$mk_c" ]] && return 1 +! [[ "$mk_b" ]] && mk_b='.*' + +if [[ "$file" ]];then + grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" "$file" && return +elif [[ "$ivar" ]];then + grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" <<< "$ivar" && return +fi +} + +#======================================================================= +# Get NEEDED HEADERS | $1 VAR CONTENT $2 LOG Proc $3 LOG Act +#======================================================================= +gsl__check_needed_headers() { +! [[ "$1" ]] \ + && gsl__logs_print \ + "$gsl_log_e" \ + "Post" \ + "Header $2" \ + "Missing: POST TITLE" \ + "${PWD}/$gsl_post" \ + && gsl_checker_err=true +} + + +#======================================================================= +# Get Fields and line nbr from header from marker +#======================================================================= +gsl__get_header_fields() { +gsl_post_header_field_1=` +gsl__get_header_field 1 "$gsl_header_content_line"` +gsl_post_header_field_2=` +gsl__get_header_field 2 "$gsl_header_content_line"` +gsl_post_header_field_3=` +gsl__get_header_field 3 "$gsl_header_content_line"` +gsl_post_header_line_nbr=` +gsl__get_line "$1$gsl_post_header_field_1" "$gsl_post"` +}