_list_blogs: Rewrite

This commit is contained in:
Stig-Ørjan Smelror 2024-02-03 20:30:06 +01:00
parent 8a33d4488b
commit 65b6710edc

24
qsgen2
View File

@ -144,7 +144,7 @@ export blogdate=$( date +%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() {
local debug=true local debug=false
# 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=()
@ -172,24 +172,30 @@ function _list_pages() {
function _list_blogs() { function _list_blogs() {
local debug=false local debug=false
# Initialize or clear the blogs array to ensure it's empty before adding files
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
# Check if there are any .blog files in the blog directory # Directly capture matching blog files into an array
local blog_files=(blog/*.blog) local -a blog_files=(blog/*.blog)
if (( ${#blog_files} == 0 )); then
if (${debug}); then _msg debug "_list_blogs: No blog files found."; fi if (( ${#blog_files[@]} == 0 )); then
if ${debug}; then _msg debug "_list_blogs: No blog files found."; fi
export no_blogs_found=true export no_blogs_found=true
return 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 fi
for file in $( ls -har blog/*.blog ); do
blogs_file_array+=("$file")
done
} }
# BLOG CACHE # BLOG CACHE
function _blog_cache() { function _blog_cache() {
local debug=false local debug=false