mirror of
https://github.com/tanrax/RSSPAPER.git
synced 2025-11-25 20:16:19 -05:00
Fix format
This commit is contained in:
@@ -8,13 +8,11 @@
|
||||
|
||||
(def date-custom-formatter (f/formatter "dd MM yyyy"))
|
||||
|
||||
|
||||
(defn datetimes-to-unixtime
|
||||
[articles]
|
||||
(map (fn [article]
|
||||
(assoc article :published-date (c/to-long (:published-date article)))) articles))
|
||||
|
||||
|
||||
(defn filter-edition
|
||||
[articles]
|
||||
(let [daily (c/to-long (t/minus (t/now) (t/days 1)))
|
||||
@@ -24,20 +22,17 @@
|
||||
"weekly" (filter (fn [article] (and (not (nil? (:published-date article))) (>= (:published-date article) weekly))) articles)
|
||||
:else articles)))
|
||||
|
||||
|
||||
(defn add-datetimes-formatter
|
||||
[articles]
|
||||
(map (fn [article]
|
||||
(assoc article :published-date-formatter (f/unparse date-custom-formatter (c/from-long (:published-date article))))) articles))
|
||||
|
||||
|
||||
(defn zip-feeds-in-articles
|
||||
[feeds]
|
||||
;; Flat all articles
|
||||
(reduce (fn [articles feed]
|
||||
;; Add in every article, all information from feed
|
||||
(concat articles (map (fn [article] (assoc article :feed (:feed (update-in feed [:feed] dissoc :entries)) )) (get-in feed [:feed :entries])))) [] feeds))
|
||||
|
||||
(concat articles (map (fn [article] (assoc article :feed (:feed (update-in feed [:feed] dissoc :entries)))) (get-in feed [:feed :entries])))) [] feeds))
|
||||
|
||||
(defn add-cover-article
|
||||
[articles]
|
||||
@@ -45,34 +40,30 @@
|
||||
;; Iterate every blog
|
||||
(map (fn [article]
|
||||
(let [url-article (second (re-find #"<img[^>]+src=\"([^\">]+)\"" (str (get-in article [:description :value]))))]
|
||||
(assoc article :cover (if (nil? url-article) (get-in article [:feed :image :url]) url-article)))
|
||||
) articles))
|
||||
|
||||
(assoc article :cover (if (nil? url-article) (get-in article [:feed :image :url]) url-article)))) articles))
|
||||
|
||||
(defn order-published
|
||||
[articles]
|
||||
(reverse (sort-by :published-date articles)))
|
||||
|
||||
|
||||
(defn get-articles
|
||||
[]
|
||||
;; Get all feeds from config -> feeds
|
||||
(->
|
||||
(reduce
|
||||
(fn [feeds feed-url]
|
||||
; Read feed
|
||||
(let [feed (parse-url feed-url {:insecure? true :throw-exceptions false})]
|
||||
; Check is not null
|
||||
(if (not (nil? feed))
|
||||
; Add feed
|
||||
(conj feeds feed)
|
||||
; Alert fail
|
||||
(prn (str "Error with '" feed-url) "'"))))
|
||||
[] (:feeds config))
|
||||
zip-feeds-in-articles
|
||||
datetimes-to-unixtime
|
||||
filter-edition
|
||||
order-published
|
||||
add-cover-article
|
||||
add-datetimes-formatter
|
||||
))
|
||||
(reduce
|
||||
(fn [feeds feed-url]
|
||||
; Read feed
|
||||
(let [feed (parse-url feed-url {:insecure? true :throw-exceptions false})]
|
||||
; Check is not null
|
||||
(if-not (nil? feed)
|
||||
; Add feed
|
||||
(conj feeds feed)
|
||||
; Alert fail
|
||||
(prn (str "Error with '" feed-url) "'"))))
|
||||
[] (:feeds config))
|
||||
zip-feeds-in-articles
|
||||
datetimes-to-unixtime
|
||||
filter-edition
|
||||
order-published
|
||||
add-cover-article
|
||||
add-datetimes-formatter))
|
||||
@@ -4,7 +4,6 @@
|
||||
[rsspaper.config :refer [config]]
|
||||
[selmer.parser :as s]))
|
||||
|
||||
|
||||
(defn make-html
|
||||
[articles]
|
||||
;; Render html in dist/index.html
|
||||
@@ -16,7 +15,5 @@
|
||||
(.mkdir (java.io.File. dir))
|
||||
;; Make dist/index.html
|
||||
(with-open [wrtr (io/writer path)]
|
||||
(.write wrtr (s/render-file (str "themes/" (:theme config) ".html") {
|
||||
:title (:title config)
|
||||
:articles articles
|
||||
})))))
|
||||
(.write wrtr (s/render-file (str "themes/" (:theme config) ".html") {:title (:title config)
|
||||
:articles articles})))))
|
||||
Reference in New Issue
Block a user