|
@@ -7,25 +7,8 @@
|
7
|
7
|
(defvar *site* (make-hash-table :test #'equal)
|
8
|
8
|
"An in-memory database to hold all site documents, keyed on page-url.")
|
9
|
9
|
|
10
|
|
-(defun add-document (doc)
|
11
|
|
- "Add DOC to the in-memory database. Error if a matching entry is present."
|
12
|
|
- (let ((url (page-url doc)))
|
13
|
|
- (if (gethash url *site*)
|
14
|
|
- (error "There is already an existing document with the url ~a" url)
|
15
|
|
- (setf (gethash url *site*) doc))))
|
16
|
|
-
|
17
|
10
|
;; Class Methods
|
18
|
11
|
|
19
|
|
-(defun find-all (doc-type)
|
20
|
|
- "Return a list of all instances of a given DOC-TYPE."
|
21
|
|
- (loop for val being the hash-values in *site*
|
22
|
|
- when (typep val doc-type) collect val))
|
23
|
|
-
|
24
|
|
-(defun purge-all (doc-type)
|
25
|
|
- "Remove all instances of DOC-TYPE from memory."
|
26
|
|
- (dolist (obj (find-all doc-type))
|
27
|
|
- (remhash (page-url obj) *site*)))
|
28
|
|
-
|
29
|
12
|
(defgeneric publish (doc-type)
|
30
|
13
|
(:documentation "Write pages to disk for all documents of the given DOC-TYPE."))
|
31
|
14
|
|
|
@@ -55,6 +38,15 @@
|
55
|
38
|
(defgeneric render (document &key &allow-other-keys)
|
56
|
39
|
(:documentation "Render the given DOCUMENT to HTML."))
|
57
|
40
|
|
|
41
|
+;; Helper Functions
|
|
42
|
+
|
|
43
|
+(defun add-document (doc)
|
|
44
|
+ "Add DOC to the in-memory database. Error if a matching entry is present."
|
|
45
|
+ (let ((url (page-url doc)))
|
|
46
|
+ (if (gethash url *site*)
|
|
47
|
+ (error "There is already an existing document with the url ~a" url)
|
|
48
|
+ (setf (gethash url *site*) doc))))
|
|
49
|
+
|
58
|
50
|
(defun write-document (document &optional theme-fn &rest render-args)
|
59
|
51
|
"Write the given DOCUMENT to disk as HTML. If THEME-FN is present,
|
60
|
52
|
use it as the template passing any RENDER-ARGS."
|
|
@@ -62,3 +54,13 @@ use it as the template passing any RENDER-ARGS."
|
62
|
54
|
(apply #'render-page document theme-fn render-args)
|
63
|
55
|
(render-page document nil))))
|
64
|
56
|
(write-file (page-path obj) html)))
|
|
57
|
+
|
|
58
|
+(defun find-all (doc-type)
|
|
59
|
+ "Return a list of all instances of a given DOC-TYPE."
|
|
60
|
+ (loop for val being the hash-values in *site*
|
|
61
|
+ when (typep val doc-type) collect val))
|
|
62
|
+
|
|
63
|
+(defun purge-all (doc-type)
|
|
64
|
+ "Remove all instances of DOC-TYPE from memory."
|
|
65
|
+ (dolist (obj (find-all doc-type))
|
|
66
|
+ (remhash (page-url obj) *site*)))
|