diff --git a/plugins/sitemap.lisp b/plugins/sitemap.lisp index 2af6517..8a79c1b 100644 --- a/plugins/sitemap.lisp +++ b/plugins/sitemap.lisp @@ -1,28 +1,26 @@ (defpackage :coleslaw-sitemap (:use :cl) (:import-from :coleslaw #:*config* + #:index #:deploy #:page-url - #:rel-path - #:staging-dir #:theme-fn - #:write-file) - (:import-from :local-time #:format-timestring - #:now) + #:write-document) (:import-from :alexandria #:hash-table-values) (:export #:enable)) (in-package :coleslaw-sitemap) +(defclass sitemap (index) + ((urls :initarg :urls :reader urls))) + +(defmethod page-url ((object sitemap)) "sitemap.xml") + (defmethod deploy :before (staging) "Render sitemap.xml under document root." (declare (ignore staging)) - (let ((urls (append '("" "sitemap.xml") ; empty string is for root url - (mapcar #'page-url (hash-table-values coleslaw::*site*))))) - (write-file (rel-path (staging-dir *config*) "sitemap.xml") - (funcall (theme-fn 'sitemap "sitemap") - (list :config *config* - :urls urls - :pubdate (format-timestring nil (now))))))) + (let* ((urls (mapcar #'page-url (hash-table-values coleslaw::*site*))) + (sitemap (make-instance 'sitemap :urls (append '("" "sitemap.xml") urls)))) + (write-document sitemap (theme-fn 'sitemap "sitemap")))) (defun enable ()) diff --git a/themes/sitemap.tmpl b/themes/sitemap.tmpl index 7335b6e..c0e2527 100644 --- a/themes/sitemap.tmpl +++ b/themes/sitemap.tmpl @@ -3,7 +3,7 @@ {template sitemap} {\n} - {foreach $url in $urls} + {foreach $url in $content.urls} {$config.domain}/{$url} {$pubdate}