This commit is contained in:
Andros Fenollosa
2021-07-02 21:29:55 +02:00
parent 34e59753cb
commit e34e09eccd
5 changed files with 51 additions and 51 deletions

View File

@@ -1,10 +1,10 @@
(ns rsspaper.core
(:require
[rsspaper.feeds :refer [get-feeds]]
[rsspaper.feeds :refer [get-articles]]
[rsspaper.html :refer [make-html]]) (:gen-class))
(defn -main [& args]
;; Main
(prn "Reading feeds... Please be patient.")
(make-html (get-feeds))
(make-html (get-articles))
(prn "Generated \uD83D\uDCF0 in 'dist/index.html'!"))

View File

@@ -8,32 +8,44 @@
(def date-custom-formatter (f/formatter "dd MM yyyy"))
(defn datetimes-to-unixtime
[data]
(map (fn [blog]
(assoc-in blog [:feed :entries]
(map (fn [article]
(assoc article :published-date (c/to-long (:published-date article))))
(get-in blog [:feed :entries])))) data))
[articles]
(map (fn [article]
(assoc article :published-date (c/to-long (:published-date article)))) articles))
(defn add-datetimes-formatter
[data]
(map (fn [blog]
(assoc-in blog [:feed :entries]
(map (fn [article]
(assoc article :published-date-formatter (f/unparse date-custom-formatter (c/from-long (:published-date article)))))
(get-in blog [:feed :entries])))) data))
[articles]
(map (fn [article]
(assoc article :published-date-formatter (f/unparse date-custom-formatter (c/from-long (:published-date article))))) articles))
(defn get-feeds
(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))
(defn add-cover-article
[articles]
;; Add cover to article search first image in description
;; Iterate every blog
(map (fn [article]
(assoc article :cover (second (re-find #"<img[^>]+src=\"([^\">]+)\"" (str (get-in article [:description :value])))))
) articles))
(defn get-articles
[]
;; Get all feeds from config -> feeds
(->
(reverse (sort-by :published-date (->
(reduce
(fn [feeds feed-url]
(conj feeds
(parse-url feed-url {:insecure? true :throw-exceptions false}))
) [] (:feeds config))
zip-feeds-in-articles
add-cover-article
datetimes-to-unixtime
add-datetimes-formatter))
add-datetimes-formatter))))

View File

@@ -4,21 +4,9 @@
[rsspaper.config :refer [config]]
[selmer.parser :as s]))
(defn add-cover-article
[data]
;; Add cover to article search first image in description
;; Iterate every blog
(map (fn [blog]
;; Replace entries
(assoc-in blog [:feed :entries]
;; New entries with add cover
(map (fn [article]
(assoc article :cover (second (re-find #"<img[^>]+src=\"([^\">]+)\"" (str (get-in article [:description :value]))))))
(get-in blog [:feed :entries])) )
) data))
(defn make-html
[data]
[articles]
;; Render html in dist/index.html
(let [dir "dist"
path (str dir "/index.html")]
@@ -30,5 +18,5 @@
(with-open [wrtr (io/writer path)]
(.write wrtr (s/render-file (str "themes/" (:theme config) ".html") {
:title (:title config)
:data (add-cover-article data)
:articles articles
})))))