Added Tools ; Checkers

This commit is contained in:
Cyrille L 2022-02-14 18:54:07 +01:00
parent a6fe6ee50c
commit 01e71ddc61
2 changed files with 110 additions and 20 deletions

View File

@ -15,15 +15,16 @@ echo -n ": Searching for needed Headers..."
gsl__post_check_needed_headers gsl__post_check_needed_headers
echo -ne "\r\033[2K: Searching for #1..." echo -ne "\r\033[2K: Searching for #1..."
gsl__post_check_h1 gsl__post_check_h1
echo -ne "\r\033[2K: Searching for Paragraph" echo -ne "\r\033[2K: Searching for Paragraphs"
gsl__post_check_paragraphs gsl__post_check_paragraphs
echo -ne "\r\033[2K: Searching for Content MARKERS..." echo -ne "\r\033[2K: Searching for Content MARKERS..."
gsl__post_check_markers gsl__post_check_markers
echo -ne "\r\033[2K: Searching for BLOCKQUOTE..." echo -ne "\r\033[2K: Searching for BLOCKQUOTEs..."
gsl__post_check_blockquote gsl__post_check_blockquote
echo -ne "\r\033[2K: Searching for ABBR..." echo -ne "\r\033[2K: Searching for ABBRs..."
gsl__post_check_abbr gsl__post_check_abbr
echo -ne "\r\033[2K: Searching for LINKs.."
gsl__post_check_links
echo echo
#echo -ne "\r\033[2K" #echo -ne "\r\033[2K"
@ -318,6 +319,7 @@ fi
# Check Post for ABBR HEADER + Content # Check Post for ABBR HEADER + Content
#======================================================================= #=======================================================================
gsl__post_check_abbr() { gsl__post_check_abbr() {
gsl_post_stat_abbr=0
while read -r "gsl_header_abbr" while read -r "gsl_header_abbr"
do do
gsl_post_abbr_s=`gsl__get_header_field 1 "$gsl_header_abbr"` gsl_post_abbr_s=`gsl__get_header_field 1 "$gsl_header_abbr"`
@ -331,32 +333,86 @@ do
"$gsl_log_e" \ "$gsl_log_e" \
"Post" \ "Post" \
"ABBR" \ "ABBR" \
"Missing Line $gsl_post_line_nbr. $gsl_marker_abbr: Short : Long" \ "Line:$gsl_post_line_nbr > Content: $gsl_log_act_abbr" \
"${PWD}/$gsl_post" "${PWD}/$gsl_post"
gsl_checker_err=true gsl_checker_err=true
continue continue
fi fi
while read -r "gsl_content_line_nbr" if ! [[ `gsl__get_content_line "$gsl_post_abbr_s" "$gsl_post"` ]];then
do
gsl_abbr_lines+="$gsl_content_line_nbr,"
done < <(gsl__get_content_line "$gsl_post_abbr_s" "$gsl_post" )
if ! [[ "$gsl_abbr_lines" ]];then
gsl__logs_print \ gsl__logs_print \
"$gsl_log_e" \ "$gsl_log_e" \
"Post" \ "Post" \
"ABBR" \ "ABBR" \
"Missing content: $gsl_post_abbr_s" \ "Missing Content: $gsl_post_abbr_s" \
"${PWD}/$gsl_post" "${PWD}/$gsl_post"
gsl_checker_err=true gsl_checker_err=true
else else
(( gsl_post_stat_abbr ++ ))
fi
done < <(gsl__get_header "$gsl_marker_abbr" "$gsl_post")
gsl__logs_print \ gsl__logs_print \
"$gsl_log_i" \ "$gsl_log_i" \
"Post" \ "Post" \
"ABBR" \ "ABBR" \
"Found: $gsl_post_abbr_s line $gsl_abbr_lines" \ "NBR=$gsl_post_stat_abbr" \
"${PWD}/$gsl_post" "${PWD}/$gsl_post"
fi }
done < <(gsl__get_header "$gsl_marker_abbr" "$gsl_post")
#=======================================================================
# Check Post for LINKs HEADER + Content
#=======================================================================
gsl__post_check_links() {
while read -r "gsl_header_link"
do
# Get in HEADERS
gsl_post_link_ref=`gsl__get_header_field 1 "$gsl_header_link"`
gsl_post_link_url=`gsl__get_header_field 2 "$gsl_header_link"`
gsl_post_link_alt=`gsl__get_header_field 3 "$gsl_header_link"`
gsl_post_line_nbr=`gsl__get_line "$gsl_marker_link$gsl_post_link_ref" "$gsl_post"`
if ! [[ "$gsl_post_link_ref" ]] || \
! [[ "$gsl_post_link_url" ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Link" \
"Line:$gsl_post_line_nbr > Content: $gsl_log_act_link" \
"${PWD}/$gsl_post"
gsl_checker_err=true
continue
fi
# Not ALT TEXT ?
if ! [[ "$gsl_post_link_alt" ]];then
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Link" \
"Line:$gsl_post_line_nbr > No ALT TEXT ?" \
"${PWD}/$gsl_post"
gsl_checker_war=true
fi
# Find if ref is in CONTENT
gsl_content_link=`
gsl__get_content_finder \
-o "$gsl_mo_link" \
-b "$gsl_post_link_ref" \
-c "$gsl_mc_link" \
-f "$gsl_post" \
| tail -1`
if ! [[ $gsl_content_link ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Link" \
"Missing Content: [_${gsl_post_link_ref}_]" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
done < <(gsl__get_header "$gsl_marker_link" "$gsl_post")
} }

View File

@ -97,6 +97,11 @@ if [[ "$gsl_db_post_hash" == "$gsl_post_hash" ]];then
fi fi
} }
#-----------------------------------------------------------------------
#
# TOOLS
#
#-----------------------------------------------------------------------
#======================================================================= #=======================================================================
# Get line nbr from Post... $1: TERM | $2: File # Get line nbr from Post... $1: TERM | $2: File
#======================================================================= #=======================================================================
@ -125,10 +130,39 @@ awk -F" : " -v f="$1" \
} }
#======================================================================= #=======================================================================
# Get fields from variable... $1: field | $2: variable # Get line nbr from CONTENT Post... $1: TERM | $2: File
#======================================================================= #=======================================================================
gsl__get_content_line() { gsl__get_content_line() {
awk -v line="$gsl_post_begin" -v s="$1" \ awk -v line="$gsl_post_begin" -v s="$1" \
'NR >= line && $0 ~ s {print NR}' \ 'NR >= line && $0 ~ s {print NR}' \
"$2" "$2"
} }
#=======================================================================
# 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"
elif [[ "$ivar" ]];then
grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" <<< "$ivar"
fi
}