Add ability to share draft posts
As a side effect of this change, any pending posts in your repository that are in "draft" status will effectively move into the new "draft" state, which means they can be reached by their URL. That's not a big deal though because those URLs are not trivial to guess. * tekuti/page-helpers.scm (post-editing-form): Add radio button to choose post status. * tekuti/post.scm (post-public?, post-draft?, post-private?): New accessors for post status. (post-from-key): Add #:allow-draft? keyword argument. * tekuti/page.scm (page-show-post): Allow direct access to draft posts.
This commit is contained in:
parent
7ecade64bd
commit
20e7658295
3 changed files with 34 additions and 13 deletions
|
@ -177,7 +177,7 @@
|
|||
""))))
|
||||
(label (@ (for "tags")) " <- tags, comma-separated"))
|
||||
(p (input (@ (name "date") (type "text")
|
||||
(value ,(if (and=> post post-published?)
|
||||
(value ,(if (and=> post post-public?)
|
||||
(timestamp->rfc822-date (post-timestamp post))
|
||||
""))))
|
||||
(label (@ (for "date")) " <- date (empty == now)"))
|
||||
|
@ -187,16 +187,27 @@
|
|||
(label (@ (for "comments")) " comments open?"))
|
||||
(div (textarea (@ (name "body") (rows "20") (cols "60"))
|
||||
,(if post (post-raw-content post) "")))
|
||||
(input (@ (type "submit") (name "status")
|
||||
(value "publish")))
|
||||
" "
|
||||
(input (@ (type "submit") (name "status")
|
||||
(value "draft"))))
|
||||
(p (label (input (@ (type "radio") (name "status") (value "private")
|
||||
,@(if (or (not post) (post-private? post))
|
||||
'((checked "checked"))
|
||||
'())))
|
||||
"Private (Only visible to admin)") (br)
|
||||
(label (input (@ (type "radio") (name "status") (value "draft")
|
||||
,@(if (or (not post) (post-draft? post))
|
||||
'((checked "checked"))
|
||||
'())))
|
||||
"Draft (Only accessible via direct link)") (br)
|
||||
(label (input (@ (type "radio") (name "status") (value "publish")
|
||||
,@(if (or (not post) (post-public? post))
|
||||
'((checked "checked"))
|
||||
'())))
|
||||
"Public") (br))
|
||||
(p (input (@ (type "submit")
|
||||
(value ,(if post "Modify post" "New post"))))))
|
||||
,@(if post
|
||||
`((form (@ (method "POST")
|
||||
(action ,(relurl `("admin" "delete-post" ,(post-key post)))))
|
||||
" "
|
||||
(input (@ (type "submit") (name "delete") (value "delete"))))
|
||||
(p (input (@ (type "submit") (name "delete") (value "delete")))))
|
||||
,@(let ((l (comments-sxml-content-edit post)))
|
||||
(if (null? l) l
|
||||
`((h2 "comments")
|
||||
|
|
|
@ -193,7 +193,8 @@
|
|||
|
||||
(define (page-show-post request body index year month day post)
|
||||
(cond
|
||||
((post-from-key index (make-post-key year month day post))
|
||||
((post-from-key index (make-post-key year month day post)
|
||||
#:allow-draft? #t)
|
||||
=> (lambda (post)
|
||||
(respond `(,(post-sidebar post index)
|
||||
,(show-post post #t))
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
#:use-module (srfi srfi-19)
|
||||
#:export (post-from-key
|
||||
|
||||
post-tags post-timestamp post-key post-published?
|
||||
post-tags post-timestamp post-key
|
||||
post-public? post-draft? post-private?
|
||||
post-comments-open? post-comments
|
||||
post-sxml-content post-readable-date post-n-comments
|
||||
post-raw-content
|
||||
|
@ -79,9 +80,11 @@
|
|||
;;; pulling posts out of the index
|
||||
;;;
|
||||
|
||||
(define* (post-from-key index key #:key allow-unpublished?)
|
||||
(define* (post-from-key index key #:key allow-unpublished? allow-draft?)
|
||||
(let ((post (hash-ref (assq-ref index 'posts) key)))
|
||||
(if (and post (or (post-published? post) allow-unpublished?))
|
||||
(if (and post (or (post-public? post)
|
||||
(and (post-draft? post) allow-draft?)
|
||||
allow-unpublished?))
|
||||
post
|
||||
#f)))
|
||||
|
||||
|
@ -89,9 +92,15 @@
|
|||
;;; accessors
|
||||
;;;
|
||||
|
||||
(define (post-published? post-alist)
|
||||
(define (post-public? post-alist)
|
||||
(equal? (assq-ref post-alist 'status) "publish"))
|
||||
|
||||
(define (post-draft? post-alist)
|
||||
(equal? (assq-ref post-alist 'status) "draft"))
|
||||
|
||||
(define (post-private? post-alist)
|
||||
(equal? (assq-ref post-alist 'status) "private"))
|
||||
|
||||
(define (post-timestamp post-alist)
|
||||
(assq-ref post-alist 'timestamp))
|
||||
|
||||
|
|
Loading…
Reference in a new issue