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

108 lines
2.9 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
2022-06-14 18:51:19 +02:00
# By echolib (XMPP: im@echolib.re)
2022-02-27 19:16:16 +01:00
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
2022-06-14 18:51:19 +02:00
# Set/Get NEEDED DATAS from META HEADERS
# $1: process
# $2: file: (gsl_tmp_head)
#======================================================================
2022-06-14 18:51:19 +02:00
get__needed_headers() {
gsl__logs_print -i -g \
"Get" \
"Needed Metas from header" \
"$2"
2022-06-14 18:51:19 +02:00
read__line_with "^$gsl_marker_type" "$1" \
"$gsl_marker_type" "meta" "$2"
2022-06-14 18:51:19 +02:00
read__line_with "^$gsl_marker_slug" "$1" \
"$gsl_marker_slug" "meta" "$2"
read__line_with "^$gsl_marker_title" "$1" \
"$gsl_marker_title" "meta" "$2"
read__line_with "^$gsl_marker_info" "$1" \
"$gsl_marker_info" "meta" "$2"
read__line_with "^$gsl_marker_author" "$1" \
"$gsl_marker_author" "meta" "$2"
2022-06-14 18:51:19 +02:00
read__line_with "^$gsl_marker_tags" "$1" \
"$gsl_marker_tags" "meta" "$2"
2022-06-14 18:51:19 +02:00
read__line_with "^$gsl_marker_date" "$1" \
"$gsl_marker_date" "meta" "$2"
2022-06-14 18:51:19 +02:00
read__line_with "^$gsl_marker_css" "$1" \
"$gsl_marker_css" "meta" "$2"
}
2022-06-14 18:51:19 +02:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Read line with
# $1: TERM
# $2: process
# $3: marker
# $4: type (meta/metas)
# $5: file
# From "meta" ; check only one marker ; get fields
# From "metas" ; check multiple markers ; get fields
# From content ; read line ; no need to get fields
#======================================================================
2022-06-14 18:51:19 +02:00
read__line_with() {
# meta must be set, and no more than one value
if [[ "$2" == "check" && "$4" == "meta" ]];then
meta_nbr=`grep -n "$1" "$5" | wc -l`
if (( $meta_nbr == 0 ));then
if [[ "$3" == "$gsl_marker_css" ]];then
gsl__logs_print -w -h \
"$gsl_marker_css" \
"Body template: css not customized" \
"$PWD/$gsl_post"
gsl_post_css=""
else
gsl__logs_print -e -h \
"$3" \
"Unused needed marker" \
"${PWD}/$gsl_post"
return
fi
2022-06-14 18:51:19 +02:00
elif (( $meta_nbr > 1 ));then
gsl__logs_print -e -h \
"$3" \
"Set only one marker ; Found $meta_nbr" \
"${PWD}/$gsl_post"
return
fi
2022-06-14 18:51:19 +02:00
fi
2022-06-14 18:51:19 +02:00
# Read line filtered
while IFS=: read -r "ln" "gsl_line"
do
2022-03-12 16:16:21 +01:00
2022-06-14 18:51:19 +02:00
# Get values if meta(s)
case "$4" in
meta|metas)
header_f1=`awk -F" : " '{print $1}' <<<"$gsl_line"`
header_f0=`awk -F": " '{print $1}' <<<"$header_f1"`
header_f1=`awk -F": " '{print $2}' <<<"$header_f1"`
header_f2=`awk -F" : " '{print $2}' <<<"$gsl_line"`
header_f3=`awk -F" : " '{print $3}' <<<"$gsl_line"`
;;
esac
2022-06-14 18:51:19 +02:00
# From process, do
case "$2" in
check) check__headers_from_filter "$1" "$2" "$3" "$4" ;;
make) make__headers_from_filter "$1" "$3" "$5" "$6" "$7" "$8" ;;
esac
2022-06-14 18:51:19 +02:00
done < <(grep -n "$1" "$5")
}