summaryrefslogtreecommitdiff
path: root/src/mulk/benki/book_marx.clj
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-02-27 23:25:23 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-02-27 23:25:23 +0100
commit453f7bfec6cba157c81ac1c170cd92aee38e4762 (patch)
treeebdafb432ba3af6f09070d79f5d4bd680836d5c2 /src/mulk/benki/book_marx.clj
parent5e56d0c6a8f8fb4807626b2699b8785a87dd2d86 (diff)
Book Marx: Add an Atom feed.
Diffstat (limited to 'src/mulk/benki/book_marx.clj')
-rw-r--r--src/mulk/benki/book_marx.clj54
1 files changed, 46 insertions, 8 deletions
diff --git a/src/mulk/benki/book_marx.clj b/src/mulk/benki/book_marx.clj
index 000e9c8..0c02a02 100644
--- a/src/mulk/benki/book_marx.clj
+++ b/src/mulk/benki/book_marx.clj
@@ -7,7 +7,7 @@
[hiccup.core :only [escape-html]]
[ring.util.codec :only [url-encode]]
noir.core
- [mulk.benki util db auth])
+ [mulk.benki util db auth config])
(:require [clojure.algo.monads :as m]
[clojure.java.jdbc :as sql]
[clojure.string :as string]
@@ -16,7 +16,11 @@
[noir.response :as response]
[noir.session :as session]
hiccup.core)
- (:import [org.jsoup Jsoup]))
+ (:import [org.jsoup Jsoup]
+ [org.apache.abdera Abdera]))
+
+
+(defonce abdera (Abdera.))
(def bookmark_tags (cq/table :bookmark_tags))
(def bookmarks (cq/table :bookmarks))
@@ -62,14 +66,17 @@
(let [input (escape-html text)]
(map (fn [x] [:p {} x]) (string/split text #"\n\s*?\n"))))
+(defn bookmarks-visible-by [user]
+ (-> bookmarks
+ (cq/join users (=* :bookmarks.owner :users.id))
+ (cq/project [:bookmarks.* :users.first_name :users.last_name])
+ ;;(cq/rename {:users.id :uid})
+ (restrict-visibility user)
+ (cq/sort [:date#desc])))
+
(defpage "/marx" {}
(let [user (session/get :user)
- marks (-> bookmarks
- (cq/join users (=* :bookmarks.owner :users.id))
- (cq/project [:bookmarks.* :users.first_name])
- ;;(cq/rename {:users.id :uid})
- (restrict-visibility (session/get :user))
- (cq/sort [:date#desc]))]
+ marks (bookmarks-visible-by user)]
(with-dbt
(layout bookmarx-list-page "Book Marx"
[:p
@@ -87,6 +94,37 @@
[:div {:class "bookmark-description"}
(htmlize-description (:description mark))]])]]))))
+(defn marx-feed-for-user [user]
+ (let [marks (bookmarks-visible-by user)]
+ (with-dbt
+ (let [last-updated (sql/with-query-results results
+ ["SELECT MAX(date) AS maxdate FROM bookmarks"]
+ (:maxdate (first results)))
+ feed (doto (.newFeed abdera)
+ (.setId (fmt nil "tag:~A,2012:/marx"
+ (:tag-base @benki-config)))
+ (.setTitle "Book Marx")
+ (.setUpdated last-updated)
+ (.addLink (link :marx)))]
+ (doseq [mark @marks]
+ (doto (.addEntry feed)
+ (.setId (fmt nil "tag:~A,2012:/marx/~D"
+ (:tag-base benki-config)
+ (:id mark)))
+ (.setTitle (:title mark))
+ (.setSummaryAsHtml (hiccup.core/html (htmlize-description (:description mark))))
+ ;;(.setUpdated (:updated mark))
+ (.setPublished (:date mark))
+ ;;(.setAuthor (fmt nil "~A ~A" (:first_name mark) (:last_name mark)))
+ ;;(.addLink (link :marx (:id mark)))
+ (.addLink (:uri mark))))
+ (.toString feed)))))
+
+(defpage "/marx/feed" {}
+ (let [user (session/get :user)]
+ (response/content-type "application/atom+xml"
+ (marx-feed-for-user user))))
+
(defpage "/marx/tags" {}
(with-auth
(with-dbt