#!/bin/bash # file: gsl__post_makers # Folder: /var/lib/gsl/scripts # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #======================================================================= # --------- # MAIN CALL # --------- #======================================================================= #======================================================================= # From: gsl__loop_posts | Convert Post from modules to HTML #======================================================================= gsl__post_all_makers() { clear unset gsl_check_done gsl__prepare_makers echo "# Great, let's begin with Block Code..." gsl__check_bcodes gsl__check_cites cat "$gsl_uri_tmp_post" } #======================================================================= # --------------------------------------------- # Tools and prepapre tmp file from CONTENT Post # --------------------------------------------- #======================================================================= #======================================================================= # Get line nbr from TMP CONTENT Post... $1: TERM | $2: File #======================================================================= gsl__get_mark_content_line() { awk -v s="$1" \ '$0 ~ s {print NR}' \ "$2" || return } #======================================================================= # Get NEEDED infos, and create TMP file from CONTENT #======================================================================= gsl__prepare_makers() { # Getting NEEDED infos gsl_post_begin=` grep -n "#1" $gsl_post \ | head -1 \ | awk -F: '{print $1}'` source "$gsl_this_conf_domain/$gsl_find_domain.conf" # Create TMP file from CONTENT gsl_dir_tmp="/tmp/gsl" gsl_file_tmp_post_content="post_content" gsl_uri_tmp_post="$gsl_dir_tmp/$gsl_file_tmp_post_content" mkdir -p "$gsl_dir_tmp" echo "" > "$gsl_uri_tmp_post" awk -v l="$gsl_post_begin" \ 'NR >= l' \ "$gsl_post" \ > "$gsl_uri_tmp_post" } #======================================================================= # --------------------------------- # Check if Convert is needed and do # --------------------------------- #======================================================================= #======================================================================= # Find BLOCK-CODES #======================================================================= gsl__check_bcodes() { gsl_lines_nbr=(` gsl__get_mark_content_line \ "$gsl_mark_code" \ "$gsl_uri_tmp_post"`) ! [[ "$gsl_lines_nbr" ]] \ && return for i in `seq 1 ${#gsl_lines_nbr[@]}` do gsl__post_maker_bcode done } #======================================================================= # Find BLOCKQUOTES #======================================================================= gsl__check_cites() { gsl_lines_nbr=(` gsl__get_mark_content_line \ "$gsl_mark_blockquote" \ "$gsl_uri_tmp_post"`) ! [[ "$gsl_lines_nbr" ]] \ && return echo "BQ: ${gsl_lines_nbr[@]}" for i in `seq 1 ${#gsl_lines_nbr[@]}` do if [[ "$gsl_cite_start" ]];then unset gsl_cite_start echo "> BQ C:${gsl_lines_nbr[$((i-1))]}" gsl_cite_line_stop=${gsl_lines_nbr[(($i-1))]} gsl__post_maker_cite else gsl_cite_start=true echo "> BQ O:${gsl_lines_nbr[(($i-1))]}" gsl_cite_line_start=${gsl_lines_nbr[(($i-1))]} fi done } #======================================================================= # ----------------------------------------------- # Convert To HTML in duplicated CONTENT Post File # ----------------------------------------------- #======================================================================= #======================================================================= # Replace gsl_mark_code #======================================================================= gsl__post_maker_bcode() { # Get mark line nbr gsl_line_nbr=` gsl__get_mark_content_line \ "$gsl_mark_code" \ "$gsl_uri_tmp_post" | head -1` #--------- # Convert #--------- gsl_css_class="${gsl_site_css}_block-code" gsl_header_content_line=`gsl__get_header "$gsl_marker_code" "$gsl_post"` gsl_file_tmp_code=`mktemp` # Set gsl_post_header_field_1 gsl_post_header_field_2 gsl__get_header_fields "$gsl_marker_code" printf '%s %s\n%b\n%s\n' \ "
" \ "$(cat -n "$gsl_dir_domain_files/$gsl_post_header_field_2")" \ "" \ > "$gsl_file_tmp_code" sed -i "${gsl_line_nbr}r $gsl_file_tmp_code" "$gsl_uri_tmp_post" sed -i "${gsl_line_nbr}d" "$gsl_uri_tmp_post" rm -f "$gsl_file_tmp_code" } #======================================================================= # Convert & replace this blockquote #======================================================================= gsl__post_maker_cite() { echo "Block: $gsl_cite_line_start > $gsl_cite_line_stop" # Put Blockquote in a file and get DATAS gsl_file_tmp_cite=`mktemp` # Put Blockquote CONTENT only in this file gsl_file_tmp_cite_content=`mktemp` # Put HTML blockquote in this file gsl_file_tmp_cite_html=`mktemp` awk -v o="$gsl_cite_line_start" -v c="$gsl_cite_line_stop" \ 'NR >= o && NR <= c' \ "$gsl_uri_tmp_post" \ > "$gsl_file_tmp_cite" while read -r "gsl_content_line" do case "$gsl_content_line" in ---*) continue ;; _cite*) gsl_bq_author=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` ;; _book*) gsl_bq_book=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` ;; _lang*) gsl_bq_lang=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` ;; _year*) gsl_bq_year=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` ;; _link*) gsl_bq_link=`awk -F" : " '{print $2}' <<< "$gsl_content_line"` ;; *) echo " $gsl_content_line" >> "$gsl_file_tmp_cite_content" ;; esac done < <(cat "$gsl_file_tmp_cite") #echo "D> Auteur: $gsl_bq_author" #echo "D> Book : $gsl_bq_book" #echo "D> lang : $gsl_bq_lang" #echo "D> year : $gsl_bq_year" #echo "D> link : $gsl_bq_link" rm -f "$gsl_file_tmp_cite" # Convert DATAS and put HTML code in a file gsl_file_tmp_cite=`mktemp` if [[ "$gsl_bq_author" ]];then gsl_css_class="class=\"${gsl_site_css}_quote\"" # In a function... [[ "$gsl_bq_lang" ]] \ && gsl_html_cite_lang=" lang=\"$gsl_bq_lang\"" [[ "$gsl_bq_link" ]] \ && gsl_html_cite_link=" cite=\"$gsl_bq_link\"" cat << EOCITE > "$gsl_file_tmp_cite_html" EOCITE # Insert blockquote file sed -i "${gsl_cite_line_stop}r $gsl_file_tmp_cite_html" "$gsl_uri_tmp_post" # Remove useless lines gsl_cite_total_lines=$(( $gsl_cite_line_stop - gsl_cite_line_start )) for i in `seq 0 $gsl_cite_total_lines` do sed -i "${gsl_cite_line_start}d" "$gsl_uri_tmp_post" done # No more BLOCKQUOTE CONTENT needed rm -f "$gsl_file_tmp_cite_content" # No more html blockquote file needed rm -f "$gsl_file_tmp_cite_html" else gsl_css_class="${gsl_site_css}_simple-quote" fi # No more DATAS needed for next if any unset ${!gsl_bq_@} }