From 488191b23797ffab1f4aed9b854805148f9eec18 Mon Sep 17 00:00:00 2001 From: Do Nhat Minh Date: Sat, 27 Apr 2013 02:13:56 +0800 Subject: [PATCH] move sitemap to plugins --- src/coleslaw.lisp | 1 - src/content.lisp | 3 --- src/feeds.lisp | 23 ----------------------- src/indices.lisp | 14 ++++++-------- themes/sitemap.tmpl | 6 +++--- 5 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index d4a1ffc..25c6b73 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -55,7 +55,6 @@ Additional args to render CONTENT can be passed via RENDER-ARGS." (when (probe-file dir) (run-program "cp -R ~a ." dir))) (do-ctypes (publish ctype)) - (render-sitemap) (render-indices) (render-feeds (feeds *config*)))) diff --git a/src/content.lisp b/src/content.lisp index 2e6f1e9..19c1ec1 100644 --- a/src/content.lisp +++ b/src/content.lisp @@ -7,9 +7,6 @@ ((name :initform nil :initarg :name :accessor tag-name) (slug :initform nil :Initarg :slug :accessor tag-slug))) -(defmethod page-url ((object tag)) - (format nil "tag/~a" (tag-slug object))) - (defun make-tag (str) "Takes a string and returns a TAG instance with a name and slug." (let ((trimmed (string-trim " " str))) diff --git a/src/feeds.lisp b/src/feeds.lisp index e137beb..83ba3a0 100644 --- a/src/feeds.lisp +++ b/src/feeds.lisp @@ -4,29 +4,6 @@ "Make a RFC1123 pubdate representing the current time." (local-time:format-rfc1123-timestring nil (local-time:now))) -(defun render-sitemap () - "Render sitemap.xml and write robots.txt under document root" - (let* ((template (theme-fn :sitemap "feeds")) - (urls (append '("" "robots.txt") ; empty string is for root url - (mapcar #'page-url (find-all 'post)) - (mapcar #'page-url (all-tags)) - (mapcar #'(lambda (m) - (format nil "date/~a.html" m)) - (all-months)))) - (index (make-instance 'url-index - :id "sitemap.xml" - :urls urls))) - (with-open-file (robots (rel-path (staging-dir *config*) "robots.txt") - :direction :output - :if-exists :supersede) - (format robots - "User-agent: *~%Disallow: ~2%Sitemap: ~a~%" - (concatenate 'string - (domain *config*) - "/" - (page-url index)))) - (write-page (page-path index) (render-page index template)))) - (defun render-feed (posts &key path template tag) (flet ((first-10 (list) (subseq list 0 (min (length list) 10))) (tag-posts (list) (remove-if-not (lambda (x) (tag-p tag x)) list))) diff --git a/src/indices.lisp b/src/indices.lisp index 65732cd..64ac6c6 100644 --- a/src/indices.lisp +++ b/src/indices.lisp @@ -16,17 +16,15 @@ (defclass tag-index (index) ()) (defclass date-index (index) ()) (defclass int-index (index) ()) -(defclass url-index (index) - ((urls :initform nil :initarg :urls :accessor urls) - (pubdate :initform (local-time:format-rfc3339-timestring nil - (local-time:now)) - :initarg :pubdate - :accessor index-pubdate))) (defmethod page-url ((object index)) (index-id object)) +(defmethod page-url ((object tag-index)) + (format nil "tags/~a" (index-id object))) (defmethod page-url ((object date-index)) (format nil "date/~a" (index-id object))) +(defmethod page-url ((object int-index)) + (format nil "~d" (index-id object))) (defun all-months () "Retrieve a list of all months with published content." @@ -42,7 +40,7 @@ (defun index-by-tag (tag content) "Return an index of all CONTENT matching the given TAG." - (make-instance 'tag-index :id (page-url tag) + (make-instance 'tag-index :id (tag-slug tag) :posts (remove-if-not (lambda (x) (tag-p tag x)) content) :title (format nil "Posts tagged ~a" (tag-name tag)))) @@ -56,7 +54,7 @@ "Return the index for the Ith page of CONTENT in reverse chronological order." (let* ((start (* step i)) (end (min (length content) (+ start step)))) - (make-instance 'int-index :id (format nil "~d" (1+ i)) + (make-instance 'int-index :id (1+ i) :posts (subseq content start end) :title "Recent Posts"))) diff --git a/themes/sitemap.tmpl b/themes/sitemap.tmpl index 4833858..89b77bb 100644 --- a/themes/sitemap.tmpl +++ b/themes/sitemap.tmpl @@ -3,10 +3,10 @@ {template sitemap} {\n} - {foreach $url in $content.urls} + {foreach $url in $urls} - {$config.domain}/{$url} - {$content.pubdate} + {$domain}/{$url} + {$pubdate} {/foreach}