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

156 lines
3.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__post_checkers
# Folder: /var/lib/gsl/scripts
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#=======================================================================
# From: gsl__loop_posts | Check Post from modules
#=======================================================================
gsl__post_all_checkers() {
clear
unset gsl_check_done
echo -n ": Searching for Headers..."
gsl__post_check_headers
echo -ne "\r\033[2K: Searching for #1..."
gsl__post_check_h1
echo
# End of checkers : show logs for war and err
[[ "$gsl_checker_war" ]] \
&& gsl log -s -w
[[ "$gsl_checker_err" ]] \
&& gsl log -s -e
}
#=======================================================================
# Check Post for VALID Content HEADERS
#=======================================================================
gsl__post_check_headers() {
#
# Check if Missing NEEDED HEADERS
#
# Title
gsl_header_title=`gsl__get_header "$gsl_marker_title" "$gsl_post"`
! [[ "$gsl_header_title" ]] \
&& gsl__logs_print \
"$gsl_log_e" \
"Title" \
"Post" \
"Missing" \
"${PWD}/$gsl_post" \
&& gsl_checker_err=true
# Slug
gsl_header_slug=`gsl__get_header "$gsl_marker_slug" "$gsl_post"`
! [[ "$gsl_header_slug" ]] \
&& gsl__logs_print \
"$gsl_log_e" \
"Slug" \
"Post" \
"Missing" \
"${PWD}/$gsl_post" \
&& gsl_checker_err=true
# Author
gsl_header_author=`gsl__get_header "$gsl_marker_author" "$gsl_post"`
! [[ "$gsl_header_author" ]] \
&& gsl__logs_print \
"$gsl_log_e" \
"Author" \
"Post" \
"Missing" \
"${PWD}/$gsl_post" \
&& gsl_checker_err=true
# Date
gsl_header_date=`gsl__get_header "$gsl_marker_date" "$gsl_post"`
! [[ "$gsl_header_date" ]] \
&& gsl__logs_print \
"$gsl_log_e" \
"Date" \
"Post" \
"Missing" \
"${PWD}/$gsl_post" \
&& gsl_checker_err=true
# Description
gsl_header_info=`gsl__get_header "$gsl_marker_info" "$gsl_post"`
! [[ "$gsl_header_info" ]] \
&& gsl__logs_print \
"$gsl_log_e" \
"Infos" \
"Post" \
"Missing" \
"${PWD}/$gsl_post" \
&& gsl_checker_err=true
#
# Check for VALID Content HEADERS
#
# Author registred
if ! [[ `grep "$gsl_header_author" "$gsl_file_auth_ndd"` ]];then
gsl__logs_print \
"$gsl_log_e" \
"Author" \
"Post" \
"$gsl_header_author not registred for domain $gsl_find_domain" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
# Date Format YYYY-MM-DD
if ! [[ "$gsl_header_date" =~ $gsl_test_date ]];then
gsl__logs_print \
"$gsl_log_e" \
"Date" \
"Post" \
"$gsl_header_date not YYYY-MM-DD" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
[[ "$gsl_checker_err" ]] && return
# Slug format title-post
gsl_header_slug_test=${gsl_header_slug// /-}
if ! [[ "$gsl_header_slug" == "$gsl_header_slug_test" ]];then
gsl_new_header_slug="$gsl_marker_slug$gsl_header_slug_test"
sed -i "s|$gsl_marker_slug$gsl_header_slug|$gsl_new_header_slug" \
"$gsl_post" && \
gsl__logs_print \
"$gsl_log_w" \
"Slug" \
"Post" \
"Changed: $gsl_header_slug_test" \
"${PWD}/$gsl_post"
gsl_checker_war=true
fi
}
#=======================================================================
# Check Post for begining content
#=======================================================================
gsl__post_check_h1() {
gsl_post_begin=`
grep -n "#1" $gsl_post \
| head -1 \
| awk -F: '{print $1}'`
if ! [[ "$gsl_post_begin" ]];then
gsl__logs_print \
"$gsl_log_e" \
"Begin" \
"Post" \
"Missing content: #1 TITLE" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}