Browse Source

Bugfixes to sitemaps, mathjax, and posts.

Brit Butler 11 years ago
parent
commit
f58c265fb7
3 changed files with 23 additions and 16 deletions
  1. 10 9
      plugins/mathjax.lisp
  2. 11 6
      plugins/sitemap.lisp
  3. 2 1
      src/posts.lisp

+ 10 - 9
plugins/mathjax.lisp

14
 </script>~]
14
 </script>~]
15
 <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
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
 (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
25
 (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
18
                  (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
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
     (let ((mathjax-header (format nil *mathjax-header* config location preset)))
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
   (:use :cl)
2
   (:use :cl)
3
   (:import-from :coleslaw #:*config*
3
   (:import-from :coleslaw #:*config*
4
                           #:index
4
                           #:index
5
-                          #:deploy
6
                           #:page-url
5
                           #:page-url
6
+                          #:find-all
7
+                          #:discover
8
+                          #:publish
7
                           #:theme-fn
9
                           #:theme-fn
10
+                          #:add-document
8
                           #:write-document)
11
                           #:write-document)
9
   (:import-from :alexandria #:hash-table-values)
12
   (:import-from :alexandria #:hash-table-values)
10
   (:export #:enable))
13
   (:export #:enable))
16
 
19
 
17
 (defmethod page-url ((object sitemap)) "sitemap.xml")
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
     (write-document sitemap (theme-fn 'sitemap "sitemap"))))
29
     (write-document sitemap (theme-fn 'sitemap "sitemap"))))
25
 
30
 
26
 (defun enable ())
31
 (defun enable ())

+ 2 - 1
src/posts.lisp

3
 (defclass post (content)
3
 (defclass post (content)
4
   ((title :initarg :title :reader title-of)
4
   ((title :initarg :title :reader title-of)
5
    (author :initarg :author :accessor author-of)
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
 (defmethod initialize-instance :after ((object post) &key)
9
 (defmethod initialize-instance :after ((object post) &key)
9
   (with-accessors ((title title-of)
10
   (with-accessors ((title title-of)