Make RSS and ATOM templates theme-independent.

This commit is contained in:
Brit Butler 2013-04-01 11:23:10 -04:00
parent b72eb5b03a
commit 9bc2e55d58
6 changed files with 17 additions and 11 deletions

View file

@ -1,3 +1,7 @@
## Changes for 0.9.1 (2013-04-xx):
* Make ATOM and RSS templates a separate "generic" theme. (thanks @woudshoo!)
## Changes for 0.9 (2013-02-20): ## Changes for 0.9 (2013-02-20):
* INCOMPATIBLE CHANGE: All :plugins in .coleslawrc must be lists. (i.e. (mathjax) not mathjax) * INCOMPATIBLE CHANGE: All :plugins in .coleslawrc must be lists. (i.e. (mathjax) not mathjax)

View file

@ -24,7 +24,7 @@
(defun render-page (content &optional theme-fn &rest render-args) (defun render-page (content &optional theme-fn &rest render-args)
"Render the given CONTENT to disk using THEME-FN if supplied. "Render the given CONTENT to disk using THEME-FN if supplied.
Additional args to render CONTENT can be passed via RENDER-ARGS." Additional args to render CONTENT can be passed via RENDER-ARGS."
(funcall (theme-fn (or theme-fn 'base)) (funcall (or theme-fn (theme-fn 'base))
(list :config *config* (list :config *config*
:content content :content content
:raw (apply 'render content render-args) :raw (apply 'render content render-args)

View file

@ -11,11 +11,13 @@
(let* ((by-date (by-date (find-all 'post))) (let* ((by-date (by-date (find-all 'post)))
(posts (first-10 by-date)) (posts (first-10 by-date))
(rss (make-instance 'index :id "rss.xml" :posts posts)) (rss (make-instance 'index :id "rss.xml" :posts posts))
(atom (make-instance 'index :id "feed.atom" :posts posts))) (atom (make-instance 'index :id "feed.atom" :posts posts))
(write-page (page-path rss) (render-page rss :rss-feed)) (rss-template (theme-fn :rss-feed "feeds"))
(write-page (page-path atom) (render-page atom :atom-feed)) (atom-template (theme-fn :atom-feed "feeds")))
(write-page (page-path rss) (render-page rss rss-template))
(write-page (page-path atom) (render-page atom atom-template))
(dolist (feed feeds) (dolist (feed feeds)
(let ((index (index-by-tag feed by-date))) (let ((index (index-by-tag feed by-date)))
(setf (index-id index) (format nil "~a-rss.xml" feed) (setf (index-id index) (format nil "~a-rss.xml" feed)
(index-posts index) (first-10 (index-posts index))) (index-posts index) (first-10 (index-posts index)))
(write-page (page-path index) (render-page index :rss-feed))))))) (write-page (page-path index) (render-page index rss-template)))))))

View file

@ -22,13 +22,13 @@ any return value other than nil indicates the injection should be added."
(list :head (injections-for :head) (list :head (injections-for :head)
:body (injections-for :body)))) :body (injections-for :body))))
(defun theme-package (&key (name (theme *config*))) (defun theme-package (name)
"Find the package matching the theme NAME." "Find the package matching the theme NAME."
(find-package (string-upcase (concatenate 'string "coleslaw.theme." name)))) (find-package (string-upcase (concatenate 'string "coleslaw.theme." name))))
(defun theme-fn (name) (defun theme-fn (name &optional (package (theme *config*)))
"Find the symbol NAME inside the current theme's package." "Find the symbol NAME inside PACKAGE which defaults to the theme package."
(find-symbol (princ-to-string name) (theme-package))) (find-symbol (princ-to-string name) (theme-package package)))
(defun compile-theme (theme) (defun compile-theme (theme)
"Locate and compile the templates for the given THEME." "Locate and compile the templates for the given THEME."

View file

@ -1,4 +1,4 @@
{namespace coleslaw.theme.hyde} {namespace coleslaw.theme.feeds}
{template atom-feed} {template atom-feed}
<?xml version="1.0"?>{\n} <?xml version="1.0"?>{\n}

View file

@ -1,4 +1,4 @@
{namespace coleslaw.theme.hyde} {namespace coleslaw.theme.feeds}
{template rss-feed} {template rss-feed}
<?xml version="1.0"?>{\n} <?xml version="1.0"?>{\n}