瀏覽代碼

Bugfixes to sitemaps, mathjax, and posts.

Brit Butler 11 年之前
父節點
當前提交
f58c265fb7
共有 3 個文件被更改,包括 23 次插入16 次删除
  1. 10 9
      plugins/mathjax.lisp
  2. 11 6
      plugins/sitemap.lisp
  3. 2 1
      src/posts.lisp

+ 10 - 9
plugins/mathjax.lisp

@@ -14,15 +14,16 @@
14 14
 </script>~]
15 15
 <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
16 16
 
17
+(defgeneric mathjax-p (document)
18
+  (:documentation "Test if DOCUMENT requires contains any math-tagged content.")
19
+  (:method ((content content))
20
+    (tag-p "math" content))
21
+  (:method ((index index))
22
+    (and (slot-boundp index 'content)
23
+         (some #'mathjax-p (index-content index)))))
24
+
17 25
 (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
18 26
                  (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
19
-  (labels ((math-post-p (obj)
20
-             ;; Would it be better to test against latex than math, here?
21
-             (tag-p "math" obj))
22
-           (mathjax-p (obj)
23
-             (or force
24
-                 (etypecase obj
25
-                   (content (math-post-p obj))
26
-                   (index (some #'math-post-p (index-content obj)))))))
27
+  (flet ((plugin-p (x) (or force (mathjax-p x))))
27 28
     (let ((mathjax-header (format nil *mathjax-header* config location preset)))
28
-      (add-injection (list mathjax-header #'mathjax-p) :head))))
29
+      (add-injection (list mathjax-header #'plugin-p) :head))))

+ 11 - 6
plugins/sitemap.lisp

@@ -2,9 +2,12 @@
2 2
   (:use :cl)
3 3
   (:import-from :coleslaw #:*config*
4 4
                           #:index
5
-                          #:deploy
6 5
                           #:page-url
6
+                          #:find-all
7
+                          #:discover
8
+                          #:publish
7 9
                           #:theme-fn
10
+                          #:add-document
8 11
                           #:write-document)
9 12
   (:import-from :alexandria #:hash-table-values)
10 13
   (:export #:enable))
@@ -16,11 +19,13 @@
16 19
 
17 20
 (defmethod page-url ((object sitemap)) "sitemap.xml")
18 21
 
19
-(defmethod deploy :before (staging)
20
-  "Render sitemap.xml under document root."
21
-  (declare (ignore staging))
22
-  (let* ((urls (mapcar #'page-url (hash-table-values coleslaw::*site*)))
23
-         (sitemap (make-instance 'sitemap :urls (append '("" "sitemap.xml") urls))))
22
+(defmethod discover ((doc-type (eql (find-class 'sitemap))))
23
+  (let ((base-urls '("" "sitemap.xml"))
24
+        (urls (mapcar #'page-url (hash-table-values coleslaw::*site*))))
25
+    (add-document (make-instance 'sitemap :urls (append base-urls urls)))))
26
+
27
+(defmethod publish ((doc-type (eql (find-class 'sitemap))))
28
+  (dolist (sitemap (find-all 'sitemap))
24 29
     (write-document sitemap (theme-fn 'sitemap "sitemap"))))
25 30
 
26 31
 (defun enable ())

+ 2 - 1
src/posts.lisp

@@ -3,7 +3,8 @@
3 3
 (defclass post (content)
4 4
   ((title :initarg :title :reader title-of)
5 5
    (author :initarg :author :accessor author-of)
6
-   (format :initarg :format :accessor post-format)))
6
+   (format :initarg :format :accessor post-format))
7
+  (:default-initargs :author nil))
7 8
 
8 9
 (defmethod initialize-instance :after ((object post) &key)
9 10
   (with-accessors ((title title-of)