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

sitemap.lisp 1.0KB

12345678910111213141516171819202122232425262728293031
  1. (defpackage :coleslaw-sitemap
  2. (:use :cl)
  3. (:import-from :coleslaw #:*config*
  4. #:index
  5. #:page-url
  6. #:find-all
  7. #:publish
  8. #:theme-fn
  9. #:add-document
  10. #:write-document)
  11. (:import-from :alexandria #:hash-table-values)
  12. (:export #:enable))
  13. (in-package :coleslaw-sitemap)
  14. (defclass sitemap ()
  15. ((urls :initarg :urls :reader urls)))
  16. (defmethod page-url ((object sitemap)) "sitemap.xml")
  17. ;; We do 'discovery' in the publish method here because we can't ensure the
  18. ;; sitemap discover method is called last. Need all other content to be
  19. ;; discovered/in the DB.
  20. (defmethod publish ((doc-type (eql (find-class 'sitemap))))
  21. (let* ((base-urls '("" "sitemap.xml"))
  22. (urls (mapcar #'page-url (hash-table-values coleslaw::*site*)))
  23. (sitemap (make-instance 'sitemap :urls (append base-urls urls))))
  24. (write-document sitemap (theme-fn 'sitemap "sitemap"))))
  25. (defun enable ())