From 7b2e58eafb5562ca425075e112746b0ab33a0869 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Sat, 28 Dec 2019 20:34:37 -0500 Subject: Let's try this again... --- haunt/jakob/builder/htaccess.scm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'haunt/jakob/builder/htaccess.scm') 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: +;; + (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))) -- cgit v1.3