aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob/dynamic/capabilities/comment-form.scm
diff options
context:
space:
mode:
Diffstat (limited to 'haunt/jakob/dynamic/capabilities/comment-form.scm')
-rw-r--r--haunt/jakob/dynamic/capabilities/comment-form.scm88
1 files changed, 49 insertions, 39 deletions
diff --git a/haunt/jakob/dynamic/capabilities/comment-form.scm b/haunt/jakob/dynamic/capabilities/comment-form.scm
index 6937d15..29e00ec 100644
--- a/haunt/jakob/dynamic/capabilities/comment-form.scm
+++ b/haunt/jakob/dynamic/capabilities/comment-form.scm
@@ -29,44 +29,49 @@
#:use-module (web request)
#:use-module (web response)
#:use-module (web uri)
- #:export (render-comment-form-success
+ #:export (render-comment-form
+
+ render-comment-form-success
render-comment-form-failure
get-comment-form))
-(define (render-comment-form slug)
- (let-values (((captcha-id captcha-image) (new-captcha!)))
- `((div (@ (id "comment-form"))
- (h1 "Comment form")
- (form (@ (id "comment-input") (action "/api/comment") (method "post"))
- (input (@ (type "text") (name "slug") (hidden #t) (value ,slug)))
- (input (@ (type "text") (name "captcha-id") (hidden #t) (value ,captcha-id)))
- (fieldset (@ (id "commenter-info"))
- (legend "Commenter Info")
- (label (@ (for "name")) "Name:")
- (input (@ (type "text") (id "name") (name "name") (required #t) (size 24)))
- (label (@ (for "email")) "Email (optional, used for Gravatar):")
- (input (@ (type "text") (id "email") (name "email") (size 24)))
- (label (@ (for "url")) "Webpage URL (optional):")
- (input (@ (type "text") (id "url") (name "url") (size 24))))
- (fieldset (@ (id "comment-content"))
- (legend "Comment")
- (label (@ (for "subject")) "Subject (optional):")
- (input (@ (type "text") (id "subject") (name "subject") (size 24)))
- (label (@ (for "comment")) "Comment :")
- (textarea (@ (id "coment") (name "comment") (rows 4) (cols 50))))
- (fieldset (@ (id "comment-captcha"))
- (legend "Captcha")
- (label (@ (for "captcha")) "Please evaluate the following definite integral:")
- (img (@ (src ,(format #f "data:image/jpeg;charset=utf-8;base64,~a"
- (base64-encode captcha-image)))))
- (input (@ (type "text") (id "captcha") (name "captcha") (size 24)))
- (button (@ (id "pow-trigger") (hidden #t))
- "Too hard? (Or unable to see the challenge?) Click here.")
- (input (@ (type "text") (id "captcha-alt") (name "captcha-alt") (hidden #t)))
- (input (@ (type "text") (id "captcha-alt-id") (name "captcha-alt-id") (hidden #t)))
- (input (@ (type "submit") (id "submit-form") (value "Submit")))))
- ,(script "proof-of-work.js")))))
+(define* (render-comment-form slug #:key (header-level 'h1) (captcha-id "") captcha-image)
+ `(div (@ (id "comment-form"))
+ (,header-level "Comment form")
+ (form (@ (id "comment-input") (action "/api/comment") (method "post"))
+ (input (@ (type "text") (name "slug") (hidden #t) (value ,slug)))
+ (input (@ (type "text") (id "captcha-id") (name "captcha-id") (hidden #t) (autocomplete "off") (value ,captcha-id)))
+ (fieldset (@ (id "commenter-info"))
+ (legend "Commenter Info")
+ (label (@ (for "name")) "Name:")
+ (input (@ (type "text") (id "name") (name "name") (required #t) (size 24)))
+ (label (@ (for "email")) "Email (optional, used for Gravatar):")
+ (input (@ (type "text") (id "email") (name "email") (size 24)))
+ (label (@ (for "url")) "Webpage URL (optional):")
+ (input (@ (type "text") (id "url") (name "url") (size 24))))
+ (fieldset (@ (id "comment-content"))
+ (legend "Comment")
+ (label (@ (for "subject")) "Subject (optional):")
+ (input (@ (type "text") (id "subject") (name "subject") (size 24)))
+ (label (@ (for "comment")) "Comment :")
+ (textarea (@ (id "coment") (name "comment") (rows 4) (cols 50))))
+ (fieldset (@ (id "comment-captcha"))
+ (legend "Captcha")
+ (label (@ (for "captcha")) "Please evaluate the following definite integral:")
+ (img (@ (id "captcha-image")
+ (src ,(if captcha-image
+ (format #f "data:image/jpeg;charset=utf-8;base64,~a"
+ (base64-encode captcha-image))
+ ""))))
+ (input (@ (type "text") (id "captcha") (name "captcha") (size 24)))
+ (button (@ (id "pow-trigger") (hidden #t))
+ "Too hard? (Or unable to see the challenge?) Click here.")
+ (input (@ (type "text") (id "captcha-alt") (name "captcha-alt") (hidden #t)))
+ (input (@ (type "text") (id "captcha-alt-id") (name "captcha-alt-id") (hidden #t)))
+ (input (@ (type "submit") (id "submit-form") (value "Submit")))))
+ ,(script "dynamic-comment-form.js")
+ ,(script "proof-of-work.js")))
(define (render-comment-form-success slug)
`((div (h1 "Success!")
@@ -77,8 +82,13 @@
"API endpoint handler for querying for the comments on a particular post
This is a wrapper around `get-comments-by-slug'."
- (let* ((path-encoded (uri-path (request-uri request)))
- (path (split-and-decode-uri-path path-encoded))
- (slug (last path)))
- (values '((content-type . (text/html)))
- (sxml->html-string (theme #:content (render-comment-form slug) #:title "Comment prompt")))))
+ (let-values (((captcha-id captcha-image) (new-captcha!)))
+ (let* ((path-encoded (uri-path (request-uri request)))
+ (path (split-and-decode-uri-path path-encoded))
+ (slug (last path))
+ (form (render-comment-form slug
+ #:captcha-id captcha-id
+ #:captcha-image captcha-image)))
+ (values '((content-type . (text/html)))
+ (sxml->html-string
+ (theme #:content form #:title "Comment prompt"))))))

© 2015 - 2026 Jakob L. Kreuze