added rss feed
This commit is contained in:
parent
f8cbf0cec7
commit
84f02df46c
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
32
src/blarg/routes/rss.clj
Normal file
32
src/blarg/routes/rss.clj
Normal file
|
@ -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)))
|
|
@ -4,6 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>blarg.ca{{html-title|default:}}</title>
|
||||
<link href="{{context}}/rss" rel="alternate" title="blarg.ca" type="application/rss+xml" />
|
||||
|
||||
<link href="{{context}}/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="{{context}}/css/bootstrap-markdown.css" rel="stylesheet" type="text/css" />
|
||||
|
|
Reference in a new issue