gsl-statique-litterateur/var/lib/gsl/scripts/gsl__do_commons

200 lines
5.3 KiB
Plaintext
Raw Normal View History

2022-02-27 19:16:16 +01:00
#!/bin/bash
# file: gsl__do_commons
# Folder: /var/lib/gsl/scripts
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#=======================================================================
# Get NEEDED DATAS from HEADERS
#=======================================================================
gsl__get_needed_headers() {
gsl_post_type=`gsl__get_header "$gsl_marker_type" "$gsl_post"`
gsl_header_title=`gsl__get_header "$gsl_marker_title" "$gsl_post"`
gsl_header_slug=`gsl__get_header "$gsl_marker_slug" "$gsl_post"`
gsl_header_author=`gsl__get_header "$gsl_marker_author" "$gsl_post"`
gsl_header_date=`gsl__get_header "$gsl_marker_date" "$gsl_post"`
gsl_header_info=`gsl__get_header "$gsl_marker_info" "$gsl_post"`
gsl_header_tags=`gsl__get_header "$gsl_marker_tags" "$gsl_post"`
}
#======================================================================
# Check | Make in Loop from header datas $1: process $2:marker $3:file
#======================================================================
gsl__do_header() {
while read -r "gsl_header_content_line"
do
gsl__get_header_fields "$2"
case "$1" in
check)
case "$2" in
"$gsl_marker_link") gsl__check_link ;;
"$gsl_marker_abbr") gsl__check_abbr ;;
"$gsl_marker_file") gsl__check_file ;;
"$gsl_marker_image") gsl__check_image ;;
"$gsl_marker_code") gsl__check_fcode ;;
esac
;;
2022-03-02 14:27:50 +01:00
2022-02-27 19:16:16 +01:00
make)
case "$2" in
2022-03-02 14:27:50 +01:00
"$gsl_marker_link") gsl__make_link ;;
"$gsl_marker_abbr") gsl__make_abbr ;;
"$gsl_marker_image") gsl__make_image ;;
2022-02-27 19:16:16 +01:00
esac
;;
esac
done < <(gsl__get_header "$2" "$3")
}
#======================================================================
# Do Strongs && Bolds + Get STATS | $1: Process $2:File
#======================================================================
gsl__do_strongs_bolds() {
case "$1" in
"stats")
gsl_stat_strongs=0
gsl_stat_bolds=0
;;
"make")
echo -ne "\r\033[2K: Convrting Strongs & Bolds..."
;;
esac
while read -r "strong"
do
if [[ "$strong" ]] && \
[[ `grep "$gsl_mark_strong$strong$gsl_mark_strong" "$2"` ]];then
case "$1" in
"stats")
((gsl_stat_strongs++))
;;
"make")
echo -ne "\r\033[2K: Convrting Strong... $strong"
gsl_strong="$gsl_mark_strong$strong$gsl_mark_strong"
gsl_html_strong="<strong>$strong</strong>"
sed -i "s|$gsl_strong|$gsl_html_strong|g" "$2"
;;
esac
fi
done < <(grep -oP "(?<=$gsl_mark_strong).*?(?=$gsl_mark_strong)" "$2")
# Bolds
echo -ne "\r\033[2K: Counting Bolds..."
while read -r "bold"
do
if [[ "$bold" ]] && \
[[ `grep "$gsl_mark_bold$bold$gsl_mark_bold" "$2"` ]];then
case "$1" in
"stats")
((gsl_stat_bolds++))
;;
"make")
echo -ne "\r\033[2K: Convrting Bold... $bold"
gsl_bold="$gsl_mark_bold$bold$gsl_mark_bold"
gsl_html_bold="<b>$bold</b>"
sed -i "s|$gsl_bold|$gsl_html_bold|g" "$2"
;;
esac
fi
done < <(grep -oP "(?<=$gsl_mark_bold).*?(?=$gsl_mark_bold)" "$2")
case "$1" in
"stats")
gsl_stat_bolds=$((gsl_stat_bolds - gsl_stat_strongs))
;;
esac
}
#======================================================================
# Do Italics + Get STATS | $1: Process $2:File
#======================================================================
gsl__do_italics() {
echo -ne "\r\033[2K: Counting Italics..."
2022-03-02 14:27:50 +01:00
while IFS=: read -r "n" "italic"
do
2022-03-02 14:27:50 +01:00
[[ `awk -v l="$n" 'NR == l && $1 ~ "_link"' "$2"` ]] && continue
case "$1" in
"make")
echo -ne "\r\033[2K: Convrting Italics..."
;;
esac
if [[ "$italic" ]] && \
[[ `grep "$gsl_mark_italic$italic$gsl_mark_italic" "$2"` ]];then
case "$1" in
"stats")
((gsl_stat_italics++))
;;
"make")
echo -ne "\r\033[2K: Convrting Italic... $italic"
gsl_italic="$gsl_mark_italic$italic$gsl_mark_italic"
gsl_html_italic="<em>$italic</em>"
sed -i "s|$gsl_italic|$gsl_html_italic|g" "$2"
;;
esac
fi
2022-03-02 14:27:50 +01:00
done < <(grep -oPn "(?<=$gsl_mark_italic).*?(?=$gsl_mark_italic)" "$2")
}
#======================================================================
# Do Italics + Get STATS | $1: Process $2:File
#======================================================================
gsl__do_icode() {
case "$1" in
"stats")
gsl_stat_icodes=0
;;
"make")
gsl_html_icode_o="<code class=\"${gsl_site_css}-code\">"
echo -ne "\r\033[2K: Convrting Inline-Codes..."
;;
esac
echo -ne "\r\033[2K: Counting Inline-Codes..."
while read -r "icode"
do
if [[ "$icode" ]] && \
[[ `grep "$gsl_mark_code$icode$gsl_mark_code" "$2"` ]];then
case "$1" in
"stats")
2022-03-01 18:39:46 +01:00
((gsl_stat_icode++))
;;
"make")
echo -ne "\r\033[2K: Convrting Inline-Code... $icode"
gsl_icode="$gsl_mark_code$icode$gsl_mark_code"
gsl_html_icode="$gsl_html_icode_o$icode</code>"
for d in "${gsl_d[@]}"
do
case "$icode" in
*"$d"*)
continue
;;
*)
sed -i "s${d}${gsl_icode}${d}${gsl_html_icode}${d}" "$2"
break
;;
esac
done
;;
esac
fi
done < <(grep -oP "(?<=$gsl_mark_code).*?(?=$gsl_mark_code)" "$2")
}