Last active
August 29, 2015 14:01
-
-
Save gtrak/4104bbe6577620262a85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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