move sitemap to plugins

This commit is contained in:
Do Nhat Minh 2013-04-27 02:13:56 +08:00
parent edcd1022ab
commit 488191b237
5 changed files with 9 additions and 38 deletions

View file

@ -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*))))

View file

@ -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)))

View file

@ -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)))

View file

@ -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")))

View file

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