Skip to content

Instantly share code, notes, and snippets.

@gtrak
Last active August 29, 2015 14:01
Show Gist options
  • Save gtrak/4104bbe6577620262a85 to your computer and use it in GitHub Desktop.
Save gtrak/4104bbe6577620262a85 to your computer and use it in GitHub Desktop.
(defn parse-string
[s]
(h/as-hickory (h/parse s)))
(defn link
[entry]
(-> (s/select (s/tag "link")
entry)
first
:attrs
:href))
(defn title
[entry]
(-> (s/select (s/tag "title")
entry)
first
:content
first))
(defn summary
[entry]
(-> (s/select (s/tag "summary")
entry)
first
:content
first
string/trim))
(defn extract-items
[{:keys [summary] :as entry}]
(let [summary (->> (js/decodeURIComponent summary)
h/parse-fragment
(map h/as-hickory))]
(assoc entry
:items (reduce
(fn [acc [e1 e2]]
(if (= :br (:tag e1))
(conj acc (string/trim e2))
acc))
[]
(partition 2 1 summary)))))
(defn entries
[parsed]
(for [e (s/select (s/tag "entry") parsed)]
(-> {:link (link e))
:title (title e))
:summary (summary e))}
extract-items)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment