From d66ed584a60a4c2c17a9fd12b0224649f6fb1f2f Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Sat, 18 Aug 2012 23:00:33 -0400 Subject: [PATCH] Sketch config and compilation, minor tweaks. --- coleslaw.asd | 6 ++++++ example.coleslawrc | 9 +++++++++ src/coleslaw.lisp | 40 +++++++++++++++++++++++++++++----------- src/config.lisp | 9 +++++++++ src/git.lisp | 6 +----- src/packages.lisp | 7 +------ src/plugins.lisp | 2 +- 7 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 example.coleslawrc create mode 100644 src/config.lisp diff --git a/coleslaw.asd b/coleslaw.asd index 7e0ac0c..81026ca 100644 --- a/coleslaw.asd +++ b/coleslaw.asd @@ -8,6 +8,8 @@ :depends-on (:closure-template :iolib.os :local-time :alexandria) :serial t :components ((:file "packages") + (:file "config") + (:file "git") (:file "coleslaw") (:file "themes") (:file "posts") @@ -28,3 +30,7 @@ (defmethod operation-done-p ((op test-op) (c (eql (find-system :coleslaw)))) (values nil)) + +(defpackage #:coleslaw-conf (:export #:*basedir*)) +(defparameter coleslaw-conf:*basedir* + (make-pathname :name nil :type nil :defaults *load-truename*)) diff --git a/example.coleslawrc b/example.coleslawrc new file mode 100644 index 0000000..a97bc3f --- /dev/null +++ b/example.coleslawrc @@ -0,0 +1,9 @@ +(:author "Brit Butler" + :domain "http://redlinernotes.com" + :interval 600 + :license "CC-BY-SA" + :plugins nil + :repo "/home/redline/projects/coleslaw/ignore/input/" + :sitenav "" + :title "Improved Means for Achieving Deteriorated Ends" + :theme "hyde") diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index 76bee64..2b4f620 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -1,14 +1,22 @@ (in-package :coleslaw) -(defparameter *storage* nil - "A db-spec for postmodern or a hash-table cache. It is expected that -*storage* has methods for each Generic Function in coleslaw implemented.") +(defclass blog () + ((author :initarg :author :initform "" :accessor author) + (domain :initarg :domain :initform "" :accessor domain) + (interval :initarg :interval :initform 600 :accessor interval) + (license :initarg :license :initform "" :accessor license) + (plugins :initarg :plugins :initform '() :accessor plugins) + (repo :initarg :repo :initform #p"/" :accessor repo) + (sitenav :initarg :sitenav :initform "" :accessor sitenav) + (title :initarg :title :initform "" :accessor title) + (theme :initarg :theme :initform "hyde" :accessor theme))) -(defgeneric get-credentials (name) - (:documentation "Retrieve the credentials keyed by NAME from *storage*.")) +(defparameter *config* nil + "A variable to store the blog configuration and plugin settings.") -(defgeneric set-credentials (name credentials) - (:documentation "Store the given CREDENTIALS in *storage* under NAME.")) +(defun app-path (path) + "Take a relative PATH and return the corresponding pathname beneath coleslaw." + (merge-pathnames path coleslaw-conf:*basedir*)) (defun load-config () nil) @@ -17,14 +25,24 @@ nil) (defun compile-blog () - (with-current-directory *temporary-directory* - nil)) + (let ((staging #p"/tmp/coleslaw/")) + ; TODO: More incremental compilation? Don't regen whole blog unnecessarily. + (if (probe-file staging) + (iolib.os:delete-files staging :recursive t) + (ensure-directories-exist staging)) + (with-current-directory staging + (let ((css-dir (app-path (format nil "themes/~a/css/" (theme *config*)))) + (static-dir (merge-pathnames "static/" (repo *config*)))) + (dolist (dir (list css-dir static-dir)) + (iolib.os:run-program "cp" `("-R" ,dir ".")))) + (render-posts) + (render-indices)) + (deploy staging))) -;; TODO: Make update interval a config option. (defun main () (load-config) (unwind-protect (loop do (if (blog-update-p) (compile-blog) - (sleep 600))) + (sleep (interval *config*)))) (exit-handler))) diff --git a/src/config.lisp b/src/config.lisp new file mode 100644 index 0000000..9f1f16b --- /dev/null +++ b/src/config.lisp @@ -0,0 +1,9 @@ +(in-package :coleslaw) + +(defparameter *config* nil + "A variable to store the blog configuration and plugin settings.") + +(defun load-config (&optional (dir (user-homedir-pathname))) + "Load the coleslaw configuration from DIR/.coleslawrc. DIR is ~ by default." + (with-open-file (in (merge-pathnames ".coleslawrc" dir)) + (setf *config* (apply #'make-instance 'blog (read in))))) diff --git a/src/git.lisp b/src/git.lisp index 91bd32d..5547b60 100644 --- a/src/git.lisp +++ b/src/git.lisp @@ -1,13 +1,9 @@ (in-package :coleslaw) -;; TODO: -; Replace hardcoded paths (repo, .deploy) with *config*? -; blog-update-p would be thing to make a generic in a plugin. - (defun last-commit () "Retrieve the SHA1 hash of the most recent blog commit." (multiple-value-bind (pid stdout stderr) - (with-current-directory "/home/redline/projects/coleslaw/" + (with-current-directory (repo *config*) (iolib.os:run-program "git" '("log" "-n 1"))) (cl-ppcre:scan-to-strings "[0-9a-f]{40}" stdout))) diff --git a/src/packages.lisp b/src/packages.lisp index 1742565..b430d0d 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -2,12 +2,7 @@ (:use :cl :closure-template) (:import-from :iolib.os #:with-current-directory #:*temporary-directory*) - (:export ;; coleslaw-core - #:*storage* - #:get-credentials - #:set-credentials - - ;; themes + (:export ;; themes #:*current-theme* #:*theme-dir* #:add-injection diff --git a/src/plugins.lisp b/src/plugins.lisp index 543a637..06d5c88 100644 --- a/src/plugins.lisp +++ b/src/plugins.lisp @@ -8,7 +8,7 @@ are in the plugins folder in coleslaw's source directory." (merge-pathnames (concatenate 'string "plugins/" (string-downcase (symbol-name sym))) - (asdf:system-source-directory 'coleslaw))) + coleslaw-conf:*basedir*)) plugins))) (map nil (lambda (file) (compile-file file)