From f821f105ec8360bdd71c9e00056cd3ccd76ed400 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Wed, 20 Apr 2011 13:45:59 -0400 Subject: [PATCH] Update coleslaw-static to not depend on S3. Add beginning of s3 plugin. Update import plugin to support writing posts out to files. Update TODO. --- TODO | 5 +++-- coleslaw-static.asd | 2 +- plugins/import.lisp | 39 ++++++++++++++++++++++++++++----------- plugins/s3.lisp | 8 +++++++- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 5e9fb03..e5f69eb 100644 --- a/TODO +++ b/TODO @@ -10,13 +10,15 @@ TODO: ;;;; implement head-inject/body-inject/navigation! ;;;; implement start-coleslaw, stop-coleslaw! ;;;; implement render-site!!! +;;;; how many globals can we move into *storage* as keywords? ALL OF THEM! +;;;; -- What about generics? ;;;; implement atom feed. RSS too? ;;;; implement non-disqus comment support? ;;;; What do post update semantics look like? i.e. edit file to change tags. ;;; indices ;; what should it really look like, keeping in mind the API should be mostly ;; identical between the static and dynamic backend? -;; indexes should be id/name, title + posts. rewrite indices to use them. +;; indexes should be id, type, title + posts. rewrite indices to use them. ;;; posts ;; post-url, improve escaping. @@ -25,7 +27,6 @@ TODO: ;;;; implement: analytics, crossposting, disqus, mathjax, pygments, recaptcha, s3 ;;;; support input or output dirs being git repos + have git hooks? ;;; import -;; add output to HTML files when static-p is true ;; add comment handling ... (when comments ...) ;; support old URLs via use of post-aliases? diff --git a/coleslaw-static.asd b/coleslaw-static.asd index 9a96b97..197588b 100644 --- a/coleslaw-static.asd +++ b/coleslaw-static.asd @@ -5,7 +5,7 @@ :maintainer "Brit Butler " :author "Brit Butler " :licence "LLGPL" - :depends-on (:coleslaw :zs3 :trivial-timers :cl-store) + :depends-on (:coleslaw :trivial-timers :cl-store) :components ((:module static :components ((:file "coleslaw") (:file "comments" diff --git a/plugins/import.lisp b/plugins/import.lisp index 5eb6383..077647a 100644 --- a/plugins/import.lisp +++ b/plugins/import.lisp @@ -1,7 +1,4 @@ -(asdf:oos 'asdf:load-op 'cxml) -(asdf:oos 'asdf:load-op 'split-sequence) -(asdf:oos 'asdf:load-op 'local-time) -(asdf:oos 'asdf:load-op 'cl-ppcre) +(ql:quickload '(cxml split-sequence local-time cl-ppcre)) (defpackage :coleslaw-import (:use :cl :coleslaw :cxml) @@ -12,11 +9,11 @@ (in-package :coleslaw-import) -(defgeneric import-post (service post) +(defgeneric import-post (service post &key static-p) (:documentation "Import POST into *storage*. The method to construct the POST object is determined by SERVICE.")) -(defmethod import-post ((service (eql :wordpress)) post) +(defmethod import-post ((service (eql :wordpress)) post &key static-p) (labels ((nodes (name) (dom:get-elements-by-tag-name post name)) (value (node) @@ -49,14 +46,34 @@ object is determined by SERVICE.")) "
") :aliases (parse-integer (node-val "wp:post_id")))) (comments (nodes "wp:comment"))) - (add-post new-post (post-id new-post)))))) + (add-post new-post (post-id new-post)) + (when static-p + (write-post post)))))) -(defgeneric import-posts (service filepath) +(defun write-post (post) + (let ((filepath (merge-pathnames *input-dir* + (format nil "~5d,'0/~a.html" + (post-id post) + ;; TODO: Write + use escaping fn. + (post-title post))))) + (with-open-file (out filepath :direction :output :if-exists :supersede) + ;; TODO: What other data/metadata should we write out? + (format out ";;;;;~%") + (format out "title: ~A~%" (post-title post)) + (format out "tags: ~A~%" (pretty-tags (post-tags post))) + (format out "date: ~A~%" (pretty-date (post-date post))) + (format out ";;;;;~%") + (format out "~A~%" (post-content post))))) + +(defgeneric import-posts (service filepath &key static-p) (:documentation "Import the posts (and potentially comments or other data) from FILEPATH, converting them to appropriate coleslaw objects and inserting -them into *storage*. The method to parse the file is determined by SERVICE.")) +them into *storage*. The method to parse the file is determined by SERVICE. +If STATIC-P is true, the posts will also be written into *.html files in +*input-directory*.")) -(defmethod import-posts ((service (eql :wordpress)) filepath) +(defmethod import-posts ((service (eql :wordpress)) filepath &key static-p) (let* ((xml (cxml:parse-file filepath (cxml-dom:make-dom-builder))) (posts (dom:get-elements-by-tag-name xml "item"))) - (loop for post across posts do (import-post service post)))) + (loop for post across posts do + (import-post service post :static-p static-p)))) diff --git a/plugins/s3.lisp b/plugins/s3.lisp index fb7f3d6..d92b33b 100644 --- a/plugins/s3.lisp +++ b/plugins/s3.lisp @@ -1,2 +1,8 @@ -(in-package :coleslaw) +(ql:quickload '(zs3)) + +(defpackage :coleslaw-s3 + (:use :cl :zs3)) + +(in-package :coleslaw-s3) +