New function: _add_blog_list_to_index

This commit is contained in:
Stig-Ørjan Smelror 2024-02-02 16:09:11 +01:00
parent b271af7871
commit 9055af219d

41
qsgen2
View File

@ -421,36 +421,22 @@ function _pages() {
# Look for links, images and videos and convert them if present. # Look for links, images and videos and convert them if present.
if (${debug}) _msg debug "_pages: Checking for #link, #showimg and #ytvideo in page_content" if (${debug}) _msg debug "_pages: Checking for #link, #showimg and #ytvideo in page_content"
if [[ $( echo ${page_content} | grep \#link ) ]]; then if [[ $( echo ${page_content} | grep \#link ) ]]; then
if (${debug}) _msg debug "_pages: #link is present, run _link: page_content" if (${debug}) _msg debug "_pages: #link is present, run _link: page_content"
local page_content=$( _link "${page_content}" ) local page_content=$( _link "${page_content}" )
fi fi
if [[ $( echo ${page_content} | grep \#showimg ) ]]; then if [[ $( echo ${page_content} | grep \#showimg ) ]]; then
if (${debug}) _msg debug "_pages: #showimg is present, run _image: page_content" if (${debug}) _msg debug "_pages: #showimg is present, run _image: page_content"
local page_content=$( _image "${page_content}" ) local page_content=$( _image "${page_content}" )
fi fi
if [[ $( echo ${page_content} | grep \#ytvideo ) ]]; then if [[ $( echo ${page_content} | grep \#ytvideo ) ]]; then
if (${debug}) _msg debug "_pages: #ytvideo is present, run _youtube: page_content" if (${debug}) _msg debug "_pages: #ytvideo is present, run _youtube: page_content"
local page_content=$( _youtube "${page_content}" ) local page_content=$( _youtube "${page_content}" )
fi fi
elif [[ ${file_ext} == "md" ]]; then elif [[ ${file_ext} == "md" ]]; then
local page_content=$(echo "$page_content" | ${engine}) local page_content=$(echo "$page_content" | ${engine})
#echo "$page_content"
#exit
fi
#new_updated_blogs=true
# Let's find the file 'index.tpl' and add the blog if blog_in_index is true
if [[ ${pages_in_array} == "index.${file_ext}" ]] && [[ ${blog_in_index} == "true" ]]; then
if (${debug}) _msg debug "_pages: Inserting blog list to index.html"
local blog_index_list=$(<${project_dir}/blog/index.tmp.html)
page_content=$( echo ${blog_index_list} >> ${page_content} )
fi fi
# Insert page_content into pages_tpl by replacing the BODY tag present there
if (${debug}) _msg debug "_pages: Replacing BODY with page_content in pages_tpl using Perl"
# Use Perl for multi-line and special character handling
local pages_tpl=$( awk -v new_body="$page_content" '{sub(/BODY/, new_body)} 1' <(echo "${pages_tpl}") )
# Replace every #pagetitle in pages_tpl # Replace every #pagetitle in pages_tpl
if (${debug}) _msg debug "_pages: Replacing #pagetitle in pages_tpl" if (${debug}) _msg debug "_pages: Replacing #pagetitle in pages_tpl"
local pages_tpl=$( echo ${pages_tpl} | perl -pe "s|#pagetitle|${page_title}|gs" ) local pages_tpl=$( echo ${pages_tpl} | perl -pe "s|#pagetitle|${page_title}|gs" )
@ -679,6 +665,20 @@ function _blog_index() {
} }
function _add_blog_list_to_index() {
local debug=true
# Let's find the file 'index.tpl' and add the blog if blog_in_index is true
if [[ ${new_updated_blogs} == "true" ]] && [[ ${blog_in_index} == "true" ]]; then
if (${debug}) _msg debug "_pages: Inserting blog list to index.html"
local blog_index_list=$(<${project_dir}/blog/index.tmp.html)
local site_index_file=$(<${www_root}/index.tmp.html)
awk -v new_body="$site_index_file" '{sub(/BLOGINDEX/, new_body)} 1' <(echo "${blog_index_list}")
fi
}
function _sitemap() { function _sitemap() {
# Check if sitemap is set to true and if there are updated Blogs or Pages before updating the sitemap.xml file. # Check if sitemap is set to true and if there are updated Blogs or Pages before updating the sitemap.xml file.
@ -900,4 +900,5 @@ _html() {
# Time to test the first function # Time to test the first function
_blogs _blogs
_pages _pages
_add_blog_list_to_index
_sitemap _sitemap