Browse Source

move sitemap to plugins

Do Nhat Minh 12 years ago
parent
commit
488191b237
5 changed files with 9 additions and 38 deletions
  1. 0 1
      src/coleslaw.lisp
  2. 0 3
      src/content.lisp
  3. 0 23
      src/feeds.lisp
  4. 6 8
      src/indices.lisp
  5. 3 3
      themes/sitemap.tmpl

+ 0 - 1
src/coleslaw.lisp

@@ -55,7 +55,6 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
55 55
       (when (probe-file dir)
56 56
         (run-program "cp -R ~a ." dir)))
57 57
     (do-ctypes (publish ctype))
58
-    (render-sitemap)
59 58
     (render-indices)
60 59
     (render-feeds (feeds *config*))))
61 60
 

+ 0 - 3
src/content.lisp

@@ -7,9 +7,6 @@
7 7
   ((name :initform nil :initarg :name :accessor tag-name)
8 8
    (slug :initform nil :Initarg :slug :accessor tag-slug)))
9 9
 
10
-(defmethod page-url ((object tag))
11
-  (format nil "tag/~a" (tag-slug object)))
12
-
13 10
 (defun make-tag (str)
14 11
   "Takes a string and returns a TAG instance with a name and slug."
15 12
   (let ((trimmed (string-trim " " str)))

+ 0 - 23
src/feeds.lisp

@@ -4,29 +4,6 @@
4 4
   "Make a RFC1123 pubdate representing the current time."
5 5
   (local-time:format-rfc1123-timestring nil (local-time:now)))
6 6
 
7
-(defun render-sitemap ()
8
-  "Render sitemap.xml and write robots.txt under document root"
9
-  (let* ((template (theme-fn :sitemap "feeds"))
10
-         (urls (append '("" "robots.txt") ; empty string is for root url
11
-                       (mapcar #'page-url (find-all 'post))
12
-                       (mapcar #'page-url (all-tags))
13
-                       (mapcar #'(lambda (m)
14
-                                   (format nil "date/~a.html" m))
15
-                               (all-months))))
16
-         (index (make-instance 'url-index
17
-                               :id "sitemap.xml"
18
-                               :urls urls)))
19
-    (with-open-file (robots (rel-path (staging-dir *config*) "robots.txt")
20
-                            :direction :output
21
-                            :if-exists :supersede)
22
-      (format robots
23
-              "User-agent: *~%Disallow: ~2%Sitemap: ~a~%"
24
-              (concatenate 'string
25
-                           (domain *config*)
26
-                           "/"
27
-                           (page-url index))))
28
-    (write-page (page-path index) (render-page index template))))
29
-
30 7
 (defun render-feed (posts &key path template tag)
31 8
   (flet ((first-10 (list) (subseq list 0 (min (length list) 10)))
32 9
          (tag-posts (list) (remove-if-not (lambda (x) (tag-p tag x)) list)))

+ 6 - 8
src/indices.lisp

@@ -16,17 +16,15 @@
16 16
 (defclass tag-index (index) ())
17 17
 (defclass date-index (index) ())
18 18
 (defclass int-index (index) ())
19
-(defclass url-index (index)
20
-  ((urls :initform nil :initarg :urls :accessor urls)
21
-   (pubdate :initform (local-time:format-rfc3339-timestring nil
22
-                                                            (local-time:now))
23
-            :initarg :pubdate
24
-            :accessor index-pubdate)))
25 19
 
26 20
 (defmethod page-url ((object index))
27 21
   (index-id object))
22
+(defmethod page-url ((object tag-index))
23
+  (format nil "tags/~a" (index-id object)))
28 24
 (defmethod page-url ((object date-index))
29 25
   (format nil "date/~a" (index-id object)))
26
+(defmethod page-url ((object int-index))
27
+  (format nil "~d" (index-id object)))
30 28
 
31 29
 (defun all-months ()
32 30
   "Retrieve a list of all months with published content."
@@ -42,7 +40,7 @@
42 40
 
43 41
 (defun index-by-tag (tag content)
44 42
   "Return an index of all CONTENT matching the given TAG."
45
-  (make-instance 'tag-index :id (page-url tag)
43
+  (make-instance 'tag-index :id (tag-slug tag)
46 44
                  :posts (remove-if-not (lambda (x) (tag-p tag x)) content)
47 45
                  :title (format nil "Posts tagged ~a" (tag-name tag))))
48 46
 
@@ -56,7 +54,7 @@
56 54
   "Return the index for the Ith page of CONTENT in reverse chronological order."
57 55
   (let* ((start (* step i))
58 56
          (end (min (length content) (+ start step))))
59
-    (make-instance 'int-index :id (format nil "~d" (1+ i))
57
+    (make-instance 'int-index :id (1+ i)
60 58
                               :posts (subseq content start end)
61 59
                               :title "Recent Posts")))
62 60
 

+ 3 - 3
themes/sitemap.tmpl

@@ -3,10 +3,10 @@
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 $content.urls}
6
+    {foreach $url in $urls}
7 7
     <url>
8
-        <loc>{$config.domain}/{$url}</loc>
9
-        <lastmod>{$content.pubdate}</lastmod>
8
+        <loc>{$domain}/{$url}</loc>
9
+        <lastmod>{$pubdate}</lastmod>
10 10
     </url>
11 11
     {/foreach}
12 12
 </urlset>