Skip to content

Commit 87fe586

Browse files
committed
Fix parse description method
Fixed #5 Signed-off-by: Yen-Chin Lee <[email protected]>
1 parent d7d478e commit 87fe586

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

project.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
[migratus "0.8.13"]
1717
[environ "1.0.2"]
1818
[im.chit/hara.io.scheduler "2.2.17"]
19-
[im.chit/hara.time.joda "2.2.17"]]
19+
[im.chit/hara.time.joda "2.2.17"]
20+
[enlive "1.1.6"]]
2021

2122
:plugins [[migratus-lein "0.2.6"]]
2223

src/clojuretwbot/feed.clj

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns clojuretwbot.feed
22
(:require [clj-http.client :as http]
3+
[net.cgrand.enlive-html :as html]
34
[taoensso.timbre :as timbre]
45
[feedparser-clj.core :as feedparser]
56
[clojure.string :as str]
@@ -17,12 +18,21 @@
1718
(catch Exception e
1819
(timbre/warn (.getMessage e)))))
1920

21+
(defn- parse-meta
22+
"Parse HTML content's metadata."
23+
[html property]
24+
(-> html
25+
(java.io.StringReader.)
26+
(html/html-resource)
27+
(html/select [[:meta (html/attr= :property property)]])
28+
(first)
29+
(get-in [:attrs :content])))
30+
2031
(defn- parse-description
2132
"Parse feed's og:description info, set :description to nil if not exist."
2233
[info]
2334
(let [html (or (fetch-html (:link info)) "")
24-
description (-> (re-find #"(<meta\s*property=\"og:description\"\s*content=\")(.*)(\">)" html)
25-
(nth 2))]
35+
description (parse-meta html "og:description")]
2636
(merge info {:description description})))
2737

2838
(defn- parse-feed

0 commit comments

Comments
 (0)