Cleanup sitemap plugin a bit.
This commit is contained in:
parent
57f9aeb696
commit
3264848cde
2 changed files with 11 additions and 13 deletions
|
@ -1,28 +1,26 @@
|
||||||
(defpackage :coleslaw-sitemap
|
(defpackage :coleslaw-sitemap
|
||||||
(:use :cl)
|
(:use :cl)
|
||||||
(:import-from :coleslaw #:*config*
|
(:import-from :coleslaw #:*config*
|
||||||
|
#:index
|
||||||
#:deploy
|
#:deploy
|
||||||
#:page-url
|
#:page-url
|
||||||
#:rel-path
|
|
||||||
#:staging-dir
|
|
||||||
#:theme-fn
|
#:theme-fn
|
||||||
#:write-file)
|
#:write-document)
|
||||||
(:import-from :local-time #:format-timestring
|
|
||||||
#:now)
|
|
||||||
(:import-from :alexandria #:hash-table-values)
|
(:import-from :alexandria #:hash-table-values)
|
||||||
(:export #:enable))
|
(:export #:enable))
|
||||||
|
|
||||||
(in-package :coleslaw-sitemap)
|
(in-package :coleslaw-sitemap)
|
||||||
|
|
||||||
|
(defclass sitemap (index)
|
||||||
|
((urls :initarg :urls :reader urls)))
|
||||||
|
|
||||||
|
(defmethod page-url ((object sitemap)) "sitemap.xml")
|
||||||
|
|
||||||
(defmethod deploy :before (staging)
|
(defmethod deploy :before (staging)
|
||||||
"Render sitemap.xml under document root."
|
"Render sitemap.xml under document root."
|
||||||
(declare (ignore staging))
|
(declare (ignore staging))
|
||||||
(let ((urls (append '("" "sitemap.xml") ; empty string is for root url
|
(let* ((urls (mapcar #'page-url (hash-table-values coleslaw::*site*)))
|
||||||
(mapcar #'page-url (hash-table-values coleslaw::*site*)))))
|
(sitemap (make-instance 'sitemap :urls (append '("" "sitemap.xml") urls))))
|
||||||
(write-file (rel-path (staging-dir *config*) "sitemap.xml")
|
(write-document sitemap (theme-fn 'sitemap "sitemap"))))
|
||||||
(funcall (theme-fn 'sitemap "sitemap")
|
|
||||||
(list :config *config*
|
|
||||||
:urls urls
|
|
||||||
:pubdate (format-timestring nil (now)))))))
|
|
||||||
|
|
||||||
(defun enable ())
|
(defun enable ())
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{template sitemap}
|
{template sitemap}
|
||||||
<?xml version="1.0"?>{\n}
|
<?xml version="1.0"?>{\n}
|
||||||
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>
|
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>
|
||||||
{foreach $url in $urls}
|
{foreach $url in $content.urls}
|
||||||
<url>
|
<url>
|
||||||
<loc>{$config.domain}/{$url}</loc>
|
<loc>{$config.domain}/{$url}</loc>
|
||||||
<lastmod>{$pubdate}</lastmod>
|
<lastmod>{$pubdate}</lastmod>
|
||||||
|
|
Loading…
Add table
Reference in a new issue