(use awful irregex posix utils lowdown srfi-13) (define wiki-dir "wiki") (create-directory wiki-dir 'recursively) (define starting-page "WelcomeVisitors") (define all-pages "AllPages") (enable-sxml #t) (define-page (irregex "/[^/]*") (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) (content (nonempty as-string))) (when (equal? path "/") (redirect-to starting-page)) (let ((edit-path (string-append path "?edit=1")) (wiki-file (make-pathname wiki-dir path)) (page-name (string-trim path #\/))) `((h1 ,page-name) (hr) ,(cond ((equal? page-name "AllPages") `(ul ,@(map (lambda (f) `(li (a (@ (href ,(pathname-file f))) ,(pathname-file f)))) (find-files wiki-dir)))) (edit `(form (@ (action ,path) (method post)) (textarea (@ (name "content") (cols 80) (rows 50) (autofocus)) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (input (@ (type "submit") (value "Save"))))) (content (with-output-to-file wiki-file (cut print content)) (redirect-to path)) (else `(,(if (file-exists? wiki-file) `((pre ,(read-all wiki-file)) (hr) (a (@ (href ,edit-path)) "Edit")) `((p "The page " ,page-name " does not exist yet.") (hr) (a (@ (href ,edit-path)) "Create"))) " | ") )) (a (@ (href ,starting-page)) "Home") " | " (a (@ (href ,all-pages)) "AllPages"))))) method: '(get post))