(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)) (search (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))) (hr))) (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)) (search `((h2 "Search results for " ,search) (ul ,(with-input-from-pipe (sprintf "grep -ri ~a ~s" (qs search) wiki-dir) (lambda () (map (lambda (l) (let* ((r (string-split l ":")) (p (pathname-file (car r))) (c (cdr r))) `(li (a (@ (href ,p)) ,p) " : " ,c))) (read-lines))))))) (else `(,(if (file-exists? wiki-file) `(,(with-input-from-file wiki-file markdown->sxml) (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") (form (@ (action ,path) (method post)) (input (@ (type "text") (name "search"))) (input (@ (type "submit") (value "Search")))))))) method: '(get post))