diff options
authorArun Isaac2022-12-24 23:22:45 +0000
committerArun Isaac2022-12-24 23:30:26 +0000
commitcfc072a57916c99d8304d6f478acd6860cb49d10 (patch)
parentf0cef5898e5e9b9149f6bb71df056c59c357d1e6 (diff)
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.
3 files changed, 15 insertions, 14 deletions
diff --git a/bin/tissue b/bin/tissue
index 2c05552..47c9c6f 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -278,7 +278,7 @@ Serve repositories specified in CONFIG-FILE over HTTP.
(parameterize ((%current-git-repository
(repository-open repository-directory)))
(cons name
- `((css . ,(tissue-configuration-web-css (load-config)))
+ `((project . ,(load-config))
(repository-directory . ,repository-directory)
(website-directory . ,(string-append state-directory "/" name "/website"))
(xapian-directory . ,(string-append state-directory "/" name "/xapian"))
@@ -311,8 +311,7 @@ Serve website and issues of current repository.
(start-repl (assq-ref args 'listen-repl)))
(start-dev-web-server (assq-ref args 'port)
- (tissue-configuration-web-css (load-config))
- (tissue-configuration-web-files (load-config)))))))
+ (load-config))))))
(define (print-usage)
(format #t "Usage: ~a COMMAND [OPTIONS] [ARGS]
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)
;; 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)
@@ -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}."
(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{<file>} objects describing files to serve."
+search in. @var{project} is a @code{<tissue-configuration>} 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))
- <> <> xapian-index css files)
+ <> <> xapian-index project)
(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
@@ -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."
- 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?