add support for deleting posts
This commit is contained in:
parent
66e04753f6
commit
9ec70ebff5
4 changed files with 31 additions and 4 deletions
|
@ -188,7 +188,11 @@
|
||||||
(input (@ (type "submit") (name "status")
|
(input (@ (type "submit") (name "status")
|
||||||
(value "draft"))))
|
(value "draft"))))
|
||||||
,@(if post
|
,@(if post
|
||||||
`((h2 "preview")
|
`((form (@ (method "POST")
|
||||||
|
(action ,(relurl `("admin" "delete-post" ,(post-key post)))))
|
||||||
|
" "
|
||||||
|
(input (@ (type "submit") (name "delete") (value "delete"))))
|
||||||
|
(h2 "preview")
|
||||||
,(show-post post #f))
|
,(show-post post #f))
|
||||||
'())))
|
'())))
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
page-admin-post
|
page-admin-post
|
||||||
page-admin-new-post
|
page-admin-new-post
|
||||||
page-admin-modify-post
|
page-admin-modify-post
|
||||||
|
page-admin-delete-post
|
||||||
page-admin-changes
|
page-admin-changes
|
||||||
page-admin-change
|
page-admin-change
|
||||||
page-admin-revert-change
|
page-admin-revert-change
|
||||||
|
@ -125,6 +126,13 @@
|
||||||
(respond `((p "redirecting..."))
|
(respond `((p "redirecting..."))
|
||||||
#:redirect (admin-post-url post))))))
|
#:redirect (admin-post-url post))))))
|
||||||
|
|
||||||
|
(define (page-admin-delete-post request body index key)
|
||||||
|
(with-authentication
|
||||||
|
request
|
||||||
|
(lambda ()
|
||||||
|
(delete-post key)
|
||||||
|
(respond `((p "redirecting...")) #:redirect (relurl `("admin"))))))
|
||||||
|
|
||||||
(define (page-admin-changes request body index)
|
(define (page-admin-changes request body index)
|
||||||
(with-authentication
|
(with-authentication
|
||||||
request
|
request
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
;; Tekuti
|
;; Tekuti
|
||||||
;; Copyright (C) 2008, 2010 Andy Wingo <wingo at pobox dot com>
|
;; Copyright (C) 2008, 2010, 2011 Andy Wingo <wingo at pobox dot com>
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; This program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
post-raw-content
|
post-raw-content
|
||||||
post-title
|
post-title
|
||||||
|
|
||||||
make-new-post modify-post
|
make-new-post modify-post delete-post
|
||||||
|
|
||||||
all-published-posts
|
all-published-posts
|
||||||
|
|
||||||
|
@ -201,6 +201,20 @@
|
||||||
(define (modify-post old-key post-data)
|
(define (modify-post old-key post-data)
|
||||||
(munge-post old-key (parse-post-data post-data)))
|
(munge-post old-key (parse-post-data post-data)))
|
||||||
|
|
||||||
|
(define (delete-post key)
|
||||||
|
(define (maybe-delete ops)
|
||||||
|
(if (and old-key (not (equal? old-key key)))
|
||||||
|
(cons ops)
|
||||||
|
ops))
|
||||||
|
(let* ((ops `((delete () (,key))))
|
||||||
|
(post (post-from-key "refs/heads/master" key))
|
||||||
|
(message (format #f "~a: \"~a\"" "post deleted" (post-title post))))
|
||||||
|
(git-update-ref "refs/heads/master"
|
||||||
|
(lambda (master)
|
||||||
|
(git-commit-tree (munge-tree master ops)
|
||||||
|
master message #f))
|
||||||
|
5)))
|
||||||
|
|
||||||
(define (all-posts master)
|
(define (all-posts master)
|
||||||
(map (lambda (pair)
|
(map (lambda (pair)
|
||||||
(post-from-tree (car pair) (cdr pair)))
|
(post-from-tree (car pair) (cdr pair)))
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
((POST admin new-post) page-admin-new-post)
|
((POST admin new-post) page-admin-new-post)
|
||||||
;; would be fine to have e.g. (DELETE admin posts posts-key!), but
|
;; would be fine to have e.g. (DELETE admin posts posts-key!), but
|
||||||
;; web browsers don't handle that
|
;; web browsers don't handle that
|
||||||
|
((POST admin delete-post post-key!) page-admin-delete-post)
|
||||||
((POST admin modify-post post-key!) page-admin-modify-post)
|
((POST admin modify-post post-key!) page-admin-modify-post)
|
||||||
((GET admin changes) page-admin-changes)
|
((GET admin changes) page-admin-changes)
|
||||||
((GET admin changes sha1!) page-admin-change)
|
((GET admin changes sha1!) page-admin-change)
|
||||||
|
|
Loading…
Reference in a new issue