aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-08-07 00:16:55 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-08-07 00:16:55 +0200
commitcc98157480c9d0e1ada985d671d5990dfa550a63 (patch)
tree9382fc56c7dbf7401234a72549a9441ffbf864ad
parentServer Uri-decode query string. (diff)
downloadcalp-cc98157480c9d0e1ada985d671d5990dfa550a63.tar.gz
calp-cc98157480c9d0e1ada985d671d5990dfa550a63.tar.xz
Add rudementary search page to HTML.
-rw-r--r--module/entry-points/server.scm32
1 files changed, 29 insertions, 3 deletions
diff --git a/module/entry-points/server.scm b/module/entry-points/server.scm
index 4e6332ad..14d929f2 100644
--- a/module/entry-points/server.scm
+++ b/module/entry-points/server.scm
@@ -29,6 +29,7 @@
:use-module (server macro)
:use-module (vcomponent)
+ :use-module (vcomponent search)
:use-module (datetime)
:use-module (output html)
:use-module (output ical)
@@ -211,9 +212,9 @@
(return '((content-type application/xml))
(with-output-to-string
(lambda ()
- (sxml->xml
- `(properties
- (uid (text ,(prop event 'UID)))))))))))
+ (sxml->xml
+ `(properties
+ (uid (text ,(prop event 'UID)))))))))))
;; Get specific page by query string instead of by path.
;; Useful for <form>'s, since they always submit in this form, but also
@@ -269,6 +270,31 @@
(return (build-response code: 404)
(format #f "No component with UID=~a found." uid))))
+ (GET "/search" (q)
+ (define query-proc (build-query-proc q))
+ (define query (prepare-query
+ query-proc
+ (get-event-set global-event-object)))
+
+ (define search-result
+ (execute-query query 0))
+
+ (return '((content-type text/html #; application/xhtml+xml
+ ))
+ (with-output-to-string
+ (lambda ()
+ (sxml->xml
+ `(*TOP*
+ (*PI* xml "version=\"1.0\" encoding=\"utf-8\"")
+ (html
+ (head (title "Search results"))
+ (body
+ (h2 "Search term")
+ (pre ,(format #f "~y" q))
+ ,@(for event in search-result
+ `(div (@ (class "event"))
+ ,(prop event 'SUMMARY)))))))))))
+
;; NOTE this only handles files with extensions. Limited, but since this
;; is mostly for development, and something like nginx should be used in
;; production it isn't a huge problem.