156 lines
6.0 KiB
Plaintext
156 lines
6.0 KiB
Plaintext
if [[ ${globaldebug} == "true" ]]; then
|
|
local debug=true
|
|
else
|
|
local debug=false
|
|
fi
|
|
|
|
_msg main "${0:t}_msg_3"
|
|
if (${debug}) _msg debug "${0:t}_msg_1"
|
|
_list_blogs
|
|
|
|
if [[ ${no_blogs_found} == "true" ]]; then
|
|
_msg sub "${0:t}_msg_2"
|
|
return
|
|
fi
|
|
if (${debug}) _msg debug "${0:t}_msg_4"
|
|
_blog_cache
|
|
|
|
if (( ${#make_blog_array[@]} > 0 )); then
|
|
BLOG_META_STR_ARRAY=()
|
|
|
|
if [[ -f ${config[project_root]}/themes/${config[site_theme]}/blogs.tpl ]]; then
|
|
local blog_tpl=$(<"${config[project_root]}/themes/${config[site_theme]}/blogs.tpl")
|
|
else
|
|
_msg info "${0:t}_msg_5"
|
|
exit
|
|
fi
|
|
|
|
for blog in "${make_blog_array[@]}"; do
|
|
if (${debug}) _msg info "*************************************************************************"
|
|
if (${debug}) _msg info "**************************FOR LOOP START*********************************"
|
|
if (${debug}) _msg info "*************************************************************************"
|
|
if (${debug}) _msg debug "${0:t}_msg_6" " ${blog}"
|
|
|
|
local content="$(<"${blog}")"
|
|
local sdate btitle ingress body blog_index blog_dir blog_url
|
|
local date_found=false
|
|
local title_found=false
|
|
while IFS= read -r line
|
|
do
|
|
if [[ "${line}" == "DATE "* ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_7"
|
|
date_found=true
|
|
fi
|
|
if [[ "${line}" == "BLOG_TITLE "* ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_8"
|
|
title_found=true
|
|
fi
|
|
if [[ "${date_found}" == true && "${title_found}" == true ]]; then
|
|
break
|
|
fi
|
|
done <<< "${content}"
|
|
if [[ "${date_found}" == false ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_9" " ${blog}."
|
|
continue
|
|
fi
|
|
if [[ "${title_found}" == false ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_10" " ${blog}."
|
|
continue
|
|
fi
|
|
sdate=( $( echo ${content} | grep DATE | sed "s|DATE\ ||" | sed "s|\-|\ |g" ) )
|
|
if [[ ${config[project_generator]} == "native" ]]; then
|
|
if (${debug}) _msg debug "* qstags: Fetching BLOG_TITLE"
|
|
while IFS= read -r line; do
|
|
if [[ "$line" == "BLOG_TITLE "* ]]; then
|
|
btitle="${line#BLOG_TITLE }"
|
|
break
|
|
fi
|
|
done <<< "$content"
|
|
elif [[ ${config[project_generator]} == "markdown" ]]; then
|
|
if (${debug}) _msg debug "* markdown: Fetching BLOG_TITLE"
|
|
while IFS= read -r line; do
|
|
if [[ "$line" == \#* ]]; then
|
|
btitle="${line#\#}"
|
|
btitle="${btitle#\#}"
|
|
btitle="${btitle#"${btitle%%[![:space:]]*}"}"
|
|
break
|
|
fi
|
|
done <<< "$content"
|
|
fi
|
|
if (${debug}) _msg debug "* Fetching INGRESS"
|
|
ingress=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#INGRESS_START\K(.*?)#INGRESS_STOP" | sed "s|\ \#INGRESS_STOP||" | sed "s|^\ ||" )
|
|
if (${debug}) _msg debug "* Fetching BODY"
|
|
body=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#BODY_START\K(.*?)#BODY_STOP" | sed "s|\ \#BODY_STOP||" | sed "s|^\ ||" )
|
|
|
|
blog_index=$(echo "${btitle:l}" | sed 's/ /_/g; s/,//g; s/\.//g; s/://g; s/[()]//g')
|
|
|
|
blog_dir="/blog/${sdate[2]}/${sdate[3]:l}/${sdate[4]}"
|
|
blog_url="${blog_dir}/${blog_index}.html"
|
|
|
|
if (${debug}) _msg debug "${0:t}_msg_11" " ${blog} " "${0:t}_msg_11.1"
|
|
local metadata_str="SDATE: ${sdate[@]}||BTITLE: ${btitle}||INGRESS: ${ingress}||URL: ${blog_url}"
|
|
BLOG_META_STR_ARRAY+=("${metadata_str}")
|
|
|
|
if (${debug}) _msg debug "${0:t}_msg_12" " ${blog}"
|
|
|
|
_msg std " - ${btitle}"
|
|
if (${debug}) _msg debug "${0:t}_msg_14" " ${blog}"
|
|
local blog_content=$(
|
|
echo "${blog_tpl}" | \
|
|
perl -pe "\
|
|
s|BLOGTITLE|${btitle}|g; \
|
|
s|BLOGURL|${blog_url}|g; \
|
|
s|\QINGRESS\E|${ingress}|g; \
|
|
s|\QBODY\E|${body}|g \
|
|
")
|
|
blog_content="${blog_content//CALNDAY/${sdate[4]}}"
|
|
blog_content="${blog_content//CALYEAR/${sdate[2]}}"
|
|
blog_content="${blog_content//CALMONTH/${sdate[3]}}"
|
|
blog_content="${blog_content//CALADAY/${sdate[1]}}"
|
|
|
|
if (${debug}) _msg debug "${0:t}_msg_15" " ${engine} " "${0:t}_msg_15_1" " ${blog}"
|
|
blog_content=$( _run_engine "${blog_content}" )
|
|
if (${debug}) _msg debug "${0:t}_msg_16"
|
|
if [[ $( echo ${blog_content} | grep \#link ) ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_17"
|
|
blog_content=$(_link "${blog_content}")
|
|
fi
|
|
if [[ $( echo ${blog_content} | grep \#showimg ) ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_18"
|
|
blog_content=$(_image "${blog_content}")
|
|
fi
|
|
if [[ $( echo ${blog_content} | grep \#ytvideo ) ]]; then
|
|
if (${debug}) _msg debug "${0:t}_msg_19"
|
|
blog_content=$(_youtube "${blog_content}")
|
|
fi
|
|
if (${debug}) _msg debug "${0:t}_msg_20"
|
|
blog_content=$( echo ${blog_content} | perl -pe "s|#tagline|${config[site_tagline]}|gs; s|#sitename|${config[site_name]}|gs; s|#pagetitle|${page_title}|gs" )
|
|
|
|
if (${debug}) _msg debug "* Running _last_updated"
|
|
blog_content=$(_last_updated "${blog_content}")
|
|
if (${debug}) _msg debug "* Running _cleanup"
|
|
blog_content=$(_cleanup "${blog_content}")
|
|
if (${debug}) _msg debug "${0:t}_msg_21" " ${config[site_root]}${blog_dir}"
|
|
[[ ! -d "${config[site_root]}/${blog_dir}" ]] && mkdir -p "${config[site_root]}/${blog_dir}"
|
|
if (${debug}) _msg debug "${0:t}_msg_22" " ${config[site_root]}${blog_url}"
|
|
echo "${blog_content}" > "${config[site_root]}${blog_url}"
|
|
|
|
unset sdate btitle ingress body blog_index blog_dir blog_url
|
|
|
|
done
|
|
export BLOG_META_STR_ARRAY
|
|
if (${debug}) _msg debug "${0:t}_msg_23"
|
|
export new_updated_blogs=true
|
|
|
|
else
|
|
_msg sub "${0:t}_msg_24"
|
|
export new_updated_blogs=false
|
|
fi
|
|
|
|
if [[ ${new_updated_blogs} == "true" ]]; then
|
|
if (${debug}) _msg sub "${0:t}_msg_25"
|
|
_blog_idx_for_index
|
|
if (${debug}) _msg sub "${0:t}_msg_26"
|
|
_blog_index
|
|
fi
|