diff of 54d87dfd66e0ab3e7c8115d1cbe110bcc2b7b5a9
54d87dfd66e0ab3e7c8115d1cbe110bcc2b7b5a9
diff --git a/aggressive-murja.asd b/aggressive-murja.asd
index 4703adc..9c8449d 100644
--- a/aggressive-murja.asd
+++ b/aggressive-murja.asd
@@ -17,7 +17,8 @@
"str"
"cl-fad"
"log4cl"
- "cl-advice")
+ "cl-advice"
+ "xml-emitter")
:description "A rewrite of the <a href=\"https://github.com/feuery/murja-blog/\">murja blogging engine</a> in lisp"
:components ((:module "src"
:components
@@ -46,6 +47,7 @@
(:file "login-routes")
(:file "post-routes")
(:file "media-routes")
+ (:file "rss-routes")
(:file "root-routes")))
(:file "main"))))
:in-order-to ((test-op (test-op "pichunter/tests"))))
diff --git a/resources/sql/019-rss-settings.sql b/resources/sql/019-rss-settings.sql
new file mode 100644
index 0000000..fa2f8e1
--- /dev/null
+++ b/resources/sql/019-rss-settings.sql
@@ -0,0 +1,5 @@
+INSERT INTO blog.Settings VALUES ('rss-title', '"feuerx.net"');
+INSERT INTO blog.Settings VALUES ('rss-link', '"https://feuerx.net/blog"');
+INSERT INTO blog.Settings VALUES ('rss-description', '"Ilpo pyöräilemässä ja koodailemassa"');
+INSERT INTO blog.Settings VALUES ('rss-lang', '"fi-fi"');
+INSERT INTO blog.Settings VALUES ('rss-email', '"feuer+rss@feuerx.net"');
diff --git a/src/migration-list.lisp b/src/migration-list.lisp
index 896af6e..4a4bd61 100644
--- a/src/migration-list.lisp
+++ b/src/migration-list.lisp
@@ -23,6 +23,7 @@
(defmigration "016-hardcoded-hidden-unlisted")
(defmigration "017-settings-in-db")
(defmigration "018-previously")
+(defmigration "019-rss-settings")
(defun prepare-e2e-migration ()
(postmodern:execute "DELETE FROM blog.Users")
diff --git a/src/routes/rss-routes.lisp b/src/routes/rss-routes.lisp
new file mode 100644
index 0000000..be337bb
--- /dev/null
+++ b/src/routes/rss-routes.lisp
@@ -0,0 +1,43 @@
+(defpackage murja.routes.rss-routes
+ (:use :cl)
+ (:import-from :easy-routes :defroute)
+ (:import-from :murja.posts.post-db :get-page)
+ (:import-from :murja.routes.settings-routes :get-settings)
+ (:import-from :murja.middleware.db :@transaction)
+ (:import-from :murja.middleware.auth :@authenticated :*user* :@can?))
+
+(in-package :murja.routes.rss-routes)
+
+(defun posts->rss (posts)
+ (let* ((settings (get-settings))
+ (title (gethash "rss-title" settings))
+ (link (gethash "rss-link" settings))
+ (description (gethash "rss-description" settings))
+ (lang (gethash "rss-lang" settings))
+ (mail (gethash "rss-mail" settings))
+ (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 "/post/~d" (gethash "id" post))
+ :description (let ((len (length (gethash "content" post))))
+ (if (> len 500)
+ (subseq (gethash "content" post)
+ 0 500)
+ (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* ((settings (get-settings))
+ (page-size (gethash "recent-post-count" settings))
+ (page (get-page 1 page-size :allow-hidden? nil)))
+ (setf (hunchentoot:content-type*) "application/rss+xml")
+ (posts->rss page)))