summaryrefslogtreecommitdiff
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
parent5e56d0c6a8f8fb4807626b2699b8785a87dd2d86 (diff)
Book Marx: Add an Atom feed.
-rw-r--r--config.sexp.sample1
-rw-r--r--project.clj1
-rw-r--r--src/mulk/benki/book_marx.clj54
-rw-r--r--src/mulk/benki/util.clj1
4 files changed, 49 insertions, 8 deletions
diff --git a/config.sexp.sample b/config.sexp.sample
index d408257..4353159 100644
--- a/config.sexp.sample
+++ b/config.sexp.sample
@@ -6,4 +6,5 @@
:user "benki"
:password ""}
:base-uri "http://localhost:3001"
+ :tag-base "example.com"
:web-port 3001}
diff --git a/project.clj b/project.clj
index 7fcb157..896a190 100644
--- a/project.clj
+++ b/project.clj
@@ -35,6 +35,7 @@
;;[clj-oauth2 "0.0.1"]
[org.openid4java/openid4java-consumer "0.9.6" :type "pom"]
[org.jsoup/jsoup "1.6.1"]
+ [org.apache.abdera/abdera-parser "1.1.1"]
]
:dev-dependencies [[swank-clojure "1.4.0-SNAPSHOT"]
[clj-stacktrace "0.2.3"]]
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
diff --git a/src/mulk/benki/util.clj b/src/mulk/benki/util.clj
index 18c3607..0d5136b 100644
--- a/src/mulk/benki/util.clj
+++ b/src/mulk/benki/util.clj
@@ -44,6 +44,7 @@
(match [(vec args)]
[[:login]] (fresolve "/login")
[[:marx]] (fresolve "/marx")
+ [[:marx id]] (fresolve "/marx/~a" id)
[[:wiki title & xs]] (fresolve "/wiki/~a~@[~a~]" title (first xs))
))