Rewrite _blogs
This commit is contained in:
parent
f747a85856
commit
062d9d485d
123
qsgen2
123
qsgen2
@ -392,101 +392,86 @@ function _pages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _blogs() {
|
function _blogs() {
|
||||||
# This function generates the blog files
|
# Rewritten _blogs function
|
||||||
|
# This function either generates blog files or exports metadata based on the argument
|
||||||
|
|
||||||
local debug=true
|
local debug=true
|
||||||
|
local mode=${1} # If <something>", exports metadata; otherwise, creates blog posts
|
||||||
|
|
||||||
# Running function _list_blog
|
# Running function _list_blog
|
||||||
# It returns the array: blog_index_file_array
|
if (${debug}) echo "_blogs: Running function _list_blog"
|
||||||
echo "_blogs: Running function _list_blog"
|
|
||||||
_list_blog
|
_list_blog
|
||||||
# Running function _blog_cache
|
# Running function _blog_cache
|
||||||
# It returns the array: make_blog_array
|
if (${debug}) echo "_blogs: Running function _blog_cache"
|
||||||
echo "_blogs: Running function _blog_cache"
|
|
||||||
_blog_cache
|
_blog_cache
|
||||||
|
|
||||||
if (( ${#make_blog_array[@]} > 0 )); then
|
if (( ${#make_blog_array[@]} > 0 )); then
|
||||||
|
local blog_tpl=$(<"${project_dir}/templates/${theme}/blogs.tpl")
|
||||||
|
|
||||||
local blog_tpl=${project_dir}/templates/${theme}/blogs.tpl
|
for blog in "${make_blog_array[@]}"; do
|
||||||
|
if (${debug}) echo "_blogs: Processing ${blog}"
|
||||||
|
|
||||||
if [[ ! -f ${blog_tpl} ]]; then
|
local content="$(<"${blog}")"
|
||||||
echo "Unable to find the Blog template: ${blog_tpl}"
|
local sdate btitle ingress body blog_index blog_dir blog_url
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
local sdate btitle ingress body blog_index blog_dir blog_url
|
# Extract blog information
|
||||||
|
sed -i "s/GETDATE/${BLOGDATE}/" ${blog}
|
||||||
if (${debug}) echo "_blogs: _blog_list_for_index: Just before the for loop: make_blog_array"
|
# Array sdate = Name day=1, Year=2, Month=3, Number day=4
|
||||||
for blog in ${make_blog_array[@]}
|
|
||||||
do
|
|
||||||
if (${debug}) echo "0001: ${red}_blogs: _blog_list_for_index: Processing ${blog}${end}"
|
|
||||||
|
|
||||||
# Read the file once
|
|
||||||
if (${debug}) echo "0002: ${red}_blogs: _blog_list_for_index: Reading blog from array into content: ${blog}${end}"
|
|
||||||
local content="$(<${blog})"
|
|
||||||
|
|
||||||
sed -i "s/GETDATE/${BLOGDATE}/" ${blog}
|
|
||||||
# Array sdate = Name day=4, Year=2, Month=3, Number day=1
|
|
||||||
sdate=( $( echo ${content} | grep DATE | sed "s|DATE\ ||" | sed "s|\-|\ |g" ) )
|
sdate=( $( echo ${content} | grep DATE | sed "s|DATE\ ||" | sed "s|\-|\ |g" ) )
|
||||||
btitle=$( echo ${content} | grep BLOG_TITLE | cut -d' ' -f2- )
|
btitle=$( echo ${content} | grep BLOG_TITLE | cut -d' ' -f2- )
|
||||||
ingress=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#INGRESS_START\K(.*?)#INGRESS_STOP" | sed "s|\ \#INGRESS_STOP||" | sed "s|^\ ||" )
|
ingress=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#INGRESS_START\K(.*?)#INGRESS_STOP" | sed "s|\ \#INGRESS_STOP||" | sed "s|^\ ||" )
|
||||||
body=$( echo ${content} | sed "s/'/\\\'/g" | xargs | grep -Po "#BODY_START\K(.*?)#BODY_STOP" | sed "s|\ \#BODY_STOP||" | sed "s|^\ ||" )
|
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 -e "s|-|_|" | sed -e "s|\ |-|g" | sed -e "s|\,||g" | sed -e "s|\.||" )
|
|
||||||
|
blog_index="${btitle,,}"
|
||||||
|
blog_index="${blog_index// /_}"
|
||||||
|
blog_index="${blog_index//,/}"
|
||||||
|
blog_index="${blog_index//./}"
|
||||||
|
|
||||||
blog_dir="/blog/${sdate[2]}/${sdate[3]}/${sdate[4]}"
|
blog_dir="/blog/${sdate[2]}/${sdate[3]}/${sdate[4]}"
|
||||||
blog_url="${blog_dir}/${blog_index}.html"
|
blog_url="${blog_dir}/${blog_index}.html"
|
||||||
|
|
||||||
if [[ ! -d ${www_root}${blog_dir} ]]; then
|
# Regular blog creation process
|
||||||
if (${debug}) echo "0003: ${red}_blogs: Creating blog directory: ${www_root}${blog_dir}${end}"
|
if [[ -z "${mode}" ]]; then
|
||||||
mkdir -p ${www_root}${blog_dir}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (${debug}) echo "0004: ${cyan}_blogs: blog_index: ${blog_tpl}${end}"
|
for blog in "${make_blog_array[@]}"; do
|
||||||
tee < ${blog_tpl} | sed \
|
if (${debug}) echo "_blogs: Processing ${blog}"
|
||||||
-e "s|BLOGTITLE|${btitle}|" \
|
|
||||||
-e "s|CALADAY|${sdate[1]}|" \
|
|
||||||
-e "s|CALNDAY|${sdate[4]}|" \
|
|
||||||
-e "s|CALMONTH|${sdate[3]}|" \
|
|
||||||
-e "s|CALYEAR|${sdate[2]}|" \
|
|
||||||
-e "s|BLOGURL|${blog_url}|" \
|
|
||||||
-e "s|INGRESS|${ingress}|" \
|
|
||||||
-e "s|DATE ||" \
|
|
||||||
> ${blog%.*}.idx
|
|
||||||
if (${debug}) echo "0005: ---------- ${red}_blogs: TO_IDX_FILE: ${blog%.*}.idx${end}"
|
|
||||||
|
|
||||||
if (${debug}) echo "0006: ${cyan}_blogs: BLOG_URL_TPL: ${www_root}${blog_url}${end}"
|
# Prepare the blog template
|
||||||
tee < ${blog_tpl} | sed \
|
local blog_content="${blog_tpl//BLOGTITLE/${btitle}}"
|
||||||
-e "s|BLOGTITLE|${btitle}|" \
|
blog_content="${blog_content//CALADAY/${sdate[1]}}"
|
||||||
-e "s|CALADAY|${sdate[1]}|" \
|
blog_content="${blog_content//CALNDAY/${sdate[4]}}"
|
||||||
-e "s|CALNDAY|${sdate[4]}|" \
|
blog_content="${blog_content//CALMONTH/${sdate[3]}}"
|
||||||
-e "s|CALMONTH|${sdate[3]}|" \
|
blog_content="${blog_content//CALYEAR/${sdate[2]}}"
|
||||||
-e "s|CALYEAR|${sdate[2]}|" \
|
blog_content="${blog_content//BLOGURL/${blog_url}}"
|
||||||
-e "s|INGRESS|${ingress}|" \
|
blog_content="${blog_content//INGRESS/${ingress}}"
|
||||||
-e "s|BODY|${body}|" \
|
blog_content="${blog_content//BODY/${body}}"
|
||||||
-e "s|DATE ||" \
|
|
||||||
-e "s|\#title||" \
|
|
||||||
>> ${www_root}${blog_url}
|
|
||||||
if (${debug}) echo "0007: ---------- ${red}_blogs: ${blog_tpl} -- TO_BLOG_URL_FILE: ${www_root}${blog_url}${end}"
|
|
||||||
|
|
||||||
echo "_blogs: _last_updated: Updating footer for ${www_root}${blog_url}"
|
# Apply transformations
|
||||||
_last_updated ${www_root}${blog_url}
|
blog_content="$(_html "${blog_content}")"
|
||||||
echo "_blogs: Running HTML engine: ${engine}"
|
blog_content="$(_link "${blog_content}")"
|
||||||
${engine} ${blog_url}
|
blog_content="$(_image "${blog_content}")"
|
||||||
if [[ $( grep \#link ${www_root}${blog_url} ) ]]; then
|
blog_content="$(_youtube "${blog_content}")"
|
||||||
echo "If #link is present, run _link: ${www_root}${blog_url}"
|
blog_content="$(_cleanup "${blog_content}")"
|
||||||
_link ${blog_url}
|
blog_content="$(_last_updated "${blog_content}")"
|
||||||
elif [[ $( grep \#showimg ${www_root}${blog_url} ) ]]; then
|
|
||||||
echo "If #showimg is present, run _image: ${www_root}${blog_url}"
|
# Create directory if it doesn't exist
|
||||||
_image ${blog_url}
|
[[ ! -d "${www_root}${blog_dir}" ]] && mkdir -p "${www_root}${blog_dir}"
|
||||||
elif [[ $( grep \#ytvideo ${www_root}${blog_url} ) ]]; then
|
|
||||||
echo "If #ytvideo is present, run _youtube: ${www_root}${blog_url}"
|
# Write to file
|
||||||
_youtube ${blog_url}
|
echo "${blog_content}" > "${www_root}${blog_url}"
|
||||||
fi
|
|
||||||
_cleanup ${blog_url}
|
elif [[ "${mode}" ]] || [[ "${mode}" != "" ]]; then
|
||||||
|
# Export metadata mode
|
||||||
|
if (${debug}) echo "_blogs: Exporting metadata for ${blog}"
|
||||||
|
export BLOG_SDATE="${sdate[@]}"
|
||||||
|
export BLOG_BTITLE="${btitle}"
|
||||||
|
export BLOG_INGRESS="${ingress}"
|
||||||
|
export BLOG_URL="${www_root}${blog_url}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "${yellow}No new or updated Blogs detected.${end}"
|
echo "${yellow}No new or updated Blogs detected.${end}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _blog_idx_for_index() {
|
function _blog_idx_for_index() {
|
||||||
|
Loading…
Reference in New Issue
Block a user