]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/webapps/help/help.factor
webapps.help: tokenize and collapse search terms
[factor.git] / extra / webapps / help / help.factor
index 1bcff3687aa625a416f60d683dbb795985bdadd1..faa1b11a5a511488b4e58ddcea7e9f836fc8c3fe 100644 (file)
@@ -4,26 +4,41 @@ USING: accessors assocs furnace.actions furnace.boilerplate
 furnace.redirection help.html help.topics html.components
 html.forms http.server http.server.dispatchers
 http.server.static io.directories io.files.temp io.servers
-kernel locals namespaces sequences unicode urls ;
+kernel namespaces sequences simple-tokenizer splitting unicode
+urls ;
 IN: webapps.help
 
 TUPLE: help-webapp < dispatcher ;
 
-: links ( seq -- seq' )
-    [ swap <simple-link> ] { } assoc>map ;
+: fixup-words ( title href -- title' href' )
+    dup "word-" head? [
+        dup ".html" ?tail drop "," split1-last nip dup ":" append
+        '[ " (" _ 3append ")" append _ ?head drop ] dip
+    ] when ;
+
+: links ( apropos -- seq )
+    [ swap fixup-words <simple-link> ] { } assoc>map ;
+
+: ?links ( has-links? apropos -- has-links? seq/f )
+    links [ f ] [ nip t swap ] if-empty ;
+
+: ?tokenize ( str -- str' )
+    [ tokenize ] [ drop 1array ] recover ;
 
 :: <search-action> ( help-dir -- action )
     <page-action>
         { help-webapp "search" } >>template
         [
-            "search" param [ unicode:blank? ] trim [
+            f "search" param [ unicode:blank? ] trim
+            dup "search" set-value [
                 help-dir [
-                    [ article-apropos links "articles" set-value ]
-                    [ word-apropos links "words" set-value ]
-                    [ vocab-apropos links "vocabs" set-value ] tri
+                    ?tokenize concat
+                    [ article-apropos ?links "articles" set-value ]
+                    [ word-apropos ?links "words" set-value ]
+                    [ vocab-apropos ?links "vocabs" set-value ] tri
                 ] with-directory
-            ] unless-empty
-            help-navbar "navbar" set-value
+            ] unless-empty not "empty" set-value
+            help-nav "nav" set-value
 
             { help-webapp "search" } <chloe-content>
         ] >>display