From: Paul Hänsch <paul@plutz.net>
Date: Tue, 22 Feb 2022 18:48:13 +0000 (+0100)
Subject: avoid orphaned close tag when tag list is empty
X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=d13a512829cd9cf5d2a364a9a6cee3ce7f614f02;p=serve0

avoid orphaned close tag when tag list is empty
---

diff --git a/widgets.sh b/widgets.sh
index 23afd9d..df141e7 100755
--- a/widgets.sh
+++ b/widgets.sh
@@ -230,7 +230,7 @@ w_delete(){
 }
 
 w_tagging(){
-  local tctag oldcat category tag
+  local tctag oldcat="" category tag
 
   cat <<-EOF
 	[a href="#multitag" Add Tags / Remove Tags]
@@ -238,8 +238,6 @@ w_tagging(){
 	  [a href="#" X]
 	EOF
 
-  oldcat="Tags"
-  printf '[fieldset [legend %s:][div .tagselect\n' "Tags"
   printf '%s\n' "$w_tags" \
   | while read tctag; do
     [ "$tctag" ] || continue
@@ -250,14 +248,14 @@ w_tagging(){
     && category="Tags"
 
     if [ "$category" != "$oldcat" ]; then
-      printf ']]'
+      [ "$oldcat" ] && printf ']]'
       printf '[fieldset [legend %s:][div .tagselect\n' "$category"
     fi
     printf '[label [checkbox "tag" "%s"] %s]\n' "$tctag" "$tag"
 
     oldcat="$category"
   done
-  printf ']]'
+  [ "$w_tags" ] && printf ']]'
 
   cat <<-EOF
 	  [fieldset [legend New:][textarea name=newtag\n]