;; free variables in this example: ;; base-dir: app web base dir. E.g., /mario ;; wiki-dir: filesystem path to the directory where wiki pages will be stored ;; define-auth-page: a wrapper around define-page which requires authentication (define-auth-page (irregex (make-pathname (main-page-path) "wiki/[^/]*")) (lambda (path) (with-request-variables ((edit (nonempty as-boolean)) content) (let ((wiki-file (make-pathname wiki-dir (if (equal? path (make-pathname (list base-dir "wiki") #f)) "index" (pathname-strip-directory path))))) (cond (edit `(form (@ (action ,path) (method post)) (textarea (@ (name "content") (autofocus) (rows 30)) ,(if (file-exists? wiki-file) (read-all wiki-file) "")) (br) (input (@ (type "submit") (value "Save"))))) (content (if (equal? content "") (begin (when (file-read-access? wiki-file) (delete-file wiki-file)) (redirect-to (make-pathname (list base-dir "wiki") #f))) (begin (with-output-to-file wiki-file (cut print content)) (redirect-to path)))) (else (if (file-read-access? wiki-file) `(,(with-input-from-file wiki-file markdown->sxml) (a (@ (href ,(string-append path "?edit=1"))) "Edit") " " (a (@ (href "https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet") (target "_blank")) "Help") (hr) (ul (@ (id "wiki-pages-listing")) ,@(map (lambda (file) `(li (a (@ (href ,(make-pathname (list base-dir "wiki") file))) ,file))) (sort (directory wiki-dir) string<)))) (redirect-to (string-append path "?edit=1")))))))) method: '(get post))