From f8ba6df7cd5111226b0cf63d228a3c25400ebd8b Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Thu, 31 May 2007 10:33:46 +0200 Subject: Abstract anchor creation away. darcs-hash:04a94f24ffe339c67067ac90baa4764cc8903623 --- journal.lisp | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/journal.lisp b/journal.lisp index d4b867d..effb26d 100755 --- a/journal.lisp +++ b/journal.lisp @@ -57,7 +57,7 @@ and :POST-COMMENT.") (defparameter *post-number* - (parse-integer (getf *query* :post "") + (parse-integer (getf *query* :id "") :junk-allowed t #|| :radix 12 ||#) "The identification number of the journal entry to be acted upon. May be NIL.") @@ -327,8 +327,23 @@ after another in any arbitrary order." (format out "~A" substring)))))))))) +(defun link-to (action &key post-id (absolute nil)) + (with-output-to-string (out) + (format out (if absolute + "http://benkard.nfshost.com/journal/journal.cgi" + "journal.cgi")) + + (multiple-value-call + #'(lambda (&rest args) (apply #'format out args)) + (case action + (:index "") + (:view-atom-feed (values "?action=view-atom-feed")) + (:view (values "?action=view&id=~D" post-id)) + (:edit (values "?action=edit&id=~D" post-id)) + (:post-comment (values "?action=view&id=~D" post-id)))))) + + (defun show-atom-feed () - (http-add-header "Content-type" "application/atom+xml; charset=UTF-8") (http-send-headers "application/atom+xml; charset=UTF-8") (flet ((atom-time (time) @@ -374,7 +389,9 @@ after another in any arbitrary order." :published (atom-time date)) (with-tag ("link" `(("rel" "alternate") ("type" "text/html") - ("href" ,(format nil "http://benkard.nfshost.com/journal/journal.cgi?action=view&post=~D" id))))) + ("href" ,(link-to :view + :post-id id + :absolute t))))) (with-tag ("content" '(("type" "xhtml") ("xml:lang" "de") ("xml:base" "http://benkard.nfshost.com/journal"))) @@ -396,9 +413,7 @@ after another in any arbitrary order." (defun show-journal-entry (journal-entry &key (comments-p nil)) (<:div :class :journal-entry - (<:h2 (<:a :href (format nil - "journal.cgi?action=view&post=~D" - (id-of journal-entry)) + (<:h2 (<:a :href (link-to :view :post-id (id-of journal-entry)) (<:as-html (title-of journal-entry)))) (<:div :class :journal-entry-header (<:span :class :journal-entry-date @@ -415,13 +430,13 @@ after another in any arbitrary order." (<:form :class :journal-entry-delete-button-form :style "display: inline;" :method "post" - :action "journal.cgi" + :action (link-to :index) (<:div :style "display: inline;" (<:input :type "hidden" :name "action" :value "delete") (<:input :type "hidden" - :name "post" + :name "id" :value (prin1-to-string (id-of journal-entry))) (<:button :type "submit" (<:as-is "Löschen")))) @@ -429,25 +444,18 @@ after another in any arbitrary order." (<:form :class :journal-entry-delete-button-form :style "display: inline;" :method "get" - :action "journal.cgi" + :action (link-to :index) (<:div :style "display: inline;" (<:input :type "hidden" :name "action" :value "edit") (<:input :type "hidden" - :name "post" + :name "id" :value (prin1-to-string (id-of journal-entry))) (<:button :type "submit" (<:as-is "Bearbeiten")))) - #+nil - (<:a :href (format nil - "journal.cgi?action=edit&post=~D" - (id-of journal-entry)) - (<:as-is "Bearbeiten")) " | " - (<:a :href (format nil - "journal.cgi?action=view&post=~D" - (id-of journal-entry)) + (<:a :href (link-to :view :post-id (id-of journal-entry)) (<:as-is (format nil "~D Kommentar~:*~[e~;~:;e~]" (length (comments-about journal-entry))))))) @@ -475,12 +483,12 @@ after another in any arbitrary order." (<:p (<:as-is "Bitte beachten Sie, daß E-Mail-Adressen niemals veröffentlicht werden und nur von Matthias eingesehen werden können.")) - (<:form :action "journal.cgi" + (<:form :action (link-to :view :post-id (id-of journal-entry)) :method "post" :accept-charset "UTF-8" (<:div :style "display: hidden" (<:input :type "hidden" - :name "post" + :name "id" :value (prin1-to-string (id-of journal-entry))) (<:input :type "hidden" :name "action" @@ -522,7 +530,6 @@ after another in any arbitrary order." (defun show-web-journal () - (http-add-header "Content-type" "text/html; charset=UTF-8") (http-send-headers "text/html; charset=UTF-8") (