From: paul Date: Sun, 15 Oct 2017 23:29:45 +0000 (+0000) Subject: cleanup of category handling X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=2ea56a62d0ef6e9d295d0b8931a071e6f2e0a963;p=confetti cleanup of category handling svn path=/trunk/; revision=158 --- diff --git a/pages/cards.sh b/pages/cards.sh index b836f6b..a90981c 100755 --- a/pages/cards.sh +++ b/pages/cards.sh @@ -60,7 +60,8 @@ list_hi_companies(){ list_categories() { catfile="${_DATA}/mappings/categories" - sort -u "$catfile" + sort -u "$catfile" \ + | sed -r '/^[\t ]*$/d' } listcards() { diff --git a/pages/categories.sh b/pages/categories.sh index 88d78c2..e875eef 100755 --- a/pages/categories.sh +++ b/pages/categories.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2015 Paul Hänsch +# Copyright 2015, 2017 Paul Hänsch # # This file is part of Confetti. # @@ -20,25 +20,32 @@ catfile="${_DATA}/mappings/categories" listcards() { - ls -1 ${_DATA}/vcard/*vcf 2>/dev/null |while read file; do - fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file") - echo "$fn\t$file" - done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:' + for file in "${_DATA}/vcard/"*.vcf; do + printf '%s\t%s\n' \ + "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" \ + "$file" + done \ + | sort \ + | sed -r 's;^.*\t(.*/)([^/]+)$;\2;' } get_name() { cfile="${_DATA}/vcard/$1" - sed -rn 's:^N(;[^"\:]+|;"[^"]+")*\:([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?\r?$:\5 \3 \4 \2 \6:p' "$cfile" \ - |sed -r 's:,: :;s:\;: :g;s: +: :g' \ + sed -rn 's;^N(\;[^":]+|\;"[^"]+")*:([^\;]*)(\;[^\;]*)(\;[^\;]*)?(\;[^\;]*)?(\;[^\;]*)?\r?$;\5 \3 \4 \2 \6;; + tX; b; :X s;[,\; ]+; ;g; p;' "$cfile" } get_categories(){ cfile="${_DATA}/vcard/$1" - sed -rn 's:^CATEGORIES(;[^"\:]+|;"[^"]+")*\:(.+)\r?$:\2:p' "$cfile" \ - | sed -r 's;(^|[^\\]+)((\\\\)+),;\1\2\n;g; s;(^|[^\\]),;\1\n;g; s;(^|[^\\]+)((\\\\)+),;\1\2\n;g; s;(^|[^\\]),;\1\n;g; s;\\,;,;g' \ + sed -rn 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:(.+)\r?$;\2;; + tX; b; :X + s;(^|[^\\]+)((\\\\)+),;\1\2\n;g; + s;(^|[^\\]),;\1\n;g; s;(^|[^\\]+)((\\\\)+),;\1\2\n;g; + s;(^|[^\\]),;\1\n;g; s;\\,;,;g; p;' "$cfile" \ | sort -u } list_categories() { - sort -u "$catfile" + sort -u "$catfile" \ + | sed -r '/^[\t ]*$/d' } diff --git a/templates/categories.html.sh b/templates/categories.html.sh index 5375965..e266e1f 100755 --- a/templates/categories.html.sh +++ b/templates/categories.html.sh @@ -1,4 +1,4 @@ -# Copyright 2015 Paul Hänsch +# Copyright 2015, 2017 Paul Hänsch # # This file is part of Confetti. # @@ -17,29 +17,27 @@ cat_listing(){ list_categories | while read cat; do - cat <<-END -
  • ${cat}
  • - END + printf '
  • %s
  • \n' \ + "$(htmlsafe "$cat")" "$(attribsafe "$cat")" "$(l10n cat_remove)" done } list_catsel(){ card="$1" - cats="$(get_categories $card)" + cats="$(get_categories "$card")" list_categories |while read cat; do - cat <<-END -
  • - END + printf '
  • ' \ + "$(printf %s "$cats" |grep -qF "$cat" && printf 'checked="checked"')" \ + "$(attribsafe "$card")" "$(attribsafe "$cat")" "$(htmlsafe "$cat")" done } display_catsel(){ card="$1" - cat <<-END -
  • $(get_name "$card")

  • - END + printf '
  • %s

  • ' } cat <$(l10n cat_update)