Add cover

This commit is contained in:
Andros Fenollosa 2021-06-30 00:41:21 +02:00
parent 09aff8568f
commit 4b91adf208
4 changed files with 19 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ target/
/.lein-repl-history
/.nrepl-port
config.yaml
config.yaml

View File

@ -123,6 +123,9 @@
{% for article in item.feed.entries %}
<article class="feed__article article">
<header class="article__header">
<p>
<img src="{{ article.cover }}" alt="{{ article.title }}">
</p>
<h1 class="article__title">{{ article.title }}</h1>
<h2 class="article__feed">{{ item.feed.title }}</h2>
</header>

View File

@ -15,7 +15,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<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.6" level="project" />
<orderEntry type="library" name="Leiningen: clj-rss:0.2.7" 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" />

View File

@ -4,6 +4,19 @@
[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]
;; Render html in dist/index.html
@ -17,5 +30,5 @@
(with-open [wrtr (io/writer path)]
(.write wrtr (s/render-file (str "themes/" (:theme config) ".html") {
:title (:title config)
:data data
:data (add-cover-article data)
})))))