qsgen2: Clean up tabs and spaces

This commit is contained in:
Stig-Ørjan Smelror 2024-02-05 20:55:22 +01:00
parent 45d1d31356
commit 535a5ec0b8

70
qsgen2
View File

@ -40,6 +40,7 @@ include common/colors
echo "${magenta}${blue_bg} ${QSGEN} ${end}${bold_white}${blue_bg}${VERSION} ${end}"
_add_site() {
local site_name="${1}"
local project_dir="${2}"
local sites_file="${HOME}/.config/qsgen2/sites.qsc"
@ -65,9 +66,11 @@ _add_site() {
# Add the site to the sites file
echo "${site_number}|${site_name}|${project_dir}" >> "${sites_file}"
echo "Site '${site_name}' added successfully."
}
_list_sites() {
local config_dir="${HOME}/.config/qsgen2"
local sites_file="${config_dir}/sites.qsc"
@ -84,6 +87,7 @@ _list_sites() {
else
echo "No sites registered."
fi
}
@ -340,6 +344,7 @@ function _pages_cache() {
# If you want to debug this function only, set this to true
local debug=false
fi
# Create an associative array for the pages cache
typeset -A pages_cache
@ -368,6 +373,7 @@ function _pages_cache() {
if [[ ${pages_cache[$file]} != "$current_hash" ]]; then
if (${debug}) _msg debug "2. _pages_cache: pages_file: ${pages_cache[$file]}"
if (${debug}) _msg debug "2. _pages_cache: current_cache: ${current_hash}"
# Pages file is new or has changed; add it to the processing array
pages_array+=("$file")
@ -406,6 +412,7 @@ function _last_updated() {
# Return the updated content
echo "${updated_content}"
}
function _f_last_updated() {
@ -472,9 +479,9 @@ function _pages() {
# If pages_array is not empty, we do work
if (${debug}) _msg debug "_pages: pages_array is not empty"
for pages_in_array in ${pages_array[@]}
do
if (${debug}) _msg debug "_pages: Setting Pages template"
local pages=${project_dir}/themes/${theme}/pages.tpl
@ -564,7 +571,6 @@ function _pages() {
export new_updated_pages=true
else
# Insert the blog to the front page is blog_in_index is true and the file in the array is index.file_ext
# and if index.tmp.html exist and is not empty
if [[ ${blog_in_index} == "true" && -s "${project_dir}/blog/index.tmp.html" ]]; then
@ -614,7 +620,6 @@ function _blogs() {
BLOG_META_STR_ARRAY=()
# Regular blog creation process
#if [[ ! ${mode} ]]; then
if [[ -f ${project_dir}/themes/${theme}/blogs.tpl ]]; then
local blog_tpl=$(<"${project_dir}/themes/${theme}/blogs.tpl")
@ -716,6 +721,7 @@ function _blogs() {
_msg sub "- No new or updated Blogs found"
export new_updated_blogs=false
fi
if [[ ${new_updated_blogs} == "true" ]]; then
if (${debug}) _msg sub "* _blogs: Running _blog_idx_for_index"
_blog_idx_for_index
@ -759,8 +765,8 @@ function _blog_idx_for_index() {
# Iterate over each component and extract information
if (${debug}) _msg debug "_blog_idx_for_index: Iterate over each component and extract information"
for component in "${meta_array[@]}"; do
for component in "${meta_array[@]}"
do
case "${component}" in
SDATE:*) sdate=${component#SDATE: } ;;
BTITLE:*) btitle=${component#BTITLE: } ;;
@ -789,6 +795,7 @@ function _blog_idx_for_index() {
")
done
unset sdate btitle ingress url
if (${debug}) _msg debug "_blog_idx_for_index: Running ${engine} on content to catch QStags in Ingress"
@ -842,17 +849,22 @@ function _add_blog_list_to_index() {
fi
# Let's find the file 'index.qst' and add the blog if blog_in_index is true
#if [[ ${new_updated_blogs} == "true" ]] && [[ ${blog_in_index} == "true" ]]; then
if (${debug}) _msg debug "_add_blog_list_to_index: Inserting blog list to index.html"
local blog_index_list=$(<${project_dir}/blog/index.tmp.html)
local site_index_file=$(<${www_root}/index.html)
echo "${site_index_file}" | awk -v new_body="${blog_index_list}" '{sub(/BLOGINDEX/, new_body)} 1' > "${www_root}/index.html"
#fi
}
function _sitemap() {
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
# If you want to debug this function only, set this to true
local debug=false
fi
# Check if sitemap is set to true and if there are updated Blogs or Pages before updating the sitemap.xml file.
if [[ ${sitemap} == "true" ]] && ( [[ ${new_updated_blogs} == "true" ]] || [[ ${new_updated_pages} == "true" ]] ); then
@ -874,7 +886,8 @@ if [[ ${sitemap} == "true" ]] && ( [[ ${new_updated_blogs} == "true" ]] || [[ ${
echo '>' >> ${sitemap_file}
# Add each URL to the sitemap
for file in "${html_files[@]}"; do
for file in "${html_files[@]}"
do
# Remove www_root from the path and prepend site_url
local url="${site_url}${file#$www_root}"
local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
@ -899,8 +912,6 @@ fi
function _link() {
# This converts #link tags to actual clickable links in a provided string
local content="${1}"
local modified_content=""
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
@ -908,6 +919,9 @@ function _link() {
local debug=false
fi
local content="${1}"
local modified_content=""
# Process the content line by line
echo "${content}" | while IFS= read -r line; do
if [[ ${line} == *"#link"* ]]; then
@ -935,13 +949,12 @@ function _link() {
# Return the modified content
echo -e "${modified_content}"
}
function _image() {
# This replaces #showimg tags with actual HTML img tags in a provided string
local content="${1}"
local modified_content=""
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
@ -949,6 +962,9 @@ function _image() {
local debug=false
fi
local content="${1}"
local modified_content=""
# Process the content line by line
echo "${content}" | while IFS= read -r line; do
if [[ ${line} == *"#showimg"* ]]; then
@ -978,13 +994,12 @@ function _image() {
# Return the modified content
echo -e "${modified_content}"
}
function _youtube() {
# This embeds a YouTube video in a provided string
local content="${1}"
local modified_content=""
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
@ -992,6 +1007,9 @@ function _youtube() {
local debug=false
fi
local content="${1}"
local modified_content=""
# Process the content line by line
echo "${content}" | while IFS= read -r line; do
if [[ ${line} == *"#ytvideo"* ]]; then
@ -1009,12 +1027,12 @@ function _youtube() {
# Return the modified content
echo -e "${modified_content}"
}
function _cleanup() {
# This removes tags used in the templates that may be left over for some reason
local content="${1}"
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
@ -1022,6 +1040,8 @@ function _cleanup() {
local debug=false
fi
local content="${1}"
if (${debug}) _msg debug "_cleanup: Cleaning up tags in content"
# Perform the cleanup
@ -1035,10 +1055,11 @@ function _cleanup() {
# Return the cleaned content
echo "${cleaned_content}"
}
function _html() {
local content="$1"
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
@ -1046,8 +1067,10 @@ function _html() {
local debug=false
fi
local content="$1"
if ${debug}; then
echo "_html: Converting QStags in content"
_msg debug "_html: Converting QStags in content"
fi
# Use perl to convert QStags to HTML
@ -1088,18 +1111,19 @@ function _html() {
"#LT", "&lt;", "#GT", "&gt;", "#NUM", "&num;"
);
}
for (my $i = 0; $i < $#tags; $i += 2) {
my $tag = $tags[$i];
my $html = $tags[$i + 1];
s/\Q$tag\E/$html/g;
}
' <<< "$content"
}
function _zhtml() {
# This function uses the regex module from Zsh to parse the QStags
local content="$1"
if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
@ -1107,6 +1131,8 @@ function _zhtml() {
local debug=false
fi
local content="$1"
if ${debug}; then
echo "_html: Converting QStags in content"
fi
@ -1150,7 +1176,8 @@ function _zhtml() {
"#LT" "&lt;" "#GT" "&gt;" "#NUM" "&num;"
)
for tag html (${(kv)tags}); do
for tag html (${(kv)tags})
do
# Escape tag for regex use
local escapedTag=$(printf '%s' "$tag" | sed 's/[].\[^$*]/\\&/g')
if [[ "$content" =~ "$escapedTag" ]]; then
@ -1159,12 +1186,9 @@ function _zhtml() {
done
echo "$content"
}
# Time to run the first function
_blogs
# _add_blog_list_to_index
_pages
_sitemap