Add the RSS feed for Florian :P
This commit is contained in:
parent
7429e12dbe
commit
ebd0713eae
8 changed files with 96 additions and 22 deletions
|
@ -4,6 +4,9 @@
|
||||||
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>yenu -- the image sharing tool for friends</title>
|
<title>yenu -- the image sharing tool for friends</title>
|
||||||
|
{% if identity %}
|
||||||
|
<link rel="alternate" type="application/atom+xml" title="Images" href="/feed?password={{ passwordhash }}" />
|
||||||
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-toggleable-md bg-inverse navbar-inverse">
|
<nav class="navbar navbar-toggleable-md bg-inverse navbar-inverse">
|
||||||
|
@ -42,6 +45,13 @@
|
||||||
</li>
|
</li>
|
||||||
-->
|
-->
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
|
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/feed?password={{ passwordhash }}" >
|
||||||
|
<span class="fa fa-rss-square"></span>
|
||||||
|
RSS-Feed
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/logout">
|
<a class="nav-link" href="/logout">
|
||||||
<span class="fa fa-sign-out"></span>
|
<span class="fa fa-sign-out"></span>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
[yenu.layout :refer [error-page]]
|
[yenu.layout :refer [error-page]]
|
||||||
[yenu.routes.auth :refer [auth-routes]]
|
[yenu.routes.auth :refer [auth-routes]]
|
||||||
[yenu.routes.core :refer [core-routes]]
|
[yenu.routes.core :refer [core-routes]]
|
||||||
|
[yenu.routes.feed :refer [feed-routes]]
|
||||||
[yenu.routes.admin :refer [admin-routes]]
|
[yenu.routes.admin :refer [admin-routes]]
|
||||||
[compojure.route :as route]
|
[compojure.route :as route]
|
||||||
[yenu.env :refer [defaults]]
|
[yenu.env :refer [defaults]]
|
||||||
|
@ -19,6 +20,10 @@
|
||||||
(wrap-routes middleware/wrap-csrf)
|
(wrap-routes middleware/wrap-csrf)
|
||||||
(wrap-routes middleware/wrap-identity)
|
(wrap-routes middleware/wrap-identity)
|
||||||
(wrap-routes middleware/wrap-formats))
|
(wrap-routes middleware/wrap-formats))
|
||||||
|
(-> #'feed-routes
|
||||||
|
(wrap-routes middleware/wrap-identity)
|
||||||
|
(wrap-routes middleware/wrap-formats)
|
||||||
|
(wrap-routes middleware/wrap-auth))
|
||||||
(-> #'core-routes
|
(-> #'core-routes
|
||||||
(wrap-routes middleware/wrap-csrf)
|
(wrap-routes middleware/wrap-csrf)
|
||||||
(wrap-routes middleware/wrap-formats)
|
(wrap-routes middleware/wrap-formats)
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
[yenu.helpers.images :as image-helper]
|
[yenu.helpers.images :as image-helper]
|
||||||
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
|
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
|
||||||
[clj-time.format :as time-format]
|
[clj-time.format :as time-format]
|
||||||
|
[yenu.config :refer [env]]
|
||||||
|
[digest :as digest]
|
||||||
[clj-time.core :as time])
|
[clj-time.core :as time])
|
||||||
(:use [markdown.core]))
|
(:use [markdown.core]))
|
||||||
|
|
||||||
|
@ -18,9 +20,7 @@
|
||||||
(filter/add-filter! :markdown-to-html md-to-html-string)
|
(filter/add-filter! :markdown-to-html md-to-html-string)
|
||||||
(filter/add-filter! :parse-date #(time/to-time-zone (time-format/parse %) (time/default-time-zone)))
|
(filter/add-filter! :parse-date #(time/to-time-zone (time-format/parse %) (time/default-time-zone)))
|
||||||
|
|
||||||
(defn render
|
(defn render-file [template & [params]]
|
||||||
"renders the HTML template located relative to resources/templates"
|
|
||||||
[template & [params]]
|
|
||||||
(content-type
|
(content-type
|
||||||
(ok
|
(ok
|
||||||
(parser/render-file
|
(parser/render-file
|
||||||
|
@ -29,9 +29,19 @@
|
||||||
:page template
|
:page template
|
||||||
:csrf-token *anti-forgery-token*
|
:csrf-token *anti-forgery-token*
|
||||||
:servlet-context *app-context*
|
:servlet-context *app-context*
|
||||||
|
:passwordhash (digest/md5 (:user-password env))
|
||||||
:identity *identity*)))
|
:identity *identity*)))
|
||||||
"text/html; charset=utf-8"))
|
"text/html; charset=utf-8"))
|
||||||
|
|
||||||
|
(defn render [string contenttype]
|
||||||
|
(content-type
|
||||||
|
(-> (ok string)
|
||||||
|
(assoc :servlet-context *app-context*
|
||||||
|
:csrf-token *anti-forgery-token*
|
||||||
|
:passwordhash (digest/md5 (:user-password env))
|
||||||
|
:identity *identity*))
|
||||||
|
(str contenttype "; charset=utf-8")))
|
||||||
|
|
||||||
(defn error-page
|
(defn error-page
|
||||||
"error-details should be a map containing the following keys:
|
"error-details should be a map containing the following keys:
|
||||||
:status - error status
|
:status - error status
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
[buddy.auth.accessrules :refer [restrict]]
|
[buddy.auth.accessrules :refer [restrict]]
|
||||||
[ring.util.response :refer [redirect]]
|
[ring.util.response :refer [redirect]]
|
||||||
[buddy.auth.accessrules :refer [success error]]
|
[buddy.auth.accessrules :refer [success error]]
|
||||||
|
[clojure.tools.logging :as log]
|
||||||
|
[digest :as digest]
|
||||||
[buddy.auth :refer [authenticated?]])
|
[buddy.auth :refer [authenticated?]])
|
||||||
(:import [javax.servlet ServletContext]))
|
(:import [javax.servlet ServletContext]))
|
||||||
|
|
||||||
|
@ -75,8 +77,15 @@
|
||||||
true
|
true
|
||||||
(error "Not a creator."))))
|
(error "Not a creator."))))
|
||||||
|
|
||||||
|
(defn external-access-with-pw [request]
|
||||||
|
(if (= (get (:query-params request) "password") (digest/md5 (:user-password env)))
|
||||||
|
true
|
||||||
|
(error "Wrong password.")))
|
||||||
|
|
||||||
(def rules
|
(def rules
|
||||||
[{:uris ["/upload" "/statistics" "/comments"]
|
[{:uris ["/feed"]
|
||||||
|
:handler external-access-with-pw}
|
||||||
|
{:uris ["/upload" "/statistics" "/comments"]
|
||||||
:handler creator-access}
|
:handler creator-access}
|
||||||
{:pattern #"^/.*"
|
{:pattern #"^/.*"
|
||||||
:handler authenticated?}])
|
:handler authenticated?}])
|
||||||
|
|
|
@ -46,12 +46,12 @@
|
||||||
|
|
||||||
(defn comment-stream []
|
(defn comment-stream []
|
||||||
(let [comments (db/get-recent-comments {:num-comments 20})]
|
(let [comments (db/get-recent-comments {:num-comments 20})]
|
||||||
(layout/render "comments.html" {:comments comments})))
|
(layout/render-file "comments.html" {:comments comments})))
|
||||||
|
|
||||||
(defn edit-image-form [id request]
|
(defn edit-image-form [id request]
|
||||||
(let [image (db/get-image {:id id})
|
(let [image (db/get-image {:id id})
|
||||||
tags (db/get-tags-for-image {:id id})]
|
tags (db/get-tags-for-image {:id id})]
|
||||||
(layout/render "admin/upload.html" {:image image :tags tags})))
|
(layout/render-file "admin/upload.html" {:image image :tags tags})))
|
||||||
|
|
||||||
(defn edit-image! [id title description tags request]
|
(defn edit-image! [id title description tags request]
|
||||||
(db/edit-image! {:id id :title title :description description})
|
(db/edit-image! {:id id :title title :description description})
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
(defroutes admin-routes
|
(defroutes admin-routes
|
||||||
(GET "/upload" [:as request]
|
(GET "/upload" [:as request]
|
||||||
(-> (layout/render
|
(-> (layout/render-file
|
||||||
"admin/upload.html"
|
"admin/upload.html"
|
||||||
{:flash (:flash request)})))
|
{:flash (:flash request)})))
|
||||||
(POST "/upload" [file title description tags]
|
(POST "/upload" [file title description tags]
|
||||||
|
@ -93,6 +93,6 @@
|
||||||
(assoc :flash {:message "Bild wurde bearbeitet" :type "success"})))
|
(assoc :flash {:message "Bild wurde bearbeitet" :type "success"})))
|
||||||
|
|
||||||
(GET "/statistics" []
|
(GET "/statistics" []
|
||||||
(layout/render "statistics.html"))
|
(layout/render-file "statistics.html"))
|
||||||
(GET "/comments" []
|
(GET "/comments" []
|
||||||
(comment-stream)))
|
(comment-stream)))
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
(defroutes auth-routes
|
(defroutes auth-routes
|
||||||
(GET "/login" [:as request]
|
(GET "/login" [:as request]
|
||||||
(layout/render "login.html", {:flash (:flash request)}))
|
(layout/render-file "login.html", {:flash (:flash request)}))
|
||||||
(POST "/login" [] login!)
|
(POST "/login" [] login!)
|
||||||
|
|
||||||
(GET "/logout" [] logout!))
|
(GET "/logout" [] logout!))
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
[ring.util.response :refer [redirect file-response]]
|
[ring.util.response :refer [redirect file-response]]
|
||||||
[yenu.helpers.images :as images]
|
[yenu.helpers.images :as images]
|
||||||
[hiccup.core :as h]
|
[hiccup.core :as h]
|
||||||
|
[hiccup.page :as p]
|
||||||
|
[clj-time.format :as time-format]
|
||||||
|
[clj-time.core :as time]
|
||||||
|
[yenu.config :refer [env]]
|
||||||
[yenu.db.core :as db]))
|
[yenu.db.core :as db]))
|
||||||
|
|
||||||
(defn number-of-pages [images-on-page]
|
(defn number-of-pages [images-on-page]
|
||||||
|
@ -50,25 +54,25 @@
|
||||||
offset (* (dec current) image-count)
|
offset (* (dec current) image-count)
|
||||||
pages (number-of-pages image-count)
|
pages (number-of-pages image-count)
|
||||||
images (db/get-all-images {:offset offset :count image-count})]
|
images (db/get-all-images {:offset offset :count image-count})]
|
||||||
(layout/render "index.html"
|
(layout/render-file "index.html"
|
||||||
{:images images
|
{:images images
|
||||||
:flash (:flash request)
|
:flash (:flash request)
|
||||||
:pagination (pagination pages current)
|
:pagination (pagination pages current)
|
||||||
:pagination-mobile (pagination-mobile pages current)})))
|
:pagination-mobile (pagination-mobile pages current)})))
|
||||||
|
|
||||||
(defn detail-page [image-id request]
|
(defn detail-page [image-id request]
|
||||||
(let [image (db/get-image {:id image-id})
|
(let [image (db/get-image {:id image-id})
|
||||||
next-img (db/get-next-image {:image-date (:created_at image)})
|
next-img (db/get-next-image {:image-date (:created_at image)})
|
||||||
prev-img (db/get-prev-image {:image-date (:created_at image)})
|
prev-img (db/get-prev-image {:image-date (:created_at image)})
|
||||||
saved-author (get-in request [:cookies "author" :value])]
|
saved-author (get-in request [:cookies "author" :value])]
|
||||||
(layout/render "detail.html"
|
(layout/render-file "detail.html"
|
||||||
{:image image
|
{:image image
|
||||||
:flash (:flash request)
|
:flash (:flash request)
|
||||||
:next-image next-img
|
:next-image next-img
|
||||||
:prev-image prev-img
|
:prev-image prev-img
|
||||||
:tags (db/get-tags-for-image {:id (:id image)})
|
:tags (db/get-tags-for-image {:id (:id image)})
|
||||||
:saved-author saved-author
|
:saved-author saved-author
|
||||||
:comments (db/get-comments-for-image {:image_id (:id image)})})))
|
:comments (db/get-comments-for-image {:image_id (:id image)})})))
|
||||||
|
|
||||||
(defn add-comment! [image-id request]
|
(defn add-comment! [image-id request]
|
||||||
(let [author (:author (:params request))
|
(let [author (:author (:params request))
|
||||||
|
|
36
src/clj/yenu/routes/feed.clj
Normal file
36
src/clj/yenu/routes/feed.clj
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
(ns yenu.routes.feed
|
||||||
|
(:require [hiccup.core :as h]
|
||||||
|
[compojure.core :refer [defroutes GET]]
|
||||||
|
[clj-time.format :as time-format]
|
||||||
|
[clj-time.core :as time]
|
||||||
|
[yenu.config :refer [env]]
|
||||||
|
[yenu.layout :refer [render]]
|
||||||
|
[yenu.db.core :as db])
|
||||||
|
(:use [markdown.core]))
|
||||||
|
|
||||||
|
(defn rss-feed []
|
||||||
|
(let [entries (db/get-all-images {:offset 0 :count 25})
|
||||||
|
with-ts #(time/to-time-zone (time-format/parse %) (time/default-time-zone))]
|
||||||
|
(str
|
||||||
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||||
|
(h/html
|
||||||
|
[:feed {:xmlns "http://www.w3.org/2005/Atom"}
|
||||||
|
[:author [:name "Aaron Fischer"]]
|
||||||
|
[:author [:name "Beatrice Fischer"]]
|
||||||
|
[:title "yenu -- the image sharing tool for friends"]
|
||||||
|
[:id (str "https://yenu.de/")]
|
||||||
|
[:updated (with-ts (:created_at (first entries)))]
|
||||||
|
(for [e entries]
|
||||||
|
[:entry
|
||||||
|
[:title (h/h (:title e))]
|
||||||
|
[:link {:href (str "https://yenu.de/show/" (:id e)) :rel "alternate"}]
|
||||||
|
[:id (str "https://yenu.de/show/" (:id e))]
|
||||||
|
[:updated (with-ts (:created_at e))]
|
||||||
|
[:summary (h/h (:title e))]
|
||||||
|
[:content {:type "xhtml"}
|
||||||
|
[:div {:xmlns "http://www.w3.org/1999/xhtml"}
|
||||||
|
(md-to-html-string (h/h (:description e)))]]])]))))
|
||||||
|
|
||||||
|
(defroutes feed-routes
|
||||||
|
(GET "/feed" []
|
||||||
|
(render (rss-feed) "text/xml")))
|
Loading…
Reference in a new issue