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

@ -238,25 +238,23 @@
<hr class="separator">
</header>
<main class="main">
{% for item in data %}
{% for article in item.feed.entries %}
<article class="feed__article article">
<header class="article__header">
{% if article.cover %}
<p class="article__header-img">
<img src="{{ article.cover }}" alt="{{ article.title }}">
</p>
{% endif %}
<div class="article__titles">
<h1 class="article__title">{{ article.title }}</h1>
<h2 class="article__feed">{{ item.feed.title }} <span class="article__date">{{ article.published-date-formatter }}</span></h2>
</div>
</header>
<main class="container article__main">
{{ article.description.value|safe }}
</main>
</article>
{% endfor %}
{% for article in articles %}
<article class="feed__article article">
<header class="article__header">
{% if article.cover %}
<p class="article__header-img">
<img src="{{ article.cover }}" alt="{{ article.title }}">
</p>
{% endif %}
<div class="article__titles">
<h1 class="article__title">{{ article.title }}</h1>
<h2 class="article__feed">{{ article.feed.title }} <span class="article__date">{{ article.published-date-formatter }}</span></h2>
</div>
</header>
<main class="container article__main">
{{ article.description.value|safe }}
</main>
</article>
{% endfor %}
</main>
</div>

View File

@ -16,6 +16,7 @@
<orderEntry type="library" name="Leiningen: cheshire:5.9.0" level="project" />
<orderEntry type="library" name="Leiningen: clj-http:3.10.2" level="project" />
<orderEntry type="library" name="Leiningen: clj-rss:0.2.7" level="project" />
<orderEntry type="library" name="Leiningen: clj-time:0.15.2" level="project" />
<orderEntry type="library" name="Leiningen: clj-tuple:0.2.2" level="project" />
<orderEntry type="library" name="Leiningen: clj-yaml:0.4.0" level="project" />
<orderEntry type="library" name="Leiningen: clojure-complete:0.2.5" level="project" />
@ -28,6 +29,7 @@
<orderEntry type="library" name="Leiningen: commons-io:2.6" level="project" />
<orderEntry type="library" name="Leiningen: commons-logging:1.2" level="project" />
<orderEntry type="library" name="Leiningen: hiccup:1.0.5" level="project" />
<orderEntry type="library" name="Leiningen: joda-time:2.10" level="project" />
<orderEntry type="library" name="Leiningen: json-html:0.4.4" level="project" />
<orderEntry type="library" name="Leiningen: nrepl:0.6.0" level="project" />
<orderEntry type="library" name="Leiningen: org.apache.httpcomponents/httpasyncclient:4.1.4" level="project" />

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
})))))