From 84f02df46cb81d12730e40cb21a4071a33143479 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 27 May 2013 00:46:38 -0400 Subject: [PATCH] added rss feed --- project.clj | 3 ++- src/blarg/handler.clj | 3 ++- src/blarg/routes/posts.clj | 3 +-- src/blarg/routes/rss.clj | 32 +++++++++++++++++++++++++++++ src/blarg/views/templates/base.html | 1 + 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/blarg/routes/rss.clj diff --git a/project.clj b/project.clj index 98d7091..a8061c9 100644 --- a/project.clj +++ b/project.clj @@ -14,7 +14,8 @@ [slugger "1.0.1"] [clj-time "0.5.0"] [org.clojure/math.numeric-tower "0.0.2"] - [cheshire "5.1.2"]] + [cheshire "5.1.2"] + [clj-rss "0.1.3"]] :plugins [[lein-ring "0.8.5"]] :ring {:handler blarg.handler/war-handler :init blarg.handler/init diff --git a/src/blarg/handler.clj b/src/blarg/handler.clj index 0612ac9..377c28c 100644 --- a/src/blarg/handler.clj +++ b/src/blarg/handler.clj @@ -3,6 +3,7 @@ blarg.routes.posts blarg.routes.auth blarg.routes.files + blarg.routes.rss blarg.routes.accessrules compojure.core) (:require [noir.util.middleware :as middleware] @@ -49,7 +50,7 @@ (timbre/info "blarg is shutting down...")) ;;append your application routes to the all-routes vector -(def all-routes [auth-routes home-routes posts-routes files-routes app-routes]) +(def all-routes [auth-routes home-routes posts-routes files-routes rss-routes app-routes]) (def app (-> all-routes (middleware/app-handler) diff --git a/src/blarg/routes/posts.clj b/src/blarg/routes/posts.clj index 040179a..5602ee7 100644 --- a/src/blarg/routes/posts.clj +++ b/src/blarg/routes/posts.clj @@ -4,8 +4,7 @@ [noir.util.route] [blarg.util] [blarg.routes.helpers]) - (:require [clj-time.core] - [clojure.math.numeric-tower :as math] + (:require [clojure.math.numeric-tower :as math] [noir.response :as resp] [noir.validation :as vali] [noir.session :as session] diff --git a/src/blarg/routes/rss.clj b/src/blarg/routes/rss.clj new file mode 100644 index 0000000..02936f4 --- /dev/null +++ b/src/blarg/routes/rss.clj @@ -0,0 +1,32 @@ +(ns blarg.routes.rss + (:use [blarg.routes.helpers] + [compojure.core]) + (:require [markdown.core :as md] + [noir.response :as resp] + [clj-rss.core :as rss] + [clj-time.core] + [clj-time.coerce] + [blarg.models.posts :as posts])) + +(def rss-title "blarg.ca") +(def rss-site-url "http://www.blarg.ca/") +(def rss-description "Assorted code and random ramblings.") + +(defn handle-rss [] + (let [channel {:title rss-title + :link rss-site-url + :description rss-description} + items (doall + (map + (fn [post] + {:title (:title post) + :pubDate (clj-time.coerce/to-date (:created_at post)) + :link (str rss-site-url (subs (get-post-url post) 1)) + :description (md/md-to-html-string (:body post))}) + (posts/list-posts false 10)))] + (resp/content-type "text/xml" + (apply (partial rss/channel-xml channel) + items)))) + +(defroutes rss-routes + (GET "/rss" [] (handle-rss))) diff --git a/src/blarg/views/templates/base.html b/src/blarg/views/templates/base.html index 31fce77..a2482bd 100644 --- a/src/blarg/views/templates/base.html +++ b/src/blarg/views/templates/base.html @@ -4,6 +4,7 @@ blarg.ca{{html-title|default:}} +