]> git.plutz.net Git - serve0/blobdiff - list.sh
great speed improvement, particularly while casting tag selectors
[serve0] / list.sh
diff --git a/list.sh b/list.sh
index 607ea201ed6580ef2a0d5087c72860600669708c..d6228347bec5006fea4cad050b6c868abb0da8d0 100644 (file)
--- a/list.sh
+++ b/list.sh
@@ -6,7 +6,7 @@
 list_item() {
   local name path length width height tags comment n
   name="$(HTML "$1")"
-  path="$(HTML "$ITEM/$1")"
+  path="$(URL "${ITEM}/${1}")"
 
   if [ -d "$_DATA/$ITEM/$1" ]; then
     printf '[a .list .dir href="%s?%s" %s]' \
@@ -34,14 +34,33 @@ list_directories(){
   ) | cut -d/ -f2- | sort
 }
 
+[ "$FILTER" ] && list_fex="$(
+  fex='p'
+  STRING "$FILTER^" \
+  | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \
+  | while read -r f; do
+    [ ! "${f#~}" ] && continue
+    [ "${f#~}" = "$f" ] \
+    && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \
+    || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}"
+    printf '%s\n' "${fex}"
+  done \
+  | tail -n1
+)"
+
 list_filemeta(){
   local meta base f fn file
   base="$1"
   meta="$1/.index/meta"
   meta_dir "$_DATA/$ITEM/$base"
 
-  grep -iE "$(STRING "${SEARCH}")" "$_DATA/$ITEM/$meta" \
-  | cut -f1,6- \
+  if [ "$FILTER" ]; then
+    sed -nr "$list_fex" "$_DATA/$ITEM/$meta"
+  elif [ "${SEARCH#!}" != "${SEARCH}" ]; then
+    grep -viE "$(STRING "${SEARCH#!}")" "$_DATA/$ITEM/$meta"
+  else
+    grep -iE "$(STRING "${SEARCH}")" "$_DATA/$ITEM/$meta"
+  fi |cut -f1,6- \
   | while f="$(line)"; do
     fn="$(UNSTRING "${f#*      }")"; fn="${fn%${CR}}";
     file="$(printf '%s\n' "$_DATA/$ITEM/$base/${fn}".*)"
@@ -69,7 +88,7 @@ list_items() {
   if   [ "$mode" = browse -a "$ORDER" = Date ]; then
     list_directories
     list_filemeta . |cut -f2- \
-    | xargs -d\n stat -c '%Y   %n' \
+    | xargs -rd'\n' stat -c '%Y        %n' \
     | sort -rn |cut -d/ -f2-
   elif [ "$mode" = browse -a "$ORDER" = Name ]; then
     list_directories
@@ -77,7 +96,7 @@ list_items() {
     | sort -k 2 |cut -d/ -f2-
   elif [ "$mode" = index  -a "$ORDER" = Date ]; then
     list_index |cut -f2- \
-    | xargs -d'\n' stat -c '%Y %n' \
+    | xargs -rd'\n' stat -c '%Y        %n' \
     | sort -rn | cut -d/ -f2-
   elif [ "$mode" = index  -a "$ORDER" = Name ]; then
     list_index | sort -k 2 | cut -d/ -f2-
@@ -119,6 +138,7 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
 "$_EXEC/cgilite/html-sh.sed" <<-EOF
 [!DOCTYPE HTML]
 [html [head [title Listing]
+  [meta name="viewport" content="width=device-width"]
   [link rel=stylesheet href="/style.css" ]
 ] [body
   [div #navigation
@@ -128,6 +148,7 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
     [a #t_prefs href="#prefs" &#x2699;]
   ]
   $(w_prefs)
+  $(w_advsearch)
 
   [form method=POST action="?a=multitag"
     $(list_items \