From 8a33d4488b25454a9b4b00f5d5190f418802fb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Sat, 3 Feb 2024 20:26:21 +0100 Subject: [PATCH] _list_pages: Rewrite --- qsgen2 | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/qsgen2 b/qsgen2 index 07a45f9..c3f3485 100755 --- a/qsgen2 +++ b/qsgen2 @@ -145,24 +145,28 @@ export blogdate=$( date +%a-%Y-%b-%d ) function _list_pages() { local debug=true - + + # Initialize or clear the array to ensure it's empty before adding files + pages_file_array=() + export no_pages_found=false # 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 + local -a pages_files=(*.${file_ext}) - # Check if there are any .blog files in the blog directory - local pages_files=$(ls *.${file_ext}) if (( ${#pages_files} == 0 )); then - if (${debug}); then _msg debug "_list_pages: No Pages found with ext ${file_ext}."; fi + 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 - - for file in $( echo ${pages_files} ); do - if (${debug}) _msg debug "_list_pages: Adding file to array: ${file}" - pages_file_array+=("$file") - done } function _list_blogs() {