move sitemap to plugins
This commit is contained in:
parent
edcd1022ab
commit
488191b237
5 changed files with 9 additions and 38 deletions
|
@ -55,7 +55,6 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
|
||||||
(when (probe-file dir)
|
(when (probe-file dir)
|
||||||
(run-program "cp -R ~a ." dir)))
|
(run-program "cp -R ~a ." dir)))
|
||||||
(do-ctypes (publish ctype))
|
(do-ctypes (publish ctype))
|
||||||
(render-sitemap)
|
|
||||||
(render-indices)
|
(render-indices)
|
||||||
(render-feeds (feeds *config*))))
|
(render-feeds (feeds *config*))))
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,6 @@
|
||||||
((name :initform nil :initarg :name :accessor tag-name)
|
((name :initform nil :initarg :name :accessor tag-name)
|
||||||
(slug :initform nil :Initarg :slug :accessor tag-slug)))
|
(slug :initform nil :Initarg :slug :accessor tag-slug)))
|
||||||
|
|
||||||
(defmethod page-url ((object tag))
|
|
||||||
(format nil "tag/~a" (tag-slug object)))
|
|
||||||
|
|
||||||
(defun make-tag (str)
|
(defun make-tag (str)
|
||||||
"Takes a string and returns a TAG instance with a name and slug."
|
"Takes a string and returns a TAG instance with a name and slug."
|
||||||
(let ((trimmed (string-trim " " str)))
|
(let ((trimmed (string-trim " " str)))
|
||||||
|
|
|
@ -4,29 +4,6 @@
|
||||||
"Make a RFC1123 pubdate representing the current time."
|
"Make a RFC1123 pubdate representing the current time."
|
||||||
(local-time:format-rfc1123-timestring nil (local-time:now)))
|
(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)
|
(defun render-feed (posts &key path template tag)
|
||||||
(flet ((first-10 (list) (subseq list 0 (min (length list) 10)))
|
(flet ((first-10 (list) (subseq list 0 (min (length list) 10)))
|
||||||
(tag-posts (list) (remove-if-not (lambda (x) (tag-p tag x)) list)))
|
(tag-posts (list) (remove-if-not (lambda (x) (tag-p tag x)) list)))
|
||||||
|
|
|
@ -16,17 +16,15 @@
|
||||||
(defclass tag-index (index) ())
|
(defclass tag-index (index) ())
|
||||||
(defclass date-index (index) ())
|
(defclass date-index (index) ())
|
||||||
(defclass int-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))
|
(defmethod page-url ((object index))
|
||||||
(index-id object))
|
(index-id object))
|
||||||
|
(defmethod page-url ((object tag-index))
|
||||||
|
(format nil "tags/~a" (index-id object)))
|
||||||
(defmethod page-url ((object date-index))
|
(defmethod page-url ((object date-index))
|
||||||
(format nil "date/~a" (index-id object)))
|
(format nil "date/~a" (index-id object)))
|
||||||
|
(defmethod page-url ((object int-index))
|
||||||
|
(format nil "~d" (index-id object)))
|
||||||
|
|
||||||
(defun all-months ()
|
(defun all-months ()
|
||||||
"Retrieve a list of all months with published content."
|
"Retrieve a list of all months with published content."
|
||||||
|
@ -42,7 +40,7 @@
|
||||||
|
|
||||||
(defun index-by-tag (tag content)
|
(defun index-by-tag (tag content)
|
||||||
"Return an index of all CONTENT matching the given TAG."
|
"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)
|
:posts (remove-if-not (lambda (x) (tag-p tag x)) content)
|
||||||
:title (format nil "Posts tagged ~a" (tag-name tag))))
|
: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."
|
"Return the index for the Ith page of CONTENT in reverse chronological order."
|
||||||
(let* ((start (* step i))
|
(let* ((start (* step i))
|
||||||
(end (min (length content) (+ start step))))
|
(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)
|
:posts (subseq content start end)
|
||||||
:title "Recent Posts")))
|
:title "Recent Posts")))
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
{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 $content.urls}
|
{foreach $url in $urls}
|
||||||
<url>
|
<url>
|
||||||
<loc>{$config.domain}/{$url}</loc>
|
<loc>{$domain}/{$url}</loc>
|
||||||
<lastmod>{$content.pubdate}</lastmod>
|
<lastmod>{$pubdate}</lastmod>
|
||||||
</url>
|
</url>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|
Loading…
Add table
Reference in a new issue