fixed bookmarks; announcements broke it

for now just skip irregular links
This commit is contained in:
rdiedrich 2020-06-29 12:24:15 +02:00
parent 41649d47c9
commit d51647c671

View File

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