namespaces added and documentation

This commit is contained in:
2026-08-15 15:01:50 +02:00
parent b9e081b13d
commit 8997f7f94a
20 changed files with 696 additions and 158 deletions
+19 -7
View File
@@ -1,5 +1,9 @@
#lang racket/base
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HTTP routing and server-rendered setup/login handling.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require net/url
net/uri-codec
racket/file
@@ -19,6 +23,10 @@
(provide start-wiki-server)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Supporting functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (user->jsexpr user)
(hash 'id (wiki-user-id user)
'username (wiki-user-username user)
@@ -244,7 +252,7 @@ CSS
(require-role
config req 'reader
(λ (_session)
(define page (and (valid-slug? slug) (read-page config slug)))
(define page (and (valid-page-reference? slug) (read-page config slug)))
(if page
(json-response page)
(json-error 404 "Page not found")))))
@@ -264,20 +272,22 @@ CSS
(with-handlers ((exn:fail? (λ (e) (json-error 400 (exn-message e)))))
(define body (request-json req))
(define requested-slug (hash-ref body 'slug #f))
(define namespace (string-trim (hash-ref body 'namespace "")))
(define title (hash-ref body 'title ""))
(define markdown (hash-ref body 'markdown ""))
(define tags (request-tags body))
(define summary (hash-ref body 'summary "Created page"))
(define slug
(if requested-slug
requested-slug
(title->slug title)))
(cond
(requested-slug requested-slug)
((string=? namespace "") (title->slug title))
(else (page-reference namespace (title->slug title)))))
(cond
((string=? (string-trim title) "")
(json-error 400 "Title is required"))
((string=? slug "")
(json-error 400 "The title cannot be converted to a page slug"))
((not (valid-slug? slug))
((not (valid-page-reference? slug))
(json-error 400 "Invalid page address"))
((read-page config slug)
(json-error 409 "A page with this address already exists"))
@@ -303,6 +313,7 @@ CSS
(json-error 400 (exn-message e))))))
(define body (request-json req))
(define title (hash-ref body 'title ""))
(define namespace (hash-ref body 'namespace #f))
(define markdown (hash-ref body 'markdown ""))
(define tags (request-tags body))
(define base-version (hash-ref body 'baseVersion ""))
@@ -315,7 +326,8 @@ CSS
(wiki-user-username (wiki-session-user session))
base-version
summary
tags))))))
tags
namespace))))))
(define (page-delete-handler config req slug)
(require-write-role
@@ -594,7 +606,7 @@ CSS
(cond
((not session)
(redirect-response "/login"))
((and slug (valid-slug? slug))
((and slug (valid-page-reference? slug))
(let ((page (read-page config slug)))
(cond
(page