src/routes/rss-routes.lisp

DOWNLOAD
(in-package :murja.routes.rss-routes)

(defun posts->rss (posts)
  (let* ((title (rss-title))
	 (link (rss-link))
	 (description (rss-description))
	 (lang (rss-lang))
	 (output (make-string-output-stream)))
    (xml-emitter:with-rss2 (output)
      (xml-emitter:rss-channel-header title
				      link
				      :description description
				      :language lang)
      (dolist (post posts)
	(xml-emitter:rss-item (gethash "title" post)
			      :link (format nil "~a/post/~d" link (gethash "id" post))
			      :description (gethash "content" post)
			      :author (gethash "nickname"
					       (gethash "creator" post))
			      :pubdate (gethash "created_at" post))))
    (get-output-stream-string output)))

(defroute rsssss ("/api/rss" :method :get
			     :decorators ( @transaction)) ()
  (let ((lisp-fixup:*rfc822* t))
    (let* ((if-modified-since (when (hunchentoot:header-in* :if-modified-since)
				(lisp-fixup:if-modified-since->simpledate-timestamp
				 (hunchentoot:header-in* :if-modified-since))))
	   (page (get-page 1 (page-size) :allow-hidden? nil
					 :modified-since if-modified-since))
	   (last-modified 
	     ;; this application's tz handling is a fucking joke 
	     (str:replace-all "EST" "GMT" 
			      (lisp-fixup:fix-timestamp (caar (murja.posts.post-db:last-modified*))))))

      (setf (hunchentoot:content-type*) "application/rss+xml")
      (setf (hunchentoot:header-out "Last-Modified") last-modified)
      (posts->rss page))))