Merge pull request #33 from mrordinaire/sitemap

Added sitemap generation.
This commit is contained in:
Brit Butler 2013-04-28 07:00:11 -07:00
commit e6c6bcbe26
6 changed files with 68 additions and 16 deletions

View file

@ -55,3 +55,9 @@
**Description**: Import blog posts from Wordpress using their export tool. Blog entries will be read from the XML and converted into .post files. Afterwards the XML file will be deleted to prevent reimporting. Optionally an ```:output``` argument may be supplied to the plugin. If provided, it should be a directory in which to store the .post files. Otherwise, the value of ```:repo``` in your .coleslawrc will be used.
**Example**: ```(import :filepath "/home/redline/redlinernotes-export.timestamp.xml" :output "/home/redlinernotes/blog/")```
## Sitemap generator
**Description**: this plugin generates a sitemap.xml under the page root, which is useful if you want google to crawl your site.
**Example**: ```(sitemap)```

29
plugins/sitemap.lisp Normal file
View file

@ -0,0 +1,29 @@
(defpackage :coleslaw-sitemap
(:use :cl)
(:import-from :coleslaw
#:*config*
#:deploy
#:domain
#:find-all
#:page-url
#:rel-path
#:staging-dir
#:theme-fn
#:write-page)
(:export #:enable))
(in-package :coleslaw-sitemap)
(defmethod deploy :before (staging)
"Render sitemap.xml under document root"
(let* ((urls (append '("" "sitemap.xml") ; empty string is for root url
(mapcar #'page-url (find-all 'coleslaw:post)))))
(write-page (rel-path (staging-dir *config*) "sitemap.xml")
(funcall (theme-fn :sitemap "feeds")
(list :domain (domain *config*)
:urls urls
:pubdate (local-time:format-rfc3339-timestring
nil
(local-time:now)))))))
(defun enable ())

View file

@ -12,14 +12,18 @@
(with-output-to-string (str)
(3bmd:parse-string-and-print-to-stream text str)))))
(defgeneric page-path (object)
(:documentation "The path to store OBJECT at once rendered."))
(defgeneric page-url (object)
(:documentation "The url to the object, without the domain"))
(defmethod page-path :around ((object t))
(defmethod page-url :around ((object t))
(let ((result (call-next-method)))
(if (pathname-type result)
result
(make-pathname :type "html" :defaults result))))
(namestring (if (pathname-type result)
result
(make-pathname :type "html" :defaults result)))))
(defun page-path (object)
"The path to store OBJECT at once rendered."
(rel-path (staging-dir *config*) (page-url object)))
(defun render-page (content &optional theme-fn &rest render-args)
"Render the given CONTENT to disk using THEME-FN if supplied.

View file

@ -17,14 +17,14 @@
(defclass date-index (index) ())
(defclass int-index (index) ())
(defmethod page-path ((object index))
(rel-path (staging-dir *config*) (index-id object)))
(defmethod page-path ((object tag-index))
(rel-path (staging-dir *config*) "tag/~a" (index-id object)))
(defmethod page-path ((object date-index))
(rel-path (staging-dir *config*) "date/~a" (index-id object)))
(defmethod page-path ((object int-index))
(rel-path (staging-dir *config*) "~d" (index-id object)))
(defmethod page-url ((object index))
(index-id object))
(defmethod page-url ((object tag-index))
(format nil "tag/~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."

View file

@ -10,8 +10,8 @@
:prev prev
:next next)))
(defmethod page-path ((object post))
(rel-path (staging-dir *config*) "posts/~a" (content-slug object)))
(defmethod page-url ((object post))
(format nil "posts/~a" (content-slug object)))
(defmethod initialize-instance :after ((object post) &key)
(with-accessors ((title post-title)

13
themes/sitemap.tmpl Normal file
View file

@ -0,0 +1,13 @@
{namespace coleslaw.theme.feeds}
{template sitemap}
<?xml version="1.0"?>{\n}
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>
{foreach $url in $urls}
<url>
<loc>{$domain}/{$url}</loc>
<lastmod>{$pubdate}</lastmod>
</url>
{/foreach}
</urlset>
{/template}