diff --git a/src/statuses/routes.clj b/src/statuses/routes.clj index 120de1f..10b9e10 100644 --- a/src/statuses/routes.clj +++ b/src/statuses/routes.clj @@ -39,3 +39,5 @@ (defn avatar-path [username] (clojure.string/replace (config :avatar-url) "{username}" username)) +(defn profile-path [username] + (str (config :profile-url-prefix) username)) diff --git a/src/statuses/routing.clj b/src/statuses/routing.clj index 6b34c50..a0e3d5a 100644 --- a/src/statuses/routing.clj +++ b/src/statuses/routing.clj @@ -7,6 +7,7 @@ [statuses.backend.persistence :refer [db]] [statuses.routes :as route] [statuses.views.atom :as atom] + [statuses.views.json :as json-decorator] [statuses.views.info :as info-view] [statuses.views.main :refer [list-page reply-form]] [statuses.views.too-long :as too-long-view])) @@ -54,7 +55,7 @@ (cond (= format "json") (content-type "application/json" - (json/as-json {:items items, :next next})) + (json/as-json {:items (json-decorator/decorate items), :next next})) (= format "atom") (content-type "application/atom+xml;charset=utf-8" (atom/render-atom items diff --git a/src/statuses/views/json.clj b/src/statuses/views/json.clj new file mode 100644 index 0000000..6e056ac --- /dev/null +++ b/src/statuses/views/json.clj @@ -0,0 +1,13 @@ +(ns statuses.views.json + (:require [statuses.routes :refer [avatar-path profile-path]])) + +(defn add-avatar [items] + (map (fn [item] (assoc item :avatar (avatar-path (:author item)))) items)) + +(defn add-profile [items] + (map (fn [item] (assoc item :self (profile-path (:author item)))) items)) + +(defn decorate [items] + (->> items + (add-avatar) + (add-profile))) diff --git a/src/statuses/views/main.clj b/src/statuses/views/main.clj index 51803a0..262346b 100644 --- a/src/statuses/views/main.clj +++ b/src/statuses/views/main.clj @@ -41,7 +41,7 @@ (defn update [is-current {:keys [id text author time in-reply-to conversation can-delete?]}] (list [:div.avatar - (link-to (str (config :profile-url-prefix) author) [:img {:src (avatar-path author) :alt author}])] + (link-to (profile-path author) [:img {:src (avatar-path author) :alt author}])] [:div.meta [:span.author (link-to (str (updates-path) "?author=" author) author)] (if in-reply-to