summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2009-10-11 12:15:57 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2009-10-11 12:15:57 +0200
commit561d5f1ea1de0d0af6938c9e446efb87e6b03ea0 (patch)
tree9d08a3edbd1b4b3b3221aa4adbcf6b82e53547b2
parent829d433565ac1d0c901a84c01cf004ad714379bb (diff)
Implement output of static HTML and XML files.
Ignore-this: 724acb08b4c75c08913325b2ebb7cb4f darcs-hash:e011eaebcaaccaef973cb0de5870dbfcbc94d8ac
-rw-r--r--globals.lisp3
-rwxr-xr-xjournal.lisp44
-rw-r--r--main.lisp5
3 files changed, 52 insertions, 0 deletions
diff --git a/globals.lisp b/globals.lisp
index 67d78b7..83eb4f9 100644
--- a/globals.lisp
+++ b/globals.lisp
@@ -69,6 +69,9 @@
(defparameter *cache-dir* nil
"The directory used for caching generated markup.")
+(defparameter *static-dir* nil
+ "The directory which all the generated HTML files will live in.")
+
(defparameter *wordpress-key* nil
"The WordPress/Akismet API key to use.")
diff --git a/journal.lisp b/journal.lisp
index 317f87a..20d2558 100755
--- a/journal.lisp
+++ b/journal.lisp
@@ -698,3 +698,47 @@
(<:h2 (<:as-html x))
(<:p "Type " (<:em (<:as-html (type-of y))) ".")
(<:pre (<:as-html (prin1-to-string y))))))))
+
+(defun update-journal ()
+ (format t "~&Updating index page...")
+ (update-index-page)
+ (format t "~&Updating individual journal entries...")
+ (update-all-journal-entry-pages)
+ (format t "~&Updating the news feeds...")
+ (update-atom-feed)
+ (update-comment-feed))
+
+(defun update-index-page ()
+ (let ((file-path (merge-pathnames "index.html" *static-dir*)))
+ (with-open-file (*standard-output* file-path :direction :output :if-exists :supersede)
+ (with-yaclml-stream *standard-output*
+ (let ((*mode* :file))
+ (show-web-journal))))))
+
+(defun update-all-journal-entry-pages ()
+ #.(locally-enable-sql-reader-syntax)
+ (dolist (entry (select 'journal-entry :order-by '(([id] :asc)) :flatp t))
+ (update-journal-entry-page entry))
+ #.(restore-sql-reader-syntax-state))
+
+(defun update-journal-entry-page (entry)
+ (with-slots (id title) entry
+ (let* ((file-name (format nil "~D.html" id))
+ (file-path (merge-pathnames file-name *static-dir*)))
+ (with-open-file (*standard-output* file-path :direction :output :if-exists :supersede)
+ (with-yaclml-stream *standard-output*
+ (let ((*mode* :file))
+ (with-web-journal (title)
+ (show-journal-entry entry :comments-p t))))))))
+
+(defun update-atom-feed ()
+ (let ((file-path (merge-pathnames "feed.xml" *static-dir*)))
+ (with-open-file (*standard-output* file-path :direction :output :if-exists :supersede)
+ (let ((*mode* :file))
+ (show-atom-feed)))))
+
+(defun update-comment-feed ()
+ (let ((file-path (merge-pathnames "comment-feed.xml" *static-dir*)))
+ (with-open-file (*standard-output* file-path :direction :output :if-exists :supersede)
+ (let ((*mode* :file))
+ (show-comment-feed)))))
diff --git a/main.lisp b/main.lisp
index f2c901a..9b18ae3 100644
--- a/main.lisp
+++ b/main.lisp
@@ -45,6 +45,7 @@
((string= "save" (car (last *subpath*))) :save-entry)
((string= "moderate" (car (last *subpath*))) :moderate)
((string= "atom" (car (last *subpath*))) :view-atom-entry)
+ ((string= "rebuild" (car (last *subpath*))) :rebuild)
(t nil))))
(*query* #+clisp (if (eq *action* :view-atom-entry)
nil
@@ -76,6 +77,7 @@
(:nfs.net (merge-pathnames #p"protected/journal/"
*site-root*))))
(*cache-dir* (merge-pathnames #p"cache/" *data-dir*))
+ (*static-dir* (merge-pathnames #p"public/journal/" *site-root*))
(*wordpress-key* (with-open-file (file (merge-pathnames
"wordpress-api-key.key"
*data-dir*))
@@ -155,6 +157,9 @@
:where [= [id] id]
:av-pairs `((spam_p "t")))))
(show-moderation-page)))
+ (:rebuild (http-send-headers "text/plain; charset=UTF-8")
+ (update-journal)
+ (format t "~&Done."))
(otherwise (show-web-journal)))
#.(restore-sql-reader-syntax-state))