diff options
Diffstat (limited to 'haunt/jakob/builder/htaccess.scm')
| -rw-r--r-- | haunt/jakob/builder/htaccess.scm | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/haunt/jakob/builder/htaccess.scm b/haunt/jakob/builder/htaccess.scm index fd20eca..e0068d1 100644 --- a/haunt/jakob/builder/htaccess.scm +++ b/haunt/jakob/builder/htaccess.scm @@ -16,20 +16,35 @@ (define-module (jakob builder htaccess) #:use-module (haunt page) + #:use-module (ice-9 match) #:export (htaccess)) +;; Good resource: +;; <https://perishablepress.com/stupid-htaccess-tricks/#ess4> + (define* (htaccess-writer contents #:optional (port (current-output-port))) (display (string-join contents "\n") port) (newline port)) -;; TODO: https://help.dreamhost.com/hc/en-us/articles/215747748-How-can-I-redirect-and-rewrite-my-URLs-with-an-htaccess-file- -(define* (htaccess #:key handler-404) +(define* (htaccess #:key + (error-documents '()) + (redirects '())) "Create an .htaccess file at the site's root. -HANDLER-404 specifies the file name of the page to display for a 404 not found." +ERROR-DOCUMENTS specifies the file name of the page to display for a specific +HTTP error code: a list of (error-code . file-name) pairs. + +REDIRECTS specifies file names to show for certain requests: a list of (pattern +. file-name) pairs." (define contents - `(,(if handler-404 - (format #f "ErrorDocument 404 ~a" handler-404)))) + `(,@(map (match-lambda + ((code . file-name) + (format #f "ErrorDocument ~a ~a" code file-name))) + error-documents) + ,@(map (match-lambda + ((pattern . file-name) + (format #f "RewriteRule ~a ~a" pattern file-name))) + redirects))) (lambda (site posts) (make-page ".htaccess" contents htaccess-writer))) |