]> git.plutz.net Git - shellwiki/commitdiff
themeable search page
authorPaul Hänsch <paul@plutz.net>
Fri, 22 Sep 2023 15:50:03 +0000 (17:50 +0200)
committerPaul Hänsch <paul@plutz.net>
Fri, 22 Sep 2023 15:50:03 +0000 (17:50 +0200)
handlers/40_search.sh
themes/default.sh

index 823ef76520a39db2dbe200d77b304fe977fdeaf6..d198f220756319f457783e95af36d43d9114351e 100644 (file)
@@ -42,16 +42,6 @@ done \
     [ "${page%/:*/}" = "${page%/:${LANGUAGE}/}" ] || continue
   fi
   acl_read "$page" || continue
-  printf '<li><a href="%s">%s</a></li>' "$(URL "$page")" "$(HTML "$page")"
+  printf '%s\n' "$page"
 done \
-| theme_page - <<-EOF
-       <article>
-         <h1>$(_ "Search results")</h1>
-         <form method=GET>
-            <input class="search" name="q" placeholder="$(_ Search)" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
-         </form>
-         <ol class="searchresults">
-           $(cat)
-         </ol>
-       </article>
-       EOF
+| theme_search "${words%       }"
index 85febeef60e7274563a2e62c0d59698e7088bb12..5e38ee4583f743c9240464022648d864bee9aeaf 100755 (executable)
@@ -131,6 +131,25 @@ theme_editor(){
 
 theme_revisions(){ theme_page "$@"; }
 
+theme_search(){
+  local words="$*"
+  # STDIN: read result pages line by line
+
+  theme_page - <<-EOF
+       <article>
+         <h1>$([ "$words" ] && _ "Search results" || _ "Search" )</h1>
+         <form method=GET>
+           <input class="search" name="q" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
+         </form>
+         <ol class="searchresults">
+           $( while read p; do
+             printf '<li><a href="%s">%s</a></li>' "$(URL "$p")" "$(HTML "$p")"
+           done)
+         </ol>
+       </article>
+       EOF
+}
+
 theme_attachments(){
   local page="$1" title
   title="${page%/}"; title="${title##*/}"