From cfc072a57916c99d8304d6f478acd6860cb49d10 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 24 Dec 2022 23:22:45 +0000 Subject: bin: Pass along entire project configuration object to servers. Themes should be free to access the entirety of the project configuration. It is impossible to predict which parts of the project configuration they will need. * bin/tissue (tissue-web, tissue-web-dev): Pass entire configuration object to start-web-server and start-dev-web-server respectively. * tissue/web/dev.scm: Import (tissue tissue). (handler, start-dev-web-server): Accept entire configuration object. * tissue/web/server.scm: Import (tissue tissue). (search-handler, start-web-server): Accept entire configuration object. --- tissue/web/dev.scm | 17 +++++++++-------- tissue/web/server.scm | 7 ++++--- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'tissue') diff --git a/tissue/web/dev.scm b/tissue/web/dev.scm index ba43930..7f29be6 100644 --- a/tissue/web/dev.scm +++ b/tissue/web/dev.scm @@ -26,21 +26,22 @@ #:use-module (web server) #:use-module (web uri) #:use-module (xapian xapian) + #:use-module (tissue tissue) #:use-module (tissue utils) #:use-module (tissue web server) #:use-module (tissue web static) #:export (start-dev-web-server)) -(define (handler request body xapian-index css files) +(define (handler request body xapian-index project) "Handle web @var{request} with @var{body} and return two values---the response headers and body. See @code{start-dev-web-server} for -documentation of @var{xapian-index}, @var{css} and @var{files}." +documentation of @var{xapian-index} and @var{project}." (let ((path (uri-path (request-uri request)))) (log-request request) (cond ;; Search page ((member path (list "/" "/search")) - (search-handler request body xapian-index css)) + (search-handler request body xapian-index project)) ;; Files ((any (lambda (web-file) (cond @@ -50,7 +51,7 @@ documentation of @var{xapian-index}, @var{css} and @var{files}." (try-paths path)) => (cut file <> (file-writer web-file))) (else #f))) - files) + (tissue-configuration-web-files project)) => (lambda (file) (values `((content-type . ,(mime-type-for-extension (file-name-extension (file-name file))))) @@ -62,17 +63,17 @@ documentation of @var{xapian-index}, @var{css} and @var{files}." (else (404-response request))))) -(define (start-dev-web-server port xapian-index css files) +(define (start-dev-web-server port xapian-index project) "Start development web server listening on @var{port}. @var{xapian-index} is the path to the Xapian index to -search in. @var{css} is a URI to a stylesheet. @var{files} is a list -of @code{} objects describing files to serve." +search in. @var{project} is a @code{} object +describing the project." (format (current-error-port) "Tissue development web server listening at http://localhost:~a~%" port) ;; Explicitly dereference the module and handler variable each time ;; so as to support live hacking. (run-server (cut (module-ref (resolve-module '(tissue web dev)) 'handler) - <> <> xapian-index css files) + <> <> xapian-index project) 'http (list #:port port))) diff --git a/tissue/web/server.scm b/tissue/web/server.scm index 1e6d04b..e9665ec 100644 --- a/tissue/web/server.scm +++ b/tissue/web/server.scm @@ -41,6 +41,7 @@ #:use-module (tissue document) #:use-module (tissue git) #:use-module (tissue search) + #:use-module (tissue tissue) #:use-module (tissue utils) #:export (log-request mime-type-for-extension @@ -237,7 +238,7 @@ query. QUERY and FILTER are Xapian Query objects." db (new-Query (Query-OP-FILTER) query filter)) #:maximum-items (database-document-count db)))) -(define (search-handler request body xapian-index css) +(define (search-handler request body xapian-index project) (let* ((path (uri-path (request-uri request))) (parameters (query-parameters (uri-query (request-uri request)))) (search-query (or (assoc-ref parameters "query") @@ -280,7 +281,7 @@ query. QUERY and FILTER are Xapian Query objects." '() mset)) search-query - css + (tissue-configuration-web-css project) #:page-uri-path path #:page-uri-parameters parameters #:matches (matches db query (Query-MatchAll)) @@ -320,7 +321,7 @@ See `start-web-server' for documentation of HOSTS." ((member path (list "/" "/search")) (search-handler request body (assq-ref host-parameters 'xapian-directory) - (assq-ref host-parameters 'css))) + (assq-ref host-parameters 'project))) ;; Static files ((let ((file-path (find file-exists? -- cgit v1.2.3