diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-04-14 23:41:35 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-04-14 23:53:54 +0200 |
commit | 0d0f566f3e70214582ba0036f6fe53d141b60eb5 (patch) | |
tree | 8fa89977137c46b43a089a3547100ea9912ede0e /src/mulk/benki/book_marx.clj | |
parent | eb8fc654ec350d17f2ebc8164c9e6e70adc29d28 (diff) |
Refactor news feed generation.
Diffstat (limited to 'src/mulk/benki/book_marx.clj')
-rw-r--r-- | src/mulk/benki/book_marx.clj | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/src/mulk/benki/book_marx.clj b/src/mulk/benki/book_marx.clj index 5c556c2..16496d3 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 config webutil]) + [mulk.benki util db auth config webutil feed]) (:require [clojure.algo.monads :as m] [clojure.java.jdbc :as sql] [clojure.string :as string] @@ -16,12 +16,9 @@ [noir.response :as response] [noir.session :as session] hiccup.core) - (:import [org.jsoup Jsoup] - [org.apache.abdera Abdera])) + (:import [org.jsoup Jsoup])) -(defonce abdera (Abdera.)) - (def bookmark_tags (cq/table :bookmark_tags)) (def bookmarks (cq/table :bookmarks)) (def tags (cq/table :tags)) @@ -113,32 +110,18 @@ " [" [:a {:href (resolve-uri (authlink feed-link))} "Atom auth"] "]" " [" [:a {:href (authlink (:uri (request/ring-request)))} "authlink"] "]"))])])))) - (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))))) + items (map #(with-meta + (assoc % + (hiccup.core/html (htmlize-description (:description %)))) + {:type ::bookmark}) @marks)] + (generate-feed "Book Marx" last-updated "marx" (link :marx) + items))))) (defpage "/marx/feed" {} (response/content-type "application/atom+xml; charset=UTF-8" |