updates + converters

This commit is contained in:
Cyrille L 2022-02-21 17:25:08 +01:00
parent 18e42778fa
commit ee739a738e
4 changed files with 421 additions and 231 deletions

View File

@ -0,0 +1,4 @@
# Tips: what to (not) do
## Do NOT:
- put "^" in titles (#1-6)

View File

@ -4,18 +4,20 @@
# By echolib # By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================= #-----------------------------------------------------------------------
# From: gsl__loop_posts | Check Post from modules # --------------------------------------------------
#======================================================================= # From: gsl__loop_posts | MAIN checkers from modules
gsl__post_all_checkers() { # --------------------------------------------------
#-----------------------------------------------------------------------
gsl__all_checkers() {
clear clear
unset gsl_check_done unset gsl_check_done
echo -ne "Searching for #1..." echo -ne ": Searching for #1..."
gsl__post_check_h1 || return gsl__post_check_h1 || return
echo -n "\r\033[2K: : Searching for NEEDED HEADERS..." echo -ne "\r\033[2K: Searching for NEEDED HEADERS..."
gsl__post_check_needed_headers gsl__post_check_needed_headers
echo -n "\r\033[2K: : Searching for Post TYPE..." echo -ne "\r\033[2K: Searching for Post TYPE..."
gsl__post_check_type gsl__post_check_type
echo -ne "\r\033[2K: Searching for PARAGRAPHS" echo -ne "\r\033[2K: Searching for PARAGRAPHS"
gsl__post_check_paragraphs gsl__post_check_paragraphs
@ -42,6 +44,12 @@ echo -ne "\r\033[2K"
gsl__db_line_post gsl__db_line_post
} }
#-----------------------------------------------------------------------
# -------------------------------------------------
# Modules checkers ; Get Datas and check for errors
# -------------------------------------------------
#-----------------------------------------------------------------------
#======================================================================= #=======================================================================
# Check Post for MISSING & VALID Content HEADERS # Check Post for MISSING & VALID Content HEADERS
#======================================================================= #=======================================================================
@ -571,11 +579,11 @@ done < <(gsl__get_header "$gsl_marker_image" "$gsl_post")
# Check for more STATS # Check for more STATS
#======================================================================= #=======================================================================
gsl__post_check_stats() { gsl__post_check_stats() {
gsl_post_stat_w=` gsl_post_stat_w=`
awk -v l="$gsl_post_begin" \ awk -v l="$gsl_post_begin" \
'NR >= l' \ 'NR >= l' \
"$gsl_post" \ "$gsl_post" \
| wc -w` | wc -w`
gsl_post_stat_w=$(( $gsl_post_stat_w - 2*$gsl_post_stat_p )) gsl_post_stat_w=$(( $gsl_post_stat_w - 2*$gsl_post_stat_p ))
} }

View File

@ -13,16 +13,25 @@
#======================================================================= #=======================================================================
# From: gsl__loop_posts | Convert Post from modules to HTML # From: gsl__loop_posts | Convert Post from modules to HTML
#======================================================================= #=======================================================================
gsl__post_all_makers() { gsl__all_makers() {
clear clear
unset gsl_check_done unset gsl_check_done
gsl__prepare_makers gsl__prepare_makers
echo "# Great, let's begin with Block Code..." echo -ne ": Searching and converting Titles..."
gsl__make_titles
echo -ne "\r\033[2K: Searching Titles and adding DIVs..."
gsl_ct=0 && gsl__make_titles_div_open
gsl_ct=0 && gsl__make_titles_div_close
echo -ne "\r\033[2K: Searching and converting Paragraphs..."
gsl__make_paragraphs
echo -ne "\r\033[2K: Searching and converting Block-Codes..."
gsl__check_bcodes gsl__check_bcodes
echo -ne "\r\033[2K: Searching and converting Citations"
gsl__check_cites gsl__check_cites
cat "$gsl_uri_tmp_post" #clear
cat -n "$gsl_uri_tmp_post"
} }
#======================================================================= #=======================================================================
@ -86,7 +95,7 @@ gsl__get_mark_content_line \
for i in `seq 1 ${#gsl_lines_nbr[@]}` for i in `seq 1 ${#gsl_lines_nbr[@]}`
do do
gsl__post_maker_bcode gsl__make_bcode
done done
} }
@ -94,29 +103,29 @@ done
# Find BLOCKQUOTES # Find BLOCKQUOTES
#======================================================================= #=======================================================================
gsl__check_cites() { gsl__check_cites() {
unset gsl_lines_nbr
gsl_lines_nbr=(` gsl_lines_nbr=(`
gsl__get_mark_content_line \ gsl__get_mark_content_line \
"$gsl_mark_blockquote" \ "$gsl_mark_blockquote" \
"$gsl_uri_tmp_post"`) "$gsl_uri_tmp_post"`)
gsl_lines_nbr=(${gsl_lines_nbr[0]} ${gsl_lines_nbr[1]})
! [[ "$gsl_lines_nbr" ]] \ ! [[ "$gsl_lines_nbr" ]] \
&& return && return
echo "BQ: ${gsl_lines_nbr[@]}" for i in `seq 1 ${#gsl_lines_nbr[@]}`
do
for i in `seq 1 ${#gsl_lines_nbr[@]}` if [[ "$gsl_cite_start" ]];then
do unset gsl_cite_start
if [[ "$gsl_cite_start" ]];then gsl_cite_line_stop=${gsl_lines_nbr[(($i-1))]}
unset gsl_cite_start gsl__make_cite
echo "> BQ C:${gsl_lines_nbr[$((i-1))]}" else
gsl_cite_line_stop=${gsl_lines_nbr[(($i-1))]} gsl_cite_start=true
gsl__post_maker_cite gsl_cite_line_start=${gsl_lines_nbr[(($i-1))]}
else fi
gsl_cite_start=true done
echo "> BQ O:${gsl_lines_nbr[(($i-1))]}" gsl__check_cites
gsl_cite_line_start=${gsl_lines_nbr[(($i-1))]}
fi
done
} }
#======================================================================= #=======================================================================
@ -125,10 +134,140 @@ done
# ----------------------------------------------- # -----------------------------------------------
#======================================================================= #=======================================================================
#=======================================================================
# Find and convert Titles #1-6
#=======================================================================
gsl__make_titles() {
while read -r "gsl_content_line_nbr" "gsl_content_line"
do
for t in `seq 1 6`
do
case "$gsl_content_line" in
"#$t"*)
gsl_content_title=`
awk -F"#$t " '{print $2}' \
<<< "$gsl_content_line"`
gsl_html_title="<h$t>$gsl_content_title</h$t>"
sed -i "${gsl_content_line_nbr}s^.*^$gsl_html_title^" \
"$gsl_uri_tmp_post"
;;
*) continue ;;
esac
done
done < <(cat -n "$gsl_uri_tmp_post")
}
#-----------------------------------------------------------------------
#
#=======================================================================
# Open DIVs after titles for css
#=======================================================================
gsl__make_titles_div_open() {
gsl_ct=$(( gsl_ct + 1 ))
gsl_content_title=`
grep -n "<h" "$gsl_uri_tmp_post" \
| head -n $gsl_ct \
| tail -n 1`
[[ "$gsl_content_title" == "$gsl_content_same_title" ]] && return
! [[ "$gsl_content_title" ]] && return
gsl_content_line_nbr=`
awk -F: '{print $1}' \
<<< $gsl_content_title`
gsl_title_n=`
awk -F"<h" '{print $2}' \
<<< "$gsl_content_title" \
| awk -F">" '{print $1}'`
gsl_html_div="<div class=\"${gsl_site_css}_content-p$gsl_title_n\">"
sed -i "$(( $gsl_content_line_nbr + 1 ))i$gsl_html_div" \
"$gsl_uri_tmp_post"
gsl_content_same_title="$gsl_content_title"
gsl__make_titles_div_open
}
#=======================================================================
# Close DIVs before titles for css
#=======================================================================
gsl__make_titles_div_close() {
gsl_test_line="<div class=\"${gsl_site_css}_content"
gsl_ct=$(( gsl_ct + 1 ))
gsl_content_title=`
grep -n "$gsl_test_line" "$gsl_uri_tmp_post" \
| head -n $gsl_ct \
| tail -n 1`
[[ "$gsl_content_title" == "$gsl_content_same_title" ]] \
&& echo "</div>" >> "$gsl_uri_tmp_post" \
&& return
! [[ "$gsl_content_title" ]] && return
gsl_content_line_nbr=`
awk -F: '{print $1}' \
<<< $gsl_content_title`
while read -r "gsl_search_line_nbr" "gsl_search_line"
do
case "$gsl_search_line" in
"<h"*)
sed -i "${gsl_search_line_nbr}i</div>" "$gsl_uri_tmp_post"
break
;;
*) continue ;;
esac
done < <(awk -v l="$gsl_content_line_nbr" \
'NR > l {print NR,$0}' \
"$gsl_uri_tmp_post")
gsl_content_same_title="$gsl_content_title"
gsl__make_titles_div_close
}
#
#-----------------------------------------------------------------------
#=======================================================================
# Find and convert paragraphs (3 different css styles)
#=======================================================================
gsl__make_paragraphs() {
gsl_html_par_o1="<p class=\"${gsl_site_css}_paragraph\">"
gsl_html_par_o2="<p class=\"${gsl_site_css}_paragraph-2\">"
gsl_html_par_o3="<p class=\"${gsl_site_css}_paragraph-3\">"
gsl_html_par_c="</p>"
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 # Replace gsl_mark_code
#======================================================================= #=======================================================================
gsl__post_maker_bcode() { gsl__make_bcode() {
# Get mark line nbr # Get mark line nbr
gsl_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 # Set gsl_post_header_field_1 gsl_post_header_field_2
gsl__get_header_fields "$gsl_marker_code" 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 "<span>$gsl_bcode_line</span>" >> "$gsl_file_bcode"
done < <(cat "$gsl_dir_domain_files/$gsl_post_header_field_2")
printf '%s %s\n%b\n%s\n' \ printf '%s %s\n%b\n%s\n' \
"<pre class=\"$gsl_css_class" \ "<pre class=\"$gsl_css_class" \
"${gsl_css_class}-$gsl_post_header_field_1\">" \ "${gsl_css_class}-$gsl_post_header_field_1\">" \
"$(cat -n "$gsl_dir_domain_files/$gsl_post_header_field_2")" \ "$(cat "$gsl_file_bcode")" \
"</pre>" \ "</pre>" \
> "$gsl_file_tmp_code" > "$gsl_file_tmp_code"
sed -i "${gsl_line_nbr}r $gsl_file_tmp_code" "$gsl_uri_tmp_post" sed -i "${gsl_line_nbr}r $gsl_file_tmp_code" "$gsl_uri_tmp_post"
sed -i "${gsl_line_nbr}d" "$gsl_uri_tmp_post" sed -i "${gsl_line_nbr}d" "$gsl_uri_tmp_post"
rm -f "$gsl_file_tmp_code" rm -f "$gsl_file_tmp_code"
rm -f "$gsl_file_bcode"
} }
#-----------------------------------------------------------------------
#
#======================================================================= #=======================================================================
# Convert & replace this blockquote # Replace and Convert this blockquote
#======================================================================= #=======================================================================
gsl__post_maker_cite() { gsl__make_cite() {
echo "Block: $gsl_cite_line_start > $gsl_cite_line_stop"
# Put Blockquote in a file and get DATAS gsl_file_tmp_cite=`mktemp` # File to Put whole Blockquote
gsl_file_tmp_cite=`mktemp` gsl_file_tmp_cite_content=`mktemp` # File to Put Blockquote CONTENT only
# Put Blockquote CONTENT only in this file gsl_file_tmp_cite_html=`mktemp` # File to Put final HTML blockquote
gsl_file_tmp_cite_content=`mktemp`
# Put HTML blockquote in this file
gsl_file_tmp_cite_html=`mktemp`
# Put whole blockquote in file
awk -v o="$gsl_cite_line_start" -v c="$gsl_cite_line_stop" \ awk -v o="$gsl_cite_line_start" -v c="$gsl_cite_line_stop" \
'NR >= o && NR <= c' \ 'NR >= o && NR <= c' \
"$gsl_uri_tmp_post" \ "$gsl_uri_tmp_post" \
> "$gsl_file_tmp_cite" > "$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" while read -r "gsl_content_line"
do do
case "$gsl_content_line" in case "$gsl_content_line" in
@ -190,37 +340,62 @@ do
;; ;;
_lang*) _lang*)
gsl_bq_lang=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` gsl_bq_lang=`awk -F" : " '{print $2}' <<< "$gsl_content_line"`
gsl_html_cite_lang=" lang=\"$gsl_bq_lang\""
;; ;;
_year*) _year*)
gsl_bq_year=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` gsl_bq_year=`awk -F" : " '{print $2}' <<< "$gsl_content_line"`
;; ;;
_link*) _link*)
gsl_bq_link=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` 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 esac
done < <(cat "$gsl_file_tmp_cite") 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_bq_year" ]] \
gsl_file_tmp_cite=`mktemp` && gsl_bq_ref+=" ($gsl_bq_year)"
if [[ "$gsl_bq_author" ]];then
gsl_css_class="class=\"${gsl_site_css}_quote\""
# In a function... [[ "$gsl_bq_book" ]] \
[[ "$gsl_bq_lang" ]] \ && gsl_html_cite_book=" title=\"Book:$gsl_bq_ref\""
&& gsl_html_cite_lang=" lang=\"$gsl_bq_lang\""
[[ "$gsl_bq_link" ]] \ ! [[ "$gsl_bq_link" ]] && [[ "$gsl_bq_book" ]] \
&& gsl_html_cite_link=" cite=\"$gsl_bq_link\"" && 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`
do
sed -i "${gsl_cite_line_start}d" "$gsl_uri_tmp_post"
done
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" cat << EOCITE > "$gsl_file_tmp_cite_html"
<figure> <figure>
@ -229,30 +404,24 @@ $(cat "$gsl_file_tmp_cite_content")
</blockquote> </blockquote>
<figcaption class="a-lec_fgc-quote"> <figcaption class="a-lec_fgc-quote">
<cite> <cite>
<a href="$gsl_bq_link" target="_blank">$gsl_bq_author</a> <a href="$gsl_bq_link" target="_blank"$gsl_html_cite_book>$gsl_bq_author</a>$gsl_bq_ref
</cite> </cite>
</figcaption> </figcaption>
</figure> </figure>
EOCITE EOCITE
# Insert blockquote file
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`
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_@}
} }
#=======================================================================
# 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"
<blockquote $gsl_css_class$gsl_html_cite_lang$gsl_html_cite_link>
$(cat "$gsl_file_tmp_cite_content")
</blockquote>
EOCITE
}
#
#-----------------------------------------------------------------------

View File

@ -4,28 +4,11 @@
# By echolib # By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================= #-----------------------------------------------------------------------
# Check NAME post from [OPT] ; should be from autocompletion # -----------------------------------------------------------
#======================================================================= # MAIN LOOP. Read from Post list. Do according to Post Status
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
#=======================================================================
gsl__loop_posts() { gsl__loop_posts() {
gsl__logs_print \ gsl__logs_print \
"$gsl_log_i" \ "$gsl_log_i" \
@ -53,6 +36,7 @@ do
continue continue
fi fi
# From COMMAND [OPT]
case "$1" in case "$1" in
check) check)
if ! [[ "$gsl_force_check" ]];then if ! [[ "$gsl_force_check" ]];then
@ -66,7 +50,7 @@ do
"$gsl_post" \ "$gsl_post" \
"${PWD}" "${PWD}"
gsl_process="Checked" gsl_process="Checked"
gsl__post_all_checkers gsl__all_checkers
;; ;;
make) make)
@ -75,7 +59,7 @@ do
case "$gsl_db_post_status" in case "$gsl_db_post_status" in
Checked) Checked)
gsl__post_compare_hash || continue gsl__post_compare_hash || continue
gsl__post_all_makers gsl__all_makers
;; ;;
Made) Made)
@ -102,13 +86,29 @@ done
&& echo "# Check already 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__check_opt_post() {
gsl_post_csum=`cksum "$gsl_post"` [[ `ls -1 *.gsl | grep "$1"` ]] \
gsl_post_hash=`awk '{print $1}' <<< "$gsl_post_csum"` && gsl_this_post="$1"
gsl_post_size=`awk '{print $2}' <<< "$gsl_post_csum"` }
#=======================================================================
# 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 if ! [[ "$gsl_db_file_hash" == "$gsl_file_hash" ]];then
gsl__logs_print \ gsl__logs_print \
"$gsl_log_e" \ "$gsl_log_w" \
"File" \ "File" \
"Hash" \ "Hash" \
"$gsl_content_filename has changed. $gsl_db_file_hash $gsl_file_hash" \ "$gsl_content_filename has changed. $gsl_db_file_hash $gsl_file_hash" \
"$gsl_file_db_files" "$gsl_file_db_files"
unset gsl_check_done gsl_checker_war=true
gsl_checker_err=true
return 1 return 1
fi fi
done < <(grep "$gsl_post" "$gsl_file_db_posts" \ done < <(grep "$gsl_post" "$gsl_file_db_posts" \
@ -174,118 +173,6 @@ case "$gsl_process" in
esac 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 # Check NEEDED Fields from HEADER
#======================================================================= #=======================================================================
@ -331,3 +218,125 @@ if ! [[ "$gsl_post_header_field_3" ]];then
esac esac
fi 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"`
}