diff --git a/src/clojsa/saparser.clj b/src/clojsa/saparser.clj index f1f3f80..83a58df 100644 --- a/src/clojsa/saparser.clj +++ b/src/clojsa/saparser.clj @@ -1,6 +1,5 @@ (ns clojsa.saparser - (:require [clojsa.saclient :refer [thread-url thread-response]] - [clojure.string :as string] + (:require [clojure.string :as string] [hickory.core :refer :all] [hickory.select :as s] [hickory.convert :refer [hickory-to-hiccup]])) @@ -36,10 +35,10 @@ (string/trim (last (hickory-to-hiccup pd)))) (defn hickory-div [class content] - {:type :element, - :attrs {:class class}, - :tag :div, - :content content}) + {:type :element + :attrs {:class class} + :tag :div + :content content}) (defn parse-pb [pb] (let [pb (-> pb :content)] @@ -71,10 +70,10 @@ htree)) (defn parse-row [htree] - (let [link (-> (s/select (s/descendant (s/class :info) (s/tag :a)) htree) first) - thread-id (re-find #"\d+$" (:href (:attrs link))) - title (-> link :content first string/trim)] - {:id thread-id :title title})) + (when-let [link (-> (s/select (s/descendant (s/class :info) (s/tag :a)) htree) first)] + (let [thread-id (re-find #"\d+$" (:href (:attrs link))) + title (-> link :content first string/trim)] + {:id thread-id :title title}))) (defn bookmarks-map [page doc] (let [htree (hickory-doc doc) @@ -85,5 +84,7 @@ :page page :page-count page-count :content - (for [row bookmarks-tree] - (parse-row row))})) + (for [row bookmarks-tree + :let [parsed-row (parse-row row)] + :when parsed-row] + parsed-row)}))