|
@@ -3,15 +3,25 @@
|
3
|
3
|
|
4
|
4
|
(defpackage :coleslaw-incremental
|
5
|
5
|
(:use :cl)
|
6
|
|
- (:import-from :coleslaw #:get-updated-files
|
|
6
|
+ (:import-from :alexandria #:when-let)
|
|
7
|
+ (:import-from :coleslaw #:all-subclasses
|
|
8
|
+ #:content
|
|
9
|
+ #:construct
|
|
10
|
+ #:get-updated-files
|
7
|
11
|
#:find-content-by-path
|
8
|
|
- #:write-document)
|
|
12
|
+ #:write-document
|
|
13
|
+ #:rel-path)
|
9
|
14
|
(:export #:enable))
|
10
|
15
|
|
11
|
16
|
(in-package :coleslaw-incremental)
|
12
|
17
|
|
13
|
18
|
;; FIXME: We currently never update the site for config changes.
|
14
|
19
|
;; Examples to consider include changing the theme or domain of the site.
|
|
20
|
+;; Both would require full site recompiles. Consequently, it seems reasonable
|
|
21
|
+;; to expect that incremental plugin users:
|
|
22
|
+;; A) have done a full build of their site
|
|
23
|
+;; B) have a cl-store dump of the database at ~/.coleslaw.db
|
|
24
|
+;; ^ we should provide a script or plugin just for this
|
15
|
25
|
|
16
|
26
|
;; NOTE: We're gonna be a bit dirty here and monkey patch. The compilation model
|
17
|
27
|
;; still isn't an "exposed" part of Coleslaw. After some experimentation maybe
|
|
@@ -21,7 +31,6 @@
|
21
|
31
|
"A list of changed content instances to iterate over and write out to disk.")
|
22
|
32
|
|
23
|
33
|
(defun coleslaw::load-content ()
|
24
|
|
- ;; TODO: What if the file doesn't exist?
|
25
|
34
|
(let ((db-file (rel-path (user-homedir-pathname) ".coleslaw.db")))
|
26
|
35
|
(setf coleslaw::*site* (cl-store:restore db-file))
|
27
|
36
|
(loop for (status path) in (get-updated-files)
|
|
@@ -33,8 +42,28 @@
|
33
|
42
|
((string= "M" status) (process-change :modified path))
|
34
|
43
|
((string= "A" status) (process-change :added path))))
|
35
|
44
|
|
36
|
|
-(defgeneric process-change (status path)
|
37
|
|
- (:documentation "Updates the database as needed for the STATUS change to PATH."))
|
|
45
|
+(defgeneric process-change (status path &key &allow-other-keys)
|
|
46
|
+ (:documentation "Updates the database as needed for the STATUS change to PATH.")
|
|
47
|
+ (:method :around (status path &key)
|
|
48
|
+ (let ((extension (pathname-type path))
|
|
49
|
+ (ctypes (all-subclasses (find-class 'content))))
|
|
50
|
+ ;; This feels way too clever. I wish I could think of a better option.
|
|
51
|
+ (flet ((class-name-p (x class)
|
|
52
|
+ (string-equal x (symbol-name (class-name class)))))
|
|
53
|
+ (when-let (ctype (find extension ctypes :test #'class-name-p))
|
|
54
|
+ (call-next-method status path :ctype ctype))))))
|
|
55
|
+
|
|
56
|
+(defmethod process-change ((status (eql :deleted)) path &key)
|
|
57
|
+ (let ((obj (find-content-by-path path)))
|
|
58
|
+ ))
|
|
59
|
+
|
|
60
|
+(defmethod process-change ((status (eql :modified)) path &key)
|
|
61
|
+ (let ((obj (find-content-by-path path)))
|
|
62
|
+ ))
|
|
63
|
+
|
|
64
|
+(defmethod process-change ((status (eql :added)) path &key ctype)
|
|
65
|
+ (let ((obj (construct ctype (read-content path))))
|
|
66
|
+ ))
|
38
|
67
|
|
39
|
68
|
(defun coleslaw::compile-blog (staging)
|
40
|
69
|
"lulz. Do it live. DO IT ALL LIVE."
|