소스 검색

Cleanup sitemap plugin a bit.

Brit Butler 11 년 전
부모
커밋
3264848cde
2개의 변경된 파일11개의 추가작업 그리고 13개의 파일을 삭제
  1. 10 12
      plugins/sitemap.lisp
  2. 1 1
      themes/sitemap.tmpl

+ 10 - 12
plugins/sitemap.lisp

@@ -1,28 +1,26 @@
1 1
 (defpackage :coleslaw-sitemap
2 2
   (:use :cl)
3 3
   (:import-from :coleslaw #:*config*
4
+                          #:index
4 5
                           #:deploy
5 6
                           #:page-url
6
-                          #:rel-path
7
-                          #:staging-dir
8 7
                           #:theme-fn
9
-                          #:write-file)
10
-  (:import-from :local-time #:format-timestring
11
-                            #:now)
8
+                          #:write-document)
12 9
   (:import-from :alexandria #:hash-table-values)
13 10
   (:export #:enable))
14 11
 
15 12
 (in-package :coleslaw-sitemap)
16 13
 
14
+(defclass sitemap (index)
15
+  ((urls :initarg :urls :reader urls)))
16
+
17
+(defmethod page-url ((object sitemap)) "sitemap.xml")
18
+
17 19
 (defmethod deploy :before (staging)
18 20
   "Render sitemap.xml under document root."
19 21
   (declare (ignore staging))
20
-  (let ((urls (append '("" "sitemap.xml") ; empty string is for root url
21
-                      (mapcar #'page-url (hash-table-values coleslaw::*site*)))))
22
-    (write-file (rel-path (staging-dir *config*) "sitemap.xml")
23
-                (funcall (theme-fn 'sitemap "sitemap")
24
-                         (list :config *config*
25
-                               :urls urls
26
-                               :pubdate (format-timestring nil (now)))))))
22
+  (let* ((urls (mapcar #'page-url (hash-table-values coleslaw::*site*)))
23
+         (sitemap (make-instance 'sitemap :urls (append '("" "sitemap.xml") urls))))
24
+    (write-document sitemap (theme-fn 'sitemap "sitemap"))))
27 25
 
28 26
 (defun enable ())

+ 1 - 1
themes/sitemap.tmpl

@@ -3,7 +3,7 @@
3 3
 {template sitemap}
4 4
 <?xml version="1.0"?>{\n}
5 5
 <urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>
6
-    {foreach $url in $urls}
6
+    {foreach $url in $content.urls}
7 7
     <url>
8 8
         <loc>{$config.domain}/{$url}</loc>
9 9
         <lastmod>{$pubdate}</lastmod>