qsgen2: More cleaning up tabs and spaces

This commit is contained in:
Stig-Ørjan Smelror 2024-02-05 21:19:22 +01:00
parent 535a5ec0b8
commit 28d26040a4

132
qsgen2
View File

@ -137,30 +137,31 @@ blog_cache_file="${project_dir}/.blog_cache"
pages_cache_file="${project_dir}/.pages_cache" pages_cache_file="${project_dir}/.pages_cache"
function _msg() { function _msg() {
# Use this function to write out messages based on their type # Use this function to write out messages based on their type
# Types are: std=green - info=yellow - debug=red other=bold_yellow # Types are: std=green - info=yellow - debug=red other=bold_yellow
# Usage: _msg <type> "<message>" # Usage: _msg <type> "<message>"
case ${1} in
std)
echo "${yellow}${2}${end}"
;;
info)
echo "${green}${2}${end}"
;;
debug)
echo "${red}${2}${end}"
;;
other)
echo "${bold_yellow}${2}${end}"
;;
sub)
echo "${magenta}${2}${end}"
;;
*)
echo "${2}"
;;
esac
case ${1} in
std)
echo "${yellow}${2}${end}"
;;
info)
echo "${green}${2}${end}"
;;
debug)
echo "${red}${2}${end}"
;;
other)
echo "${bold_yellow}${2}${end}"
;;
sub)
echo "${magenta}${2}${end}"
;;
*)
echo "${2}"
;;
esac
} }
case ${1} in case ${1} in
@ -171,19 +172,19 @@ case ${1} in
echo "Usage: qsgen2 add \"Site Name\" \"/path/to/project\"" echo "Usage: qsgen2 add \"Site Name\" \"/path/to/project\""
fi fi
exit exit
;; ;;
list) list)
_list_sites _list_sites
exit exit
;; ;;
force) force)
_msg sub "- Forced Update: Generating Everything" _msg sub "- Forced Update: Generating Everything"
: >| "$blog_cache_file" # Truncate the blog cache before doing update : >| "$blog_cache_file" # Truncate the blog cache before doing update
: >| "$pages_cache_file" # Truncate the page cache before doing update : >| "$pages_cache_file" # Truncate the page cache before doing update
;; ;;
*) *)
#echo "Usage: qsgen2 [command]" #echo "Usage: qsgen2 [command]"
;; ;;
esac esac
# Let's check if qsgen2 can generate this site by checking if 'generator' is available # Let's check if qsgen2 can generate this site by checking if 'generator' is available
@ -220,6 +221,7 @@ export blogdate=$(strftime "%a-%Y-%b-%d")
# Let's create arrays of all the files we'll be working on # Let's create arrays of all the files we'll be working on
function _list_pages() { function _list_pages() {
if [[ ${globaldebug} == "true" ]]; then if [[ ${globaldebug} == "true" ]]; then
local debug=true local debug=true
else else
@ -227,30 +229,32 @@ function _list_pages() {
local debug=false local debug=false
fi fi
# Initialize or clear the array to ensure it's empty before adding files # Initialize or clear the array to ensure it's empty before adding files
pages_file_array=() pages_file_array=()
export no_pages_found=false export no_pages_found=false
# Temporarily set null_glob for this function # Temporarily set null_glob for this function
setopt local_options null_glob setopt local_options null_glob
# Using an array to directly capture matching files # Using an array to directly capture matching files
local -a pages_files=(*.${file_ext}) local -a pages_files=(*.${file_ext})
if (( ${#pages_files} == 0 )); then
if ${debug}; then _msg debug "_list_pages: No Pages found with ext ${file_ext}."; fi
export no_pages_found=true
return
else
for file in "${pages_files[@]}"; do
if ${debug}; then _msg debug "_list_pages: Adding file to array: ${file}"; fi
pages_file_array+=("$file")
done
fi
if (( ${#pages_files} == 0 )); then
if ${debug}; then _msg debug "_list_pages: No Pages found with ext ${file_ext}."; fi
export no_pages_found=true
return
else
for file in "${pages_files[@]}"; do
if ${debug}; then _msg debug "_list_pages: Adding file to array: ${file}"; fi
pages_file_array+=("$file")
done
fi
} }
function _list_blogs() { function _list_blogs() {
if [[ ${globaldebug} == "true" ]]; then if [[ ${globaldebug} == "true" ]]; then
local debug=true local debug=true
else else
@ -258,32 +262,35 @@ function _list_blogs() {
local debug=false local debug=false
fi fi
# Initialize or clear the blogs array to ensure it's empty before adding files # Initialize or clear the blogs array to ensure it's empty before adding files
blogs_file_array=() blogs_file_array=()
export no_blogs_found=false export no_blogs_found=false
# Temporarily set null_glob for this function # Temporarily set null_glob for this function
setopt local_options null_glob setopt local_options null_glob
# Directly capture matching blog files into an array # Directly capture matching blog files into an array
local -a blog_files=(blog/*.blog(On)) local -a blog_files=(blog/*.blog(On))
if (( ${#blog_files[@]} == 0 )); then
if ${debug}; then _msg debug "_list_blogs: No blog files found."; fi
export no_blogs_found=true
return
else
for file in "${blog_files[@]}"
do
if ${debug}; then _msg debug "_list_blogs: Adding file to array: $file"; fi
blogs_file_array+=("$file")
done
fi
if (( ${#blog_files[@]} == 0 )); then
if ${debug}; then _msg debug "_list_blogs: No blog files found."; fi
export no_blogs_found=true
return
else
for file in "${blog_files[@]}"; do
if ${debug}; then _msg debug "_list_blogs: Adding file to array: $file"; fi
blogs_file_array+=("$file")
done
fi
} }
# BLOG CACHE # BLOG CACHE
function _blog_cache() { function _blog_cache() {
if [[ ${globaldebug} == "true" ]]; then if [[ ${globaldebug} == "true" ]]; then
local debug=true local debug=true
else else
@ -332,12 +339,14 @@ function _blog_cache() {
for name in "${(@k)blog_cache}"; do for name in "${(@k)blog_cache}"; do
echo "$name:${blog_cache[$name]}" >> "$blog_cache_file" echo "$name:${blog_cache[$name]}" >> "$blog_cache_file"
done done
} }
# PAGES CACHE # PAGES CACHE
# Returns the array pages_array() # Returns the array pages_array()
function _pages_cache() { function _pages_cache() {
if [[ ${globaldebug} == "true" ]]; then if [[ ${globaldebug} == "true" ]]; then
local debug=true local debug=true
else else
@ -387,6 +396,7 @@ function _pages_cache() {
for name in "${(@k)pages_cache}"; do for name in "${(@k)pages_cache}"; do
echo "$name:${pages_cache[$name]}" >> "$pages_cache_file" echo "$name:${pages_cache[$name]}" >> "$pages_cache_file"
done done
} }
function _last_updated() { function _last_updated() {