浏览代码

Sketch config and compilation, minor tweaks.

Brit Butler 13 年之前
父节点
当前提交
d66ed584a6
共有 7 个文件被更改,包括 56 次插入23 次删除
  1. 6 0
      coleslaw.asd
  2. 9 0
      example.coleslawrc
  3. 29 11
      src/coleslaw.lisp
  4. 9 0
      src/config.lisp
  5. 1 5
      src/git.lisp
  6. 1 6
      src/packages.lisp
  7. 1 1
      src/plugins.lisp

+ 6 - 0
coleslaw.asd

@@ -8,6 +8,8 @@
8 8
   :depends-on (:closure-template :iolib.os :local-time :alexandria)
9 9
   :serial t
10 10
   :components ((:file "packages")
11
+               (:file "config")
12
+               (:file "git")
11 13
                (:file "coleslaw")
12 14
                (:file "themes")
13 15
                (:file "posts")
@@ -28,3 +30,7 @@
28 30
 (defmethod operation-done-p ((op test-op)
29 31
                              (c (eql (find-system :coleslaw))))
30 32
   (values nil))
33
+
34
+(defpackage #:coleslaw-conf (:export #:*basedir*))
35
+(defparameter coleslaw-conf:*basedir*
36
+  (make-pathname :name nil :type nil :defaults *load-truename*))

+ 9 - 0
example.coleslawrc

@@ -0,0 +1,9 @@
1
+(:author "Brit Butler"
2
+ :domain "http://redlinernotes.com"
3
+ :interval 600
4
+ :license "CC-BY-SA"
5
+ :plugins nil
6
+ :repo "/home/redline/projects/coleslaw/ignore/input/"
7
+ :sitenav ""
8
+ :title "Improved Means for Achieving Deteriorated Ends"
9
+ :theme "hyde")

+ 29 - 11
src/coleslaw.lisp

@@ -1,14 +1,22 @@
1 1
 (in-package :coleslaw)
2 2
 
3
-(defparameter *storage* nil
4
-  "A db-spec for postmodern or a hash-table cache. It is expected that
5
-*storage* has methods for each Generic Function in coleslaw implemented.")
3
+(defclass blog ()
4
+  ((author :initarg :author :initform "" :accessor author)
5
+   (domain :initarg :domain :initform "" :accessor domain)
6
+   (interval :initarg :interval :initform 600 :accessor interval)
7
+   (license :initarg :license :initform "" :accessor license)
8
+   (plugins :initarg :plugins :initform '() :accessor plugins)
9
+   (repo :initarg :repo :initform #p"/" :accessor repo)
10
+   (sitenav :initarg :sitenav :initform "" :accessor sitenav)
11
+   (title :initarg :title :initform "" :accessor title)
12
+   (theme :initarg :theme :initform "hyde" :accessor theme)))
6 13
 
7
-(defgeneric get-credentials (name)
8
-  (:documentation "Retrieve the credentials keyed by NAME from *storage*."))
14
+(defparameter *config* nil
15
+  "A variable to store the blog configuration and plugin settings.")
9 16
 
10
-(defgeneric set-credentials (name credentials)
11
-  (:documentation "Store the given CREDENTIALS in *storage* under NAME."))
17
+(defun app-path (path)
18
+  "Take a relative PATH and return the corresponding pathname beneath coleslaw."
19
+  (merge-pathnames path coleslaw-conf:*basedir*))
12 20
 
13 21
 (defun load-config ()
14 22
   nil)
@@ -17,14 +25,24 @@
17 25
   nil)
18 26
 
19 27
 (defun compile-blog ()
20
-  (with-current-directory *temporary-directory*
21
-    nil))
28
+  (let ((staging #p"/tmp/coleslaw/"))
29
+    ; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
30
+    (if (probe-file staging)
31
+        (iolib.os:delete-files staging :recursive t)
32
+        (ensure-directories-exist staging))
33
+    (with-current-directory staging
34
+      (let ((css-dir (app-path (format nil "themes/~a/css/" (theme *config*))))
35
+            (static-dir (merge-pathnames "static/" (repo *config*))))
36
+        (dolist (dir (list css-dir static-dir))
37
+          (iolib.os:run-program "cp" `("-R" ,dir "."))))
38
+      (render-posts)
39
+      (render-indices))
40
+    (deploy staging)))
22 41
 
23
-;; TODO: Make update interval a config option.
24 42
 (defun main ()
25 43
   (load-config)
26 44
   (unwind-protect
27 45
        (loop do (if (blog-update-p)
28 46
                     (compile-blog)
29
-                    (sleep 600)))
47
+                    (sleep (interval *config*))))
30 48
     (exit-handler)))

+ 9 - 0
src/config.lisp

@@ -0,0 +1,9 @@
1
+(in-package :coleslaw)
2
+
3
+(defparameter *config* nil
4
+  "A variable to store the blog configuration and plugin settings.")
5
+
6
+(defun load-config (&optional (dir (user-homedir-pathname)))
7
+  "Load the coleslaw configuration from DIR/.coleslawrc. DIR is ~ by default."
8
+  (with-open-file (in (merge-pathnames ".coleslawrc" dir))
9
+    (setf *config* (apply #'make-instance 'blog (read in)))))

+ 1 - 5
src/git.lisp

@@ -1,13 +1,9 @@
1 1
 (in-package :coleslaw)
2 2
 
3
-;; TODO:
4
-; Replace hardcoded paths (repo, .deploy) with *config*?
5
-; blog-update-p would be thing to make a generic in a plugin.
6
-
7 3
 (defun last-commit ()
8 4
   "Retrieve the SHA1 hash of the most recent blog commit."
9 5
   (multiple-value-bind (pid stdout stderr)
10
-      (with-current-directory "/home/redline/projects/coleslaw/"
6
+      (with-current-directory (repo *config*)
11 7
         (iolib.os:run-program "git" '("log" "-n 1")))
12 8
     (cl-ppcre:scan-to-strings "[0-9a-f]{40}" stdout)))
13 9
 

+ 1 - 6
src/packages.lisp

@@ -2,12 +2,7 @@
2 2
   (:use :cl :closure-template)
3 3
   (:import-from :iolib.os #:with-current-directory
4 4
                           #:*temporary-directory*)
5
-  (:export ;; coleslaw-core
6
-           #:*storage*
7
-           #:get-credentials
8
-           #:set-credentials
9
-
10
-           ;; themes
5
+  (:export ;; themes
11 6
            #:*current-theme*
12 7
            #:*theme-dir*
13 8
            #:add-injection

+ 1 - 1
src/plugins.lisp

@@ -8,7 +8,7 @@ are in the plugins folder in coleslaw's source directory."
8 8
                          (merge-pathnames
9 9
                           (concatenate 'string "plugins/"
10 10
                                        (string-downcase (symbol-name sym)))
11
-                          (asdf:system-source-directory 'coleslaw)))
11
+                          coleslaw-conf:*basedir*))
12 12
                        plugins)))
13 13
     (map nil (lambda (file)
14 14
                (compile-file file)