summaryrefslogtreecommitdiff
path: root/tissue/document.scm
diff options
context:
space:
mode:
authorArun Isaac2022-06-29 00:18:18 +0530
committerArun Isaac2022-06-29 00:18:18 +0530
commita8023a99111233fec4b6050c6de3130097e84483 (patch)
tree0614a2f25b75b69ddd0a928b4bd4f63ad265514e /tissue/document.scm
parent58dcd6b052a61229e0ceb021076a1f450a80aea9 (diff)
downloadtissue-a8023a99111233fec4b6050c6de3130097e84483.tar.gz
tissue-a8023a99111233fec4b6050c6de3130097e84483.tar.lz
tissue-a8023a99111233fec4b6050c6de3130097e84483.zip
web: server: Add web server for search.
* tissue/web/server.scm: New file. * tissue/document.scm (document-sxml-snippet): New public function. (document->sxml): New generic method. * tissue/issue.scm: Import (web uri). (document->sxml): New generic method. * bin/tissue: Import (system repl server) and (tissue web server). (address->socket-address, tissue-run-web): New function. (print-usage): List `tissue run-web' subcommand. (main): Call tissue-run-web.
Diffstat (limited to 'tissue/document.scm')
-rw-r--r--tissue/document.scm38
1 files changed, 38 insertions, 0 deletions
diff --git a/tissue/document.scm b/tissue/document.scm
index 86fa548..2806f3b 100644
--- a/tissue/document.scm
+++ b/tissue/document.scm
@@ -41,6 +41,8 @@
document-term-generator
document-snippet
print
+ document-sxml-snippet
+ document->sxml
<file-document>
file-document-path
read-gemtext-document))
@@ -206,6 +208,42 @@ MSet object representing a list of search results."
(newline)
(newline))))
+(define (document-sxml-snippet document mset)
+ "Return snippet in SXML form for DOCUMENT. MSET is the xapian MSet
+object representing a list of search results."
+ ;; mset-snippet returns serialized HTML. So, we reverse it with
+ ;; html->sxml.
+ (match (html->sxml (mset-snippet mset
+ (document-text document)
+ #:length 200
+ #:highlight-start "<b>"
+ #:highlight-end "</b>"
+ #:stemmer (make-stem "en")))
+ (('*TOP* children ...)
+ (append-map (lambda (child)
+ (cond
+ ;; Add (br) if end of line.
+ ((and (string? child)
+ (string-suffix? "\n" child))
+ (list (string-trim-right child #\newline)
+ '(br)))
+ ;; Else, return verbatim.
+ (else
+ (list child))))
+ children))))
+
+(define-method (document->sxml (document <file-document>) mset)
+ "Render DOCUMENT to SXML. MSET is the xapian MSet object representing
+a list of search results."
+ `(li (@ (class "search-result"))
+ (a (@ (href ,(document-web-uri document)))
+ ,(document-title document))
+ ,@(let ((snippet (document-sxml-snippet document mset)))
+ (if snippet
+ (list `(span (@ (class "search-result-snippet"))
+ ,@snippet))
+ (list)))))
+
(define (read-gemtext-document file)
"Reade gemtext document from FILE. Return a <file-document> object."
(make <file-document>