+w_tags="$_DATA/.index/tags.cache"; w_tagcategories="$_DATA/.index/tagcategories.cache"
+if [ ! -f "$w_tags" -o ! -f "$w_tagcategories" ] \
+ || [ "$(find "$_DATA/" -path '*/.index/meta' -newer "$w_tags")" ]
+ then
+ w_tags="$( { local cn=1
+ find "$_DATA/" -path '*/.index/meta' -print0 \
+ | xargs -r0 sed -r '
+ s;^.*\t.*\t.*\ttags=(.*)\tcomment=.*\t.*\r$;\1;;
+ s;,;\n;g;'"$UNSTRING" \
+ | { sort; printf '\n'; } \
+ | while read -r tag; do
+ [ "$tag" = "$otag" ] \
+ && cn=$((cn + 1)) \
+ || {
+ printf "%i %s\n" "$cn" "$otag"
+ cn=1
+ }
+ otag="$tag"
+ done
+ } |sort -rn |cut -f2- |HTML |sed "$w_ascii s- -\n-g; s;\n\n;\n;g;" |tee "$w_tags" )"
+ w_tagcategories="$(printf %s "$w_tags" \
+ | sed -rn '/:/s;^-?([^:]+):.*$;\1;p' |sort -u \
+ | tee "$w_tagcategories" )"
+else
+ w_tags="$(cat "$w_tags")"
+ w_tagcategories="$(cat "$w_tagcategories")"
+fi
+
+
+[ "$ORDER" = Name ] && w_coname=checked
+[ "$ORDER" = Date ] && w_codate=checked
+[ "$ORDER" = Length ] && w_colength=checked
+[ "$ORDER" = Group ] && w_cogroup=checked
+
+w_bookmarks(){
+ local name='' cf='' cs='' bm="$_DATA/.index/bookmarks" proposed_name=''
+ [ ! -d "${bm%/*}" ] && return 0
+ [ ! -f "$bm" ] && touch "$bm"
+
+ [ "$SEARCH" ] && cs="$(STRING "$SEARCH")"
+ [ "$FILTER" ] && cf="$(STRING "$FILTER")"
+
+ name="$(grep -m1 -aF " search=$cs filter=$cf${CR}" "$bm" |cut -f1 |UNSTRING)"
+ [ ! "$name" ] && proposed_name="$(
+ printf '%s\t%s' "$SEARCH" "$FILTER" \
+ |sed -r '/^\t$/{ s;\t;All;; q;}
+ /.*\t$/{ s;\t$;;; q;}
+ /^\t.*/{ s;^\t;;;
+ :x; s;(^|[~^|])([^|^~:]+):;\1;; tx;
+ s;\^; and ;g; s;\|;,;g; s;~;not ;g; q;}'
+ )"
+
+ printf '[form #bookmarks action=?a=bookmark method=POST
+ [a href="#" x]
+ [hidden "ref" "%s"]
+ [hidden "search" "%s"][hidden "filter" "%s"]
+ [label Name for current page:]
+ [input name="name" value="%s" placeholder="Name" ]
+ [button type="submit" %s]' \
+ "$w_refuri" \
+ "$(HTML "$SEARCH")" "$(HTML "$FILTER")" \
+ "$(HTML "${name:-${proposed_name}}")" \
+ "${name:+Update}${proposed_name:+Add}"
+ [ "$name" ] && printf ' [submit "delete" "delete" Delete]'
+
+ sort "$bm" |while read -r name search filter; do
+ search="${search#search=}" filter="${filter#filter=}" filter="${filter%${CR}}"
+ [ "$search" = "${cs}" -a "$filter" = "${cf}" ] && continue
+
+ name="$(UNSTRING "$name")";
+ search="$(UNSTRING "${search}" |URL)";
+ filter="$(UNSTRING "${filter}" |URL)";
+ printf '[label .link %s]
+ [a .link target=blank href="?o=Name&s=%s&f=%s" by Name]
+ [a .link target=blank href="?o=Date&s=%s&f=%s" by Date]
+ [a .link target=blank href="?o=Length&s=%s&f=%s" by Length]
+ [a .link target=blank href="?o=Group&s=%s&f=%s" by Group]
+ [br]' \
+ "$(HTML "$name" |sed 's;,\;;&[wbr];g;')" \
+ "$search" "$filter" \
+ "$search" "$filter" \
+ "$search" "$filter" \
+ "$search" "$filter"
+ done
+ printf ']'
+}