From f58c265fb7e43e120b0bb6f83270db17dec73d51 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Fri, 16 May 2014 09:52:04 -0400 Subject: [PATCH] Bugfixes to sitemaps, mathjax, and posts. --- plugins/mathjax.lisp | 19 ++++++++++--------- plugins/sitemap.lisp | 17 +++++++++++------ src/posts.lisp | 3 ++- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/plugins/mathjax.lisp b/plugins/mathjax.lisp index a303f31..df6bd80 100644 --- a/plugins/mathjax.lisp +++ b/plugins/mathjax.lisp @@ -14,15 +14,16 @@ ~] ") +(defgeneric mathjax-p (document) + (:documentation "Test if DOCUMENT requires contains any math-tagged content.") + (:method ((content content)) + (tag-p "math" content)) + (:method ((index index)) + (and (slot-boundp index 'content) + (some #'mathjax-p (index-content index))))) + (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML") (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js")) - (labels ((math-post-p (obj) - ;; Would it be better to test against latex than math, here? - (tag-p "math" obj)) - (mathjax-p (obj) - (or force - (etypecase obj - (content (math-post-p obj)) - (index (some #'math-post-p (index-content obj))))))) + (flet ((plugin-p (x) (or force (mathjax-p x)))) (let ((mathjax-header (format nil *mathjax-header* config location preset))) - (add-injection (list mathjax-header #'mathjax-p) :head)))) + (add-injection (list mathjax-header #'plugin-p) :head)))) diff --git a/plugins/sitemap.lisp b/plugins/sitemap.lisp index 8a79c1b..294ef28 100644 --- a/plugins/sitemap.lisp +++ b/plugins/sitemap.lisp @@ -2,9 +2,12 @@ (:use :cl) (:import-from :coleslaw #:*config* #:index - #:deploy #:page-url + #:find-all + #:discover + #:publish #:theme-fn + #:add-document #:write-document) (:import-from :alexandria #:hash-table-values) (:export #:enable)) @@ -16,11 +19,13 @@ (defmethod page-url ((object sitemap)) "sitemap.xml") -(defmethod deploy :before (staging) - "Render sitemap.xml under document root." - (declare (ignore staging)) - (let* ((urls (mapcar #'page-url (hash-table-values coleslaw::*site*))) - (sitemap (make-instance 'sitemap :urls (append '("" "sitemap.xml") urls)))) +(defmethod discover ((doc-type (eql (find-class 'sitemap)))) + (let ((base-urls '("" "sitemap.xml")) + (urls (mapcar #'page-url (hash-table-values coleslaw::*site*)))) + (add-document (make-instance 'sitemap :urls (append base-urls urls))))) + +(defmethod publish ((doc-type (eql (find-class 'sitemap)))) + (dolist (sitemap (find-all 'sitemap)) (write-document sitemap (theme-fn 'sitemap "sitemap")))) (defun enable ()) diff --git a/src/posts.lisp b/src/posts.lisp index 3cd8663..ebfc2c2 100644 --- a/src/posts.lisp +++ b/src/posts.lisp @@ -3,7 +3,8 @@ (defclass post (content) ((title :initarg :title :reader title-of) (author :initarg :author :accessor author-of) - (format :initarg :format :accessor post-format))) + (format :initarg :format :accessor post-format)) + (:default-initargs :author nil)) (defmethod initialize-instance :after ((object post) &key) (with-accessors ((title title-of)