From 65b6710edcaf79944c1cc4917c031d9b81b49bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Sat, 3 Feb 2024 20:30:06 +0100 Subject: [PATCH] _list_blogs: Rewrite --- qsgen2 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/qsgen2 b/qsgen2 index c3f3485..0402b38 100755 --- a/qsgen2 +++ b/qsgen2 @@ -144,7 +144,7 @@ export blogdate=$( date +%a-%Y-%b-%d ) # Let's create arrays of all the files we'll be working on function _list_pages() { - local debug=true + local debug=false # Initialize or clear the array to ensure it's empty before adding files pages_file_array=() @@ -172,24 +172,30 @@ function _list_pages() { function _list_blogs() { 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 # Temporarily set null_glob for this function setopt local_options null_glob - # Check if there are any .blog files in the blog directory - local blog_files=(blog/*.blog) - if (( ${#blog_files} == 0 )); then - if (${debug}); then _msg debug "_list_blogs: No blog files found."; fi + # Directly capture matching blog files into an array + local -a blog_files=(blog/*.blog) + + 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 - - for file in $( ls -har blog/*.blog ); do - blogs_file_array+=("$file") - done } + # BLOG CACHE function _blog_cache() { local debug=false