Flexible Lisp Blogware. Fork for personal use. Mirrored from https://github.com/kingcons/coleslaw originally.

feeds.lisp 1.4KB

1234567891011121314151617181920212223242526272829303132333435
  1. (in-package :coleslaw)
  2. (defun make-pubdate ()
  3. "Make a RFC1123 pubdate representing the current time."
  4. (local-time:format-rfc1123-timestring nil (local-time:now)))
  5. (defun first-10 (list)
  6. "Get up to the first 10 items in LIST."
  7. (subseq list 0 (min (length list) 10)))
  8. (defun make-tag-feed (tag posts)
  9. "Make an RSS feed for the given TAG and POSTS."
  10. (flet ((valid-p (obj) (member tag (content-tags obj) :test #'tag-slug=)))
  11. (make-instance 'tag-index :id (format nil "~A-rss.xml" (tag-slug tag))
  12. :posts (first-10 (remove-if-not #'valid-p posts)))))
  13. (defun render-feed (posts &key path template tag)
  14. "Given a PATH, TEMPLATE, and possibly a TAG, render the appropriate feed."
  15. (let ((template (theme-fn template "feeds"))
  16. (index (if tag
  17. (make-tag-feed tag posts)
  18. (make-instance 'index :id path
  19. :posts (first-10 posts)))))
  20. (write-page (page-path index) (render-page index template))))
  21. (defun render-feeds (tag-feeds)
  22. "Render the default RSS and ATOM feeds along with any TAG-FEEDS."
  23. (let ((posts (by-date (find-all 'post))))
  24. (dolist (feed '((:path "rss.xml" :template :rss-feed)
  25. (:path "feed.atom" :template :atom-feed)))
  26. (apply #'render-feed posts feed))
  27. (dolist (feed tag-feeds)
  28. (apply #'render-feed posts (list :tag (make-tag feed)
  29. :template :rss-feed)))))