aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-08-23 00:06:42 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-08-23 00:06:42 +0200
commite8d00149cf0bdca3c613c5317fc0618c1742550e (patch)
treef79fb498eeca0696aaa726de40c9d42f3eb17271
parentSome benchmarking impmrovements. (diff)
downloadcalp-e8d00149cf0bdca3c613c5317fc0618c1742550e.tar.gz
calp-e8d00149cf0bdca3c613c5317fc0618c1742550e.tar.xz
GET /search without query now works.
-rw-r--r--module/calp/server/routes.scm15
-rw-r--r--module/html/view/search.scm7
2 files changed, 12 insertions, 10 deletions
diff --git a/module/calp/server/routes.scm b/module/calp/server/routes.scm
index 29a620b0..02bbd123 100644
--- a/module/calp/server/routes.scm
+++ b/module/calp/server/routes.scm
@@ -345,14 +345,15 @@
(return (build-response code: 404)
(format #f "No component with UID=~a found." uid))))
- ;; TODO search without query should work
(GET "/search" (q p)
- (define search-term (prepare-string q))
+ (define search-term (and=> q prepare-string))
- (define q= (find (lambda (s)
- (and (<= 2 (string-length s))
- (string=? "q=" (string-take s 2))))
- (string-split r:query #\&)))
+ ;; keep original string for links below. Should guarantee that it's correct.
+ (define q= (if (not q)
+ "" (find (lambda (s)
+ (and (<= 2 (string-length s))
+ (string=? "q=" (string-take s 2))))
+ (string-split r:query #\&))))
(define paginator (get-query-page search-term))
@@ -381,7 +382,7 @@
(lambda ()
(sxml->xml
(search-result-page
- search-term search-result page paginator q=))))))
+ q search-term search-result page paginator q=))))))
;; NOTE this only handles files with extensions. Limited, but since this
;; is mostly for development, and something like nginx should be used in
diff --git a/module/html/view/search.scm b/module/html/view/search.scm
index 2b93ebfc..12d8399f 100644
--- a/module/html/view/search.scm
+++ b/module/html/view/search.scm
@@ -10,7 +10,7 @@
)
(define-public (search-result-page
- search-term search-result page paginator q=)
+ has-query? search-term search-result page paginator q=)
(xhtml-doc
(@ (lang sv))
(head (title "Search results")
@@ -20,8 +20,9 @@
(form
(pre (textarea (@ (name "q") (rows 5) (spellcheck false)
(style "width:100%"))
- ,(with-output-to-string
- (lambda () (pretty-print search-term)))))
+ ,(when has-query?
+ (with-output-to-string
+ (lambda () (pretty-print search-term))))))
(input (@ (type submit))))
(h2 "Result (page " ,page ")")
(ul