]> git.plutz.net Git - shellwiki/commitdiff
use tags (#positive and !negative) in search
authorPaul Hänsch <paul@plutz.net>
Tue, 19 Mar 2024 11:10:33 +0000 (12:10 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 19 Mar 2024 11:10:33 +0000 (12:10 +0100)
handlers/40_search.sh
themes/default.sh

index 1e3301944299d1288b690947953cdba56164abd7..57117e3834a1bbe0c816f92e785bc38c188bc186 100644 (file)
 . "$_EXEC/cgilite/db23.sh"
 
 I="$_DATA/index"
+tags="$( GET q | awk '
+  BEGIN { # Field separator FS should include punctuation, including Unicode Block U+2000 - U+206F
+          if ( length("¡") == 1 )  # Utf-8 aware AWK
+          FS = "([] \\t\\n\\r!\"'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '[\342\200\200-\342\201\257]')"')+";
+          else                     # UTF-8 Hack
+          FS = "([] \\t\\n\\r!\"'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+";
+          fi
+        }
+  { for (n = 1; n <= NF; n++) if ($n ~ /#[[:alnum:]_]+/) {
+      sub(/^#/,"",$n)
+      printf "%s       ", toupper($n);
+    }
+  }
+')"
+
+ntags="$( GET q | awk '
+  BEGIN { # Field separator FS should include punctuation, including Unicode Block U+2000 - U+206F
+          if ( length("¡") == 1 )  # Utf-8 aware AWK
+          FS = "([] \\t\\n\\r\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '[\342\200\200-\342\201\257]')"')+";
+          else                     # UTF-8 Hack
+          FS = "([] \\t\\n\\r\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+";
+          fi
+        }
+  { for (n = 1; n <= NF; n++) if ($n ~ /![[:alnum:]_]+/) {
+      sub(/^!/,"",$n)
+      printf "%s       ", toupper($n);
+    }
+  }
+')"
+
 words="$( GET q | awk '
   BEGIN { # Field separator FS should include punctuation, including Unicode Block U+2000 - U+206F
           if ( length("¡") == 1 )  # Utf-8 aware AWK
-          FS = "([] \\t\\n\\r!\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '[\342\200\200-\342\201\257]')"')+";
+          FS = "([] \\t\\n\\r\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '[\342\200\200-\342\201\257]')"')+";
           else                     # UTF-8 Hack
-          FS = "([] \\t\\n\\r!\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+";
+          FS = "([] \\t\\n\\r\"#'\''()*+,./:;<=>?\\\\^_`{|}~[-]|%[0-9A-Fa-f]{2}|'"$(printf '\342\200[\200-\277]|\342\201[\201-\257]')"')+";
           fi
         }
-       { for (n = 1; n <= NF; n++) printf "%s  ", tolower($n); }
+  { for (n = 1; n <= NF; n++) if ($n !~ /![[:alnum:]_]+/) {
+      sub(/!/," ",$n)
+      printf "%s       ", tolower($n);
+    }
+  }
 ')"
 
 searchteaser() {
@@ -89,6 +123,8 @@ done \
     [ "${page%/:*/}" = "${page%/:${LANGUAGE}/}" ] || continue
   fi
   acl_read "$page" || continue
+  has_tags "$page" $tags || continue
+  has_tag "$page" $ntags && continue
   printf '%s   %s\n' "$doc" "$(searchteaser "$(mdfile "$page")" $words)"
 done \
 | theme_search "${words%       }"
index 033dd7f7a270d14d8f88774fde0ad9737a8a40cf..0f45c591cd570773fc8e5ab036c5c7ae970dcb61 100755 (executable)
@@ -142,7 +142,7 @@ theme_search(){
        <article>
          <h1>$([ "$words" ] && _ "Search results" || _ "Search" )</h1>
          <form class="search" method="GET">
-           <input type="search" name="q" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
+           <input type="search" name="q" value="$(GET q |HTML)"><button class="search" type="submit">$(_ Search)</button>
          </form>
          <ol class="searchresults">
            $(while read -r p t; do