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

1374 lines
35 KiB
Plaintext
Raw Normal View History

2022-02-17 17:21:35 +01:00
#!/bin/bash
# file: gsl__post_makers
# Folder: /var/lib/gsl/scripts
2022-06-14 18:51:19 +02:00
# By echolib (XMPP: im@echolib.re)
2022-02-17 17:21:35 +01:00
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
2022-02-19 18:17:09 +01:00
2022-03-05 18:06:48 +01:00
2022-06-14 18:51:19 +02:00
#----------------------------------------------------------------------
# ---------------
# SIDEBAR Section
# ---------------
#----------------------------------------------------------------------
#======================================================================
# Get arguments from COMMAND (sidebar)
# $1: process
# $2: position
# $3: file
#======================================================================
sidebar__OPTIONS() {
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# Check OPTIONS except for "latest"
# ---------------------------------
sidebar__check_args() {
# Position
[[ "$1" = *[!0-9]* ]] \
&& gsl__invalid_option "$1" "position (1 to $site_max_list)"
(( "$1" == "0" || "$1" > "$site_max_list" )) \
&& gsl__invalid_option "$1" "position (1 to $site_max_list)"
2022-03-02 14:27:50 +01:00
2022-06-14 18:51:19 +02:00
position="$1"
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# file post
if__file "$2" post
gsl_post="$2"
! [[ -f "$gsl_dir_db_domain/$gsl_this_post.db" ]] \
&& echo "! Article not check yet" \
&& exit
}
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
case "$1" in
add|-a)
sidebar__check_args "$2" "$3"
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
replace|-r)
sidebar__check_args "$2" "$3"
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
latest|-l|oldest|-o)
2022-06-23 18:06:18 +02:00
position="1 to $site_max_list"
2022-06-14 18:51:19 +02:00
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
*)
gsl__invalid_option "$1" "add|replace|latest|oldest"
;;
esac
2022-06-14 18:51:19 +02:00
# Start process
sidebar__create "$1" "$position"
}
#======================================================================
# Sidebar: create /templates/sidebar.html
# $1: process
# $2: Position
# $3: DB file
#======================================================================
sidebar__create() {
log__process_begin "Sidebar"
2022-03-05 20:15:53 +01:00
2022-06-25 12:30:54 +02:00
gsl__logs_print -i -srv $1 \
2022-06-14 18:51:19 +02:00
"Position: $2 in final sidebar" \
"$gsl_dir_domain_tpl/sidebar.html"
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
mkdir -p "$gsl_dir_domain_sidebar"
case "$1" in
latest|-l) sort_arg='-k2' ;;
oldest|-o) sort_arg='-k2r' ;;
esac
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
case "$1" in
latest|-l|oldest|-o)
sidebar_pos=0
while read -r "sorted_file"
do
((sidebar_pos++))
sidebar_HTML_item="$gsl_dir_domain_sidebar/$sidebar_pos.html"
db_name=`awk -F: '{print $1}' <<<"$sorted_file"`
source "$db_name"
gsl_post=`basename "$article_URI"`
gsl__logs_print -i -sdb $1 \
"Position: $sidebar_pos ; $article_epoch" \
"$sidebar_HTML_item"
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
srv__files datas
create__HTML_sidebar_item "$sidebar_HTML_item"
done < <(grep "Date" "$gsl_dir_db_domain/"*.gsl.db \
| sort -t= $sort_arg \
| head -n $site_max_list)
;;
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
replace|-r)
gsl__logs_print -i -sdb $1 \
"Position: $2" \
"$gsl_dir_domain_sidebar/$2.html"
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
source "$gsl_dir_db_domain/$gsl_this_post.db"
2022-06-24 09:53:05 +02:00
srv__files datas
2022-06-14 18:51:19 +02:00
create__HTML_sidebar_item "$gsl_dir_domain_sidebar/$2.html"
;;
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
add|-a)
for i in `seq $site_max_list -1 $2`
do
if (( $i == $site_max_list)) &&
[[ -f "$gsl_dir_domain_sidebar/$i.html" ]];then
rm -f "$gsl_dir_domain_sidebar/$i.html"
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
else
[[ -f "$gsl_dir_domain_sidebar/$i.html" ]] \
&& mv "$gsl_dir_domain_sidebar/$i.html" \
"$gsl_dir_domain_sidebar/$(( i + 1 )).html"
fi
done
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
gsl__logs_print -i -sdb $1 \
"Position: $2" \
"$gsl_dir_domain_sidebar/$2.html"
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
source "$gsl_dir_db_domain/$gsl_this_post.db"
2022-06-24 09:53:05 +02:00
srv__files datas
2022-06-14 18:51:19 +02:00
create__HTML_sidebar_item "$gsl_dir_domain_sidebar/$2.html"
;;
esac
create__HTML_sidebar "$1" "$gsl_dir_domain_tpl/sidebar.html"
gsl__logs_print -w -sdb "Tips" \
"Do not forget to sync ; use gsl sync" \
"$gsl_dir_domain_tpl/sidebar.html"
unset gsl_post
log__process_end "Sidebar"
2022-02-19 18:17:09 +01:00
}
2022-06-14 18:51:19 +02:00
#----------------------------------------------------------------------
# ------------
# MAKE Section
# ------------
#----------------------------------------------------------------------
#======================================================================
2022-06-14 18:51:19 +02:00
# Get arguments from COMMAND (make)
#======================================================================
make__OPTIONS() {
gsl_proc="wip"
2022-04-23 17:51:46 +02:00
2022-06-14 18:51:19 +02:00
while test "$2"
do
2022-06-14 18:51:19 +02:00
case "$2" in
-F)
gsl_force_make=true
log_info_force="Force "
;;
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
*".gsl")
if__file "$2" post
gsl_post="$2"
post_only="$2"
;;
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
-N)
gsl_make_newer=true
unset gsl_force_make
;;
2022-06-25 12:30:54 +02:00
2022-06-14 18:51:19 +02:00
*)
[[ "$gsl_post" ]] || [[ $gsl_force_make ]] \
&& echo "! Unused argument: $2" \
|| gsl__invalid_option "$2" "-F|(FILE)"
;;
esac
2022-06-14 18:51:19 +02:00
shift
2022-04-23 17:51:46 +02:00
done
2022-06-14 18:51:19 +02:00
[[ "$gsl_post" ]] || log_info_all=" ALL"
log__process_begin "${log_info_force}Make${log_info_all}"
posts__loop make
2022-06-14 18:51:19 +02:00
# For logs ; set post or unset if all
[[ $log_info_all ]] && unset gsl_post
[[ $post_only ]] && gsl_post="$post_only"
2022-04-23 17:51:46 +02:00
2022-06-14 18:51:19 +02:00
log__process_end "${log_info_force}Make${log_info_all}"
}
2022-06-14 18:51:19 +02:00
#=======================================================================
# From: posts__loop() ; Convert Post to HTML
# But, before: Compare hash ans existing files
#=======================================================================
Makers() {
# Check if hashes not match
! [[ "$gsl_do_make" ]] && return
# OPT: -F (force)
gsl_do_make=true
if [[ "$gsl_force_make" ]];then
if [[ "$gsl_srv_wip_file" ]];then
gsl__logs_print -w -g -M \
"WIP: Force again HTML $article_Type" \
"$PWD/$gsl_post"
fi
2022-06-14 18:51:19 +02:00
# Not force
else
# if file exists (value is true)
if [[ "$gsl_srv_wip_file" ]];then
2022-06-15 17:55:43 +02:00
if (( $article_Status_chk == $article_Status_wip ));then
gsl__logs_print -w -g -M \
"WIP: Already done ; Use -F to force" \
"$gsl_srv_post_wip"
unset gsl_do_make
fi
2022-06-14 18:51:19 +02:00
fi
fi
2022-04-23 17:51:46 +02:00
2022-06-14 18:51:19 +02:00
! [[ "$gsl_do_make" ]] && return
#----------------------------------------------------------------------
2022-06-14 18:51:19 +02:00
# makers modules
#----------------------------------------------------------------------
# Titles
read__line_with "^#[1-6]" "make" "title" "content" "$gsl_tmp_post"
2022-06-14 18:51:19 +02:00
# Paragraphs
make__paragraphs "$gsl_mark_p_start " "$gsl_mark_p_close" "$gsl_tmp_post"
2022-04-23 17:51:46 +02:00
2022-06-14 18:51:19 +02:00
# New Line (convert | in <br />)
make__br "$gsl_mark_newline" "$gsl_tmp_post"
# abbr
read__line_with "^$gsl_marker_abbr" "make" \
"abbr" "metas" "$gsl_tmp_head"
2022-06-14 18:51:19 +02:00
# links
read__line_with "^$gsl_marker_link" "make" \
"link" "metas" "$gsl_tmp_head"
2022-06-14 18:51:19 +02:00
# flink
read__line_with "^$gsl_marker_flink" "make" \
"flink" "metas" "$gsl_tmp_head"
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
#----------------------------------------------------------------------
2022-06-28 22:56:48 +02:00
# Method bsis (Bold, String, Italic, Strike)
# Same for inline_code, done after bsis
# Search all lines for bsis mark
## Read each letter from line, excluding ones inside inline_code
## Convert mark with specific special charcter
## Convert specific special character to HTML
#----------------------------------------------------------------------
# Convert bsis
make__bsis_search "$gsl_tmp_post"
make__bsis "$gsl_tmp_post"
# Convert inlinde_code
make__icode_convert "$gsl_tmp_post"
make__icode "$gsl_tmp_post"
2022-06-14 18:51:19 +02:00
#----------------------------------------------------------------------
2022-06-28 22:56:48 +02:00
2022-06-14 18:51:19 +02:00
# Image
read__line_with "^$gsl_marker_image" "make" \
"image" "metas" "$gsl_tmp_head"
2022-06-14 18:51:19 +02:00
# lists
make__lists "$gsl_tmp_post"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Quotes
make__quotes "$gsl_tmp_post"
2022-06-14 18:51:19 +02:00
# File code
read__line_with "^$gsl_marker_fcode" "make" \
"fcode" "metas" "$gsl_tmp_head"
2022-04-13 18:33:11 +02:00
2022-06-14 18:51:19 +02:00
# At the very end, make brut codes
read__line_with "^$gsl_marker_fbrut" "make" \
"fbrut" "metas" "$gsl_tmp_head"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# a11y + div between titles
make__div_title "$gsl_tmp_post"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# a11y (tabulation)
spc=' ' # 8 spaces. Main content (2*4)
sed -i -e "s|^|$spc|" "$gsl_tmp_post"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Create wip HTML page
create__HTML_page
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
rm -f "$gsl_tmp_post"
DB__set_status "wip"
}
2022-02-21 17:25:08 +01:00
2022-04-07 18:47:48 +02:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Filter content
# Called from read__line_with() in gsl__do_commons
# $1: marker
# $2: mark
# $3: file
# $4: HTML start
# $5: HTML close
#======================================================================
make__headers_from_filter() {
case "$2" in
title) make__titles "$3" ;;
abbr) make__abbrs "$5" "$gsl_tmp_post" ;;
link|flink) make__links "$gsl_tmp_post" "$2" ;;
fcode) make__file_codes "$gsl_tmp_post" ;;
fbrut) make__file_bruts "$gsl_tmp_post" ;;
image) make__file_images "$gsl_tmp_post" ;;
esac
}
2022-04-25 13:17:09 +02:00
2022-06-14 18:51:19 +02:00
#======================================================================
# From make loop_line()
# Convert words between marks (strong, icode, emphasis)
# $1: marker
# #2: mark (betwee)
# $3: file
# $4: HTML start
# $5: HTML close
# $6: temp marker (if legacy in inline code)
#======================================================================
make__words() {
icm=0
for (( i=0; i<${#gsl_line}; i++ ))
do
# For markers not "inline-code", set characters to bypass
case "${gsl_line:$i:1}" in
"$gsl_mark_icode")
if [[ "$1" != "$gsl_mark_icode" ]];then
icm=$(( icm + 1 ))
incode=true;incode_s=$i
icm_p=$(( $icm % 2 ))
[[ $icm_p -eq 0 ]] && unset incode
fi
;;
esac
case "${gsl_line:$i:1}" in
"$1")
if [[ $incode ]] && (( "$i" > $incode_s ));then
# Get line containing temp markers and replace
[[ `grep "$ln" <<<"${incode_line[@]}"` ]] || incode_line+=($ln)
sed -i -r "${ln}s|^(.{"$i"})"$1"|\1$6|" "$3"
continue
fi
if [[ $open ]];then
unset open
sed -i -r "${ln}s|^(.{"$i"})"$1"|\1$5|" "$3"
break
2022-04-25 13:17:09 +02:00
2022-06-14 18:51:19 +02:00
else
open=true
sed -i -r "${ln}s|^(.{"$i"})"$1"|\1$4|" "$3"
break
2022-04-25 13:17:09 +02:00
fi
2022-03-02 17:25:23 +01:00
;;
esac
2022-06-14 18:51:19 +02:00
done
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
make__loop_line "$1" "$2" "$3" "$4" "$5" "$6"
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Make HTML Titles
# $1: file (from $5 of read__line_with)
#======================================================================
make__titles() {
while read -r "t" "content"
do
tn=${t: -1}
HTML_title=`
printf '%s%s%s\n' \
"<h$tn class=\"${site_css}_title ${site_css}_title-$tn\">" \
"$content" \
"</h$tn>"`
sed -i "${ln}s^.*^$HTML_title^" "$1"
done <<<"$gsl_line"
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Make HTML paragraphs
# $1: marker open
# $2: marker close
# $3: file
#======================================================================
make__paragraphs() {
[[ `grep "^$2$" "$3"` ]] \
&& sed -i "s,^$2$,$HTML_p_close,g" "$3" \
|| return
while read -r "lnpm" "class"
do
ln=`awk -F: '{print $1}' <<<$lnpm`
pm=`awk -F: '{print $2}' <<<$lnpm`
if [[ $class ]];then
HTML_p="<p class=\"${site_css}_p $class\">"
sed -i "${ln}s^$pm $class^$HTML_p^" "$3"
else
HTML_p="<p class=\"${site_css}_p\">"
sed -i "${ln}s^$pm^$HTML_p^" "$3"
fi
done < <(grep -n '^($\|^'"$1" "$3")
2022-02-19 18:17:09 +01:00
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Convert new line "|" to <br /> ($HTML_br)
# $1: marker
# $2: file
#======================================================================
make__br() {
[[ `grep "^$1$" "$2"` ]] \
&& sed -i "s,^$1$,$HTML_br,g" "$2"
}
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# HTML abbr: SHORT must have 1 space before/after, or both
# $1: file header
# $2: file post
#======================================================================
make__abbrs() {
! [[ "$header_f1" ]] && return
2022-02-21 17:25:08 +01:00
2022-06-25 12:30:54 +02:00
[[ "$header_f3" ]] \
&& abbr_word=${header_f1,,} \
|| abbr_word="$header_f1"
2022-06-14 18:51:19 +02:00
abbr_title="title=\"$header_f2\""
abbr_class="class=\"${site_css}_abbr\""
2022-06-25 12:30:54 +02:00
abbr_words="<abbr $abbr_class $abbr_title>$abbr_word</abbr>"
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
sed -i "s^ $header_f1 ^ $abbr_words ^g" "$2"
sed -i "s^$header_f1 ^$abbr_words ^g" "$2"
sed -i "s^ $header_f1^ $abbr_words^g" "$2"
}
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# HTML link: + to open in new window
# $1: file post
# $2: mark type
#======================================================================
make__links() {
! [[ "$header_f1" ]] && return
[[ "$header_f3" ]] \
&& link_title=" title=\"$header_f3\""
# link or flink
case "$2" in
"link")
mt="$gsl_mark_link"
cssn="link"
unset luri
;;
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
"flink")
mt="$gsl_mark_flink"
cssn="link-file"
luri="${srv_uri}files/"
;;
esac
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
link_class="class=\"${site_css}_$cssn\""
link_class2="class=\"${site_css}_$cssn ${site_css}_$cssn-window\""
link_words=`
printf '%s%s%s\n' \
"<a $link_class href=\"$luri$header_f2\"" \
"$link_title>" \
"$header_f1</a>"`
link_words2=`
printf '%s%s%s\n' \
"<a target=\"_blank\" $link_class2 href=\"$luri$header_f2\"" \
"$link_title>" \
"$header_f1</a>"`
sed -i "s^$mt${header_f1}+^$link_words2^g" "$1"
sed -i "s^$mt$header_f1^$link_words^g" "$1"
}
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# HTML code : create tmp file with source code
# converted in HTML version with <pre>, and replace mark with tmp file
# $1: file post
#======================================================================
make__file_codes() {
pre_class="class=\"${site_css}_code-block ${site_css}_code-block-$header_f1\""
pre_css_line="class=\"${site_css}_code-line\""
pre_css_content="class=\"${site_css}_code-content\""
pre_css_source="class=\"${site_css}_code-link\""
pre_css_p="class=\"${site_css}_code-p\""
# No Alt-Text ; generate
if [[ "$header_f3" ]];then
pre_title=" title=\"Code: source\""
else
header_f3="Code: source"
fi
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
gsl_tmp_code=`mktemp`
cat << EOCODE > "$gsl_tmp_code"
<pre $pre_class>
$(while read -r "code_ln" "code_content"
do
printf '%2s%s%s\n' "" \
"<span $pre_css_line>$code_ln</span>" \
"<span $pre_css_content>$code_content</span>"
done < <(cat -n "$gsl_dir_domain_files/$header_f2"))
</pre>
2022-06-18 18:02:14 +02:00
<div $pre_css_p>
2022-06-14 18:51:19 +02:00
<a $pre_css_source
target="_blank"
href="${srv_uri}files/$header_f2"$pre_title>
$header_f3
</a>
2022-06-18 18:02:14 +02:00
</div>
2022-06-14 18:51:19 +02:00
EOCODE
# for/from make__file_codes (Replace mark till no more)
# $1: file post
#-------------------------------------------------
make__file_codes_replace() {
lncode=`
grep -n "$gsl_mark_fcode:$header_f1" "$1" \
| head -n1 \
| awk -F: '{print $1}'`
[[ "$lncode" ]] || return
sed -i "${lncode}r $gsl_tmp_code" "$1"
sed -i "${lncode}d" "$1"
make__file_codes_replace "$1"
}
2022-02-21 17:25:08 +01:00
2022-06-14 18:51:19 +02:00
make__file_codes_replace "$1"
rm -f "$gsl_tmp_code"
2022-02-21 17:25:08 +01:00
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Replace marks with brut file. Must be done at the end !
# $1: file post
#======================================================================
make__file_bruts() {
lncode=`
grep -n "$gsl_mark_fbrut:$header_f1" "$1" \
| head -n1 \
| awk -F: '{print $1}'`
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
[[ "$lncode" ]] || return
2022-02-19 18:17:09 +01:00
2022-06-14 18:51:19 +02:00
sed -i "${lncode}r $gsl_dir_domain_files/$header_f2" "$1"
sed -i "${lncode}d" "$1"
make__file_bruts "$1"
2022-02-19 18:17:09 +01:00
}
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
#======================================================================
# Make images
# $1: file post
#======================================================================
make__file_images() {
2022-06-23 12:24:01 +02:00
unset ${!image_@}
link_class="${site_css}_image-link"
this_image=`grep -n "$gsl_mark_image:$header_f1" "$1" | head -n 1`
2022-06-14 18:51:19 +02:00
[[ "$this_image" ]] || return
2022-06-23 12:24:01 +02:00
# local link with "+" or external link if http*
# $1: field
make__file_image_link() {
case "$1" in
"+") image_link="${srv_uri}images/$header_f2" ;;
"http"*|"ftp"*) image_link="$image_field_link" ;;
esac
}
2022-06-14 18:51:19 +02:00
2022-06-18 12:16:52 +02:00
mark_image=${this_image#*:} # Get content mark to replace
2022-06-14 18:51:19 +02:00
while IFS=: read -r "ln" \
"marker" \
2022-06-14 18:51:19 +02:00
"f1" \
"class" \
"width" \
"height" \
"target"
2022-03-02 14:27:50 +01:00
do
2022-06-23 12:24:01 +02:00
# Class
if [[ "$class" ]];then
image_field_link="$class$width"
case "$class" in
R|r|D|d) image_class="${site_css}_image-right" ;;
G|g|L|l) image_class="${site_css}_image-left" ;;
C|c|D|d) image_class="${site_css}_image-center" ;;
2022-04-11 18:06:38 +02:00
2022-06-23 12:24:01 +02:00
# Use this class if not known target
*)
make__file_image_link "$class"
if [[ $image_link ]];then
image_class="${site_css}_image-center"
unset width height
else
image_class="$class"
link_class+=" $class"
fi
;;
esac
else
image_class="${site_css}_image-center"
fi
2022-06-23 12:24:01 +02:00
# Width
if [[ "$width" ]];then
image_field_link="$width$height"
make__file_image_link "$width"
if [[ $image_link ]];then
unset width height target
else
image_width=`
grep -Eo '[[:alpha:]]+|[0-9]+' \
<<<"$width" \
| head -n 1`
if (( $image_width == 0 ));then
unset width
else
image_unitw=${width/$image_width/}
! [[ "$image_unitw" ]] && image_unitw="px"
fi
fi
fi
2022-06-23 12:24:01 +02:00
# Height
if [[ "$height" ]];then
image_field_link="$height$target"
make__file_image_link "$height"
if [[ $image_link ]];then
unset height target
else
image_height=`
grep -Eo '[[:alpha:]]+|[0-9]+' \
<<<"$height" \
| head -n 1`
if (( $image_height == 0 ));then
unset height
else
image_unith=${height/$image_height/}
! [[ "$image_unith" ]] && image_unith="px"
fi
fi
fi
# Target
if [[ "$target" ]];then
image_field_link="$target"
make__file_image_link "$target"
fi
# Create HTML width & height for <img ...
2022-06-15 17:22:25 +02:00
if [[ "$height" && "$width" ]];then
2022-06-23 12:24:01 +02:00
image_style=`
printf ' %s%s%s\n' \
"style=\"" \
"width:$image_width$image_unitw;" \
"height:$image_height$image_unith;\""`
2022-06-15 17:22:25 +02:00
elif [[ "$width" ]];then
2022-06-23 12:24:01 +02:00
image_style=`
printf ' %s%s\n' \
"style=\"" \
"width:$image_width$image_unitw;\""`
2022-06-15 17:22:25 +02:00
elif [[ "$height" ]];then
2022-06-23 12:24:01 +02:00
image_style=`
printf ' %s%s\n' \
"style=\"" \
"height:$image_height$image_unith;\""`
2022-06-15 17:22:25 +02:00
fi
2022-06-23 12:24:01 +02:00
# Create HTML
image_css="class=\"${site_css}_image $image_class\""
image_src="src=\"${srv_uri}images/$header_f2\""
image_alt="alt=\"$header_f3\" title=\"$header_f3\""
2022-06-14 18:51:19 +02:00
HTML_image=`
printf '%s%s\n' \
"<img $image_css $image_src $image_alt" \
2022-06-15 17:22:25 +02:00
"$image_style />"`
2022-06-23 12:24:01 +02:00
if [[ "$image_link" ]];then
link_css="class=\"$link_class\""
2022-06-14 18:51:19 +02:00
HTML_image=`
2022-06-15 17:22:25 +02:00
printf '%s%s%s\n' \
2022-06-23 12:24:01 +02:00
"<a $link_css href=\"$image_link\">" \
2022-06-14 18:51:19 +02:00
"$HTML_image" \
"</a>"`
fi
2022-06-23 12:24:01 +02:00
sed -i "${ln}s^$mark_image^$HTML_image^" "$1"
2022-06-14 18:51:19 +02:00
done <<<"$this_image"
2022-06-14 18:51:19 +02:00
make__file_images "$1"
2022-02-27 19:16:16 +01:00
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Lists (independant module)
# repeat for each ^>> found
# Put bloc list in a file: gsl_tmp_list_brut
# Convert list to HTML in a new file: gsl_tmp_list_HTML
# Replace gsl bloc with new file
# $1: file
#======================================================================
make__lists() {
# Check for last bloc Item list
[[ `grep '^>>' "$1"` ]] || return
unset mark list mn sign muo_class my_class
# Define start and close line number
list_ln_start=`grep -n "^<<" "$1" | head -n 1 | awk -F: '{print $1}'`
list_ln_close=`grep -n "^>>" "$1" | head -n 1 | awk -F: '{print $1}'`
#----------------------------------------------------------------------
# Put gsl block list in tmp file
#----------------------------------------------------------------------
gsl_tmp_list_brut=`mktemp`
awk -v lns="$list_ln_start" -v lnc="$list_ln_close" \
'NR >= lns && NR <= lnc {print}' \
"$1" \
> "$gsl_tmp_list_brut"
# File to print HTML List
gsl_tmp_list_HTML=`mktemp`
# Define CSS class
li_class="${site_css}_li ${site_css}_li-"
uo_class="${site_css}_list ${site_css}_list-"
# Custom class for bloc only
my_class=`awk 'NR == 1 {print $2}' "$gsl_tmp_list_brut"`
[[ $my_class ]] \
&& muo_class=" ${site_css}_list-$my_class ${site_css}_list-$my_class-"
#----------------------------------------------------------------------
# Define list in arrays
#----------------------------------------------------------------------
i=0;l=0
while read -r "ln" "mark" "content"
do
((i++))
mark[$i]="${mark}"
sign[$i]="${mark:0:1}"
line[$i]="$ln"
mn[$i]="${#mark}"
case "$mark" in
"="*) list[$i]="ul" ;;
"+"*) list[$i]="ol" ;;
esac
2022-06-28 22:56:48 +02:00
done < <(awk '($1 ~ "=" || $1 ~ "+" || $1 ~ ">>") \
2022-06-14 18:51:19 +02:00
{print NR,$0}' \
"$gsl_tmp_list_brut")
# Generic prints li
# -----------------
make__list_li() {
printf "%$((sp + 2))s%s\n" "" \
"<li class=\"$li_class${mn[$n]}\">${content[$n]}</li>" \
| awk -v sp="$((sp+2))" \
'NR == 1 {print $0};NR > 1 {printf "%" sp "s%s\n", "", $0}' \
>> "$gsl_tmp_list_HTML"
}
2022-06-14 18:51:19 +02:00
# Generic print ul | ol (open current)
# ------------------------------------
make__list_open_n() {
l=$(( l + 1 ))
printf "%${sp}s%s\n" "" \
"<${list[n]}>" \
>> "$gsl_tmp_list_HTML"
}
#----------------------------------------------------------------------
# Define content items and make HTML list
#----------------------------------------------------------------------
for n in `seq 1 $i`
2022-02-27 19:16:16 +01:00
do
2022-06-14 18:51:19 +02:00
# Define content items for each list
content[$n]=`
awk -v cts="${line[$n]}" -v ctc="${line[$((n+1))]}" \
'NR >= cts && NR < ctc {print $0}' \
"$gsl_tmp_list_brut" \
| awk '{ sub(/^[ \t]+/, ""); print }'`
2022-06-14 18:51:19 +02:00
content[$n]=${content[$n]/${mark[$n]}/}
content[$n]=`awk '{sub(/^[ \t]+/, ""); print}' <<<"${content[$n]}"`
# Define HTML ul | ol from previous item list
# ----------------------------------------
# Define a11y tabulation for each item
sp=$(( ${mn[$n]} * 2 - 2 ))
2022-06-14 18:51:19 +02:00
# ----------
# First Item
# ----------
if (( $n == 1 ));then
uo_class+="${list[n]}"
[[ $my_class ]] \
&& muo_class+="${list[n]}"
l=$(( l + 1 ))
printf "%${sp}s%s\n" "" \
"<${list[n]} class=\"$uo_class$muo_class\">" \
>> "$gsl_tmp_list_HTML"
printf "%$((sp + 2))s%s\n" "" \
"<li class=\"${li_class}1\">${content[$n]}</li>" \
>> "$gsl_tmp_list_HTML"
# ---------
# Last Item
# ---------
elif (( $n == $i ));then
sp=$(( ${mn[$(( n - 1 ))]} * 2 - 2 ))
# ---------------------
# Same sign | Last Item
# ---------------------
if [[ ${sign[1]} == ${sign[$(( n - 1 ))]} ]];then
for c in `seq 1 ${mn[$(( n - 1 ))]}`
do
printf "%${sp}s%s\n" "" \
"</${list[l]}>" \
>> "$gsl_tmp_list_HTML"
sp=$(( sp - 2 ))
l=$(( l - 1 ))
done
# ---------------------
# Diff sign | Last Item
# ---------------------
else
printf "%${sp}s%s\n" "" \
"</${list[$(( n - 1 ))]}>" \
>> "$gsl_tmp_list_HTML"
l=$(( l - 1 ))
for c in `seq 1 ${mn[$(( n - 1 ))]}`
do
l=$(( l - 1 ))
sp=$(( sp - 2 ))
(( $sp < 0 )) && sp=0
printf "%${sp}s%s\n" "" \
"</${list[l]}>" \
>> "$gsl_tmp_list_HTML"
done
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# -----------
# Middle Item
# -----------
else
# Diff NBR between current and previous mark: mark difference
md=$(( ${mn[$n]} - ${mn[$((n - 1))]} ))
#echo "${mark[n]} | ${sign[n]} <==> ${mark[$(( n - 1 ))]} | ${sign[$(( n - 1 ))]}"
# ----------------------------
# Same Diff from previous Item
# ----------------------------
if (( $md == 0 ));then
# ---------------------
# Same sign | Same Item
# ---------------------
if [[ ${sign[n]} == ${sign[$(( n - 1 ))]} ]];then
make__list_li
# ---------------------
# Diff sign | Same Item
# ---------------------
else
make__list_open_n
make__list_li
fi
# -------------------------
# NEW Item UP from previous
# -------------------------
elif (( $md > 0 ));then
# -----------------------
# Same sign | New Item UP
# -----------------------
if [[ ${sign[n]} == ${sign[$(( n - 1 ))]} ]];then
make__list_open_n
make__list_li
# -----------------------
# Diff sign | New item UP
# -----------------------
else
make__list_open_n
make__list_li
fi
# ---------------------------
# New Item DOWN from previous
# ---------------------------
else
bsp=$(( ${mn[$(( n - 1 ))]} * 2 - 2 ))
# -------------------------
# Same sign | New Item Down
# -------------------------
if [[ ${sign[n]} == ${sign[$(( n - 1 ))]} ]];then
for c in `seq 1 ${md/-/}`
do
printf "%${bsp}s%s\n" "" \
"</${list[l]}>" \
>> "$gsl_tmp_list_HTML"
bsp=$(( bsp - 2 ))
l=$(( l - 1 ))
done
make__list_li
# -------------------------
# Diff sing | New Item Down
# -------------------------
else
l=$(( l + 1 ))
for c in `seq 1 $(( ${md/-/} + 1 ))`
do
printf "%${bsp}s%s\n" "" \
"</${list[$(( n - 1 ))]}>" \
>> "$gsl_tmp_list_HTML"
bsp=$(( bsp - 2 ))
l=$(( l - 1 ))
done
make__list_li
fi
fi
fi
done
# Delete source lines and insert HTML file
del_ln=`seq $list_ln_start $list_ln_close | wc -l`
for i in `seq 1 $del_ln`
do
sed -i "${list_ln_start}d" "$1"
done
sed -i "$((list_ln_start - 1))r$gsl_tmp_list_HTML" "$1"
rm -f "$gsl_tmp_list_brut"
rm -f "$gsl_tmp_list_HTML"
make__lists "$gsl_tmp_post"
}
#======================================================================
# Quotes (independant module)
# $1: file
#======================================================================
make__quotes() {
# Get block quote
unset ${!quote@} my_class ${!q_@}
while IFS=: read -r "ln" "mk"
do
[[ $quote_ln_start ]] \
&& quote_ln_close="$ln" \
|| quote_ln_start="$ln"
done < <(grep -n "^---" "$1" | head -n 2)
[[ $quote_ln_close ]] || return
# Put in a file brut block quote
gsl_tmp_quote_brut=`mktemp`
awk -v lns="$quote_ln_start" -v lnc="$quote_ln_close" \
'NR >= lns && NR <= lnc {print}' \
"$1" \
> "$gsl_tmp_quote_brut"
# Define custom CSS class
my_class=`awk 'NR == 1 {print $2}' "$gsl_tmp_quote_brut"`
[[ $my_class ]] \
&& my_class=" $my_class"
sed -i "1d" "$gsl_tmp_quote_brut"
sed -i "`cat "$gsl_tmp_quote_brut" | wc -l`d" "$gsl_tmp_quote_brut"
# Get metadatas from quote
#-------------------------
make__quotes_set() {
grep "$1" "$gsl_tmp_quote_brut" | awk -F" : " '{print $2}'
}
2022-06-14 18:51:19 +02:00
# Delete useless line from source
#--------------------------------
make__quotes_rmln() {
[[ "$2" ]] || return
q_ln=`grep -n "$1" "$gsl_tmp_quote_brut" | awk -F: '{print $1}'`
sed -i "${q_ln}d" "$gsl_tmp_quote_brut"
}
q_link=`make__quotes_set '^_link : '` && \
make__quotes_rmln '^_link : ' "$q_link"
q_lang=`make__quotes_set '^_lang : '` && \
make__quotes_rmln '^_lang : ' "$q_lang"
q_auth=`make__quotes_set '^_cite : '` && \
make__quotes_rmln '^_cite : ' "$q_auth"
q_book=`make__quotes_set '^_book : '` && \
make__quotes_rmln '^_book : ' "$q_book"
q_year=`make__quotes_set '^_year : '` && \
make__quotes_rmln '^_year : ' "$q_year"
# Put in a file HTML quote
gsl_tmp_quote_HTML=`mktemp`
[[ "$q_auth" ]] && q_ref="$q_auth "
[[ "$q_book" ]] && q_book="- $q_book"
[[ "$q_year" ]] && q_year="($q_year)"
# Define HTML
[[ "$q_link" ]] && q_HTML_link="href=\"$q_link\" target=\"_blank\""
[[ "$q_lang" ]] && q_HTML_lang=" lang=\"$q_lang\""
[[ "$q_link" ]] && q_HTML_cite=" cite=\"$q_link\""
q_CSS="class=\"${site_css}_quote$my_class\""
q_CSS_fig="class=\"${site_css}_quote-fig$my_class\""
q_CSS_link="class=\"${site_css}_quote-link\""
if [[ "$q_book" && "$q_year" ]];then
q_ref+="$q_book$q_year"
q_data=" $q_book$q_year"
q_TITLE=" title=\"$q_ref\""
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
elif [[ "$q_book" ]] && ! [[ "$q_year" ]];then
q_ref+="$q_book"
q_data=" $q_book"
q_TITLE=" title=\"$q_ref\""
elif [[ "$q_year" ]] && ! [[ "$q_book" ]];then
q_ref+="$q_year"
q_data=" $q_year"
q_TITLE=" title=\"$q_ref\""
fi
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Make HTML file
if [[ "$q_auth" ]];then
# case figure
cat <<EOQUOTE > "$gsl_tmp_quote_HTML"
<figure $q_CSS_fig>
<blockquote$q_HTML_lang$q_HTML_cite>
$(while read -r "line"
do
printf '%4s%s\n' "" "$line"
done < <(cat "$gsl_tmp_quote_brut"))
</blockquote>
<figcaption>
<cite>
<a $q_HTML_link$q_TITLE>$q_auth</a>$q_data
</cite>
</figcaption>
</figure>
EOQUOTE
else
# Simple quote
cat <<EOQUOTE > "$gsl_tmp_quote_HTML"
<blockquote $q_CSS$q_HTML_lang$q_HTML_cite$q_TITLE>
$(while read -r "line"
do
printf '%4s%s\n' "" "$line"
done < <(cat "$gsl_tmp_quote_brut"))
</blockquote>
EOQUOTE
fi
# Remove source lines and insert HTML file
del_ln=`seq $quote_ln_start $quote_ln_close | wc -l`
for i in `seq 1 $del_ln`
do
sed -i "${quote_ln_start}d" "$1"
done
sed -i "$((quote_ln_start - 1))r$gsl_tmp_quote_HTML" "$1"
#cat "$gsl_tmp_quote_brut"
rm -f "$gsl_tmp_quote_brut"
rm -f "$gsl_tmp_quote_HTML"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
make__quotes "$gsl_tmp_post"
2022-02-27 19:16:16 +01:00
}
2022-06-14 18:51:19 +02:00
#======================================================================
# div container between titles
# $1: file
#======================================================================
make__div_title() {
max_lines=`cat "$1" | wc -l`
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
# Mark if betwee
while IFS=: read -r "ln" "content"
2022-02-27 19:16:16 +01:00
do
2022-06-14 18:51:19 +02:00
[[ $title_start ]] \
&& title_close="$ln" \
|| title_start="$ln"
2022-04-23 17:51:46 +02:00
2022-06-14 18:51:19 +02:00
! [[ $title_close ]] && continue
if [[ -z `awk -v lns="$title_start" -v lnc="$title_close" \
'NR > lns && NR < lnc' "$1"` ]];then
sed -i -e "${title_start}s|^|NODIV|" "$1"
else
sed -i -e "${title_close}s|$|ENDIV|" "$1"
2022-02-27 19:16:16 +01:00
fi
2022-06-14 18:51:19 +02:00
title_start=$title_close;unset title_close
done < <(grep "^<h" -n "$1")
2022-06-14 18:51:19 +02:00
# Add div after title
n=0
while IFS=: read -r "ln" "content"
do
(( n++ ))
tn=${content:2:1}
2022-06-15 16:15:44 +02:00
div_title="<div class=\"${site_css}_content ${site_css}_content-h$tn\">"
2022-06-14 18:51:19 +02:00
sed -i "$(( ln + n ))i$div_title" "$1"
done < <(grep "^<h" -n "$1")
n=1
# add /div before title
while IFS=: read -r "ln" "content"
do
2022-06-14 18:51:19 +02:00
sed -i "$(( ln + n -1 ))i</div>" "$1"
(( n++ ))
done < <(grep -n 'ENDIV$' "$1")
echo "</div>" >> "$1"
sed -i "s^NODIV^^g" "$1"
sed -i "s^ENDIV^^g" "$1"
}
2022-06-28 22:56:48 +02:00
#======================================================================
# bsis: Search all lines for bsis mark
# $1: file (gsl_tmp_post)
#======================================================================
make__bsis_search() {
while read -r "ln" "gsl_line"
do
case "$gsl_line" in
*"$gsl_mark_bold"*|\
*"$gsl_mark_strike"*|\
*"$gsl_mark_em"*|\
*"$gsl_mark_del"*|\
*"$gsl_mark_strong"*)
make__bsis_convert "$ln" "$1"
;;
esac
done < <(cat -n "$1")
}
#======================================================================
# Called from make__bsis_search
# bsis: Read each letter from line, excluding ones inside inline_code
# $1: line number
# $2: file (gsl_tmp_post)
#======================================================================
make__bsis_convert() {
for (( i=0; i<${#gsl_line}; i++ ))
do
case "${gsl_line:$i:1}" in
"$gsl_mark_icode")
if [[ $code_open ]];then
unset code_open
else
code_open=true
fi
;;
"$gsl_mark_bold")
[[ $code_open ]] && continue
if [[ $bold_open ]];then
sed -i -r "$1s|^(.{"$i"})"'\*'"|\1$bold_close|" "$2"
unset bold_open
else
sed -i -r "$1s|^(.{"$i"})"'\*'"|\1$bold_start|" "$2"
bold_open=true
article_has_bold=true
fi
;;
"$gsl_mark_cross")
[[ $code_open ]] && continue
if [[ $cross_open ]];then
sed -i -r "$1s|^(.{"$i"})"$gsl_mark_cross"|\1$cross_close|" "$2"
unset cross_open
else
sed -i -r "$1s|^(.{"$i"})"$gsl_mark_cross"|\1$cross_start|" "$2"
cross_open=true
article_has_cross=true
fi
;;
"$gsl_mark_del")
[[ $code_open ]] && continue
if [[ $del_open ]];then
sed -i -r "$1s|^(.{"$i"})"$gsl_mark_del"|\1$del_close|" "$2"
unset del_open
else
sed -i -r "$1s|^(.{"$i"})"$gsl_mark_del"|\1$del_start|" "$2"
del_open=true
article_has_del=true
fi
;;
"$gsl_mark_em")
[[ $code_open ]] && continue
if [[ $em_open ]];then
sed -i -r "$1s|^(.{"$i"})"'\\'"|\1$em_close|" "$2"
unset em_open
else
sed -i -r "$1s|^(.{"$i"})"'\\'"|\1$em_start|" "$2"
em_open=true
article_has_em=true
fi
;;
"$gsl_mark_strong")
[[ $code_open ]] && continue
if [[ $strong_open ]];then
sed -i -r "$1s|^(.{"$i"})"'¤'"|\1$strong_close|" "$2"
unset strong_open
else
sed -i -r "$1s|^(.{"$i"})"'¤'"|\1$strong_start|" "$2"
strong_open=true
article_has_strong=true
fi
;;
esac
done
}
#======================================================================
# bsis: Convert specific characters to HTML
# $1: file (gsl_tmp_post)
#======================================================================
make__bsis() {
if [[ $article_has_bold ]];then
HTML_bold_start="<b class=\"${site_css}_bold\">"
sed -i "s^$bold_start^$HTML_bold_start^g" "$1"
sed -i "s^$bold_close^</b>^g" "$1"
fi
if [[ $article_has_em ]];then
HTML_em_start="<i class=\"${site_css}_em\">"
sed -i "s^$em_start^$HTML_em_start^g" "$1"
sed -i "s^$em_close^</i>^g" "$1"
fi
if [[ $article_has_cross ]];then
HTML_cross_start="<span class=\"${site_css}_cross\">"
sed -i "s^$cross_start^$HTML_cross_start^g" "$1"
sed -i "s^$cross_close^</span>^g" "$1"
fi
if [[ $article_has_del ]];then
HTML_del_start="<del class=\"${site_css}_del\">"
sed -i "s^$del_start^$HTML_del_start^g" "$1"
sed -i "s^$del_close^</del>^g" "$1"
fi
if [[ $article_has_strong ]];then
HTML_strong_start="<strong class=\"${site_css}_strong\">"
sed -i "s^$strong_start^$HTML_strong_start^g" "$1"
sed -i "s^$strong_close^</strong>^g" "$1"
fi
}
#======================================================================
# inline-code: Read each letter from line, convert to specific character
# $1: file (gsl_tmp_post)
#======================================================================
make__icode_convert() {
while read -r "ln" "gsl_line"
do
case "$gsl_line" in
*"$gsl_mark_icode"*)
for (( i=0; i<${#gsl_line}; i++ ))
do
case "${gsl_line:$i:1}" in
"$gsl_mark_icode")
if [[ $icode_open ]];then
sed -i -r "${ln}s|^(.{"$i"})"$gsl_mark_icode"|\1$icode_close|" "$1"
unset icode_open
else
sed -i -r "${ln}s|^(.{"$i"})"$gsl_mark_icode"|\1$icode_start|" "$1"
icode_open=true
article_has_icode=true
fi
;;
esac
done
;;
esac
done < <(cat -n "$1")
}
#======================================================================
# inline-code: Convert specific characters to HTML <code>
# $1: file (gsl_tmp_post)
#======================================================================
make__icode() {
if [[ $article_has_icode ]];then
HTML_icode_start="<code class=\"${site_css}_icode\">"
sed -i "s^$icode_start^$HTML_icode_start^g" "$1"
sed -i "s^$icode_close^</code>^g" "$1"
fi
}