|
|
@@ -19,30 +19,29 @@
|
|
|
(nreverse (plump:get-elements-by-tag-name node tag)))
|
|
|
|
|
|
(defun url-parse (url)
|
|
|
- (plump:parse (flexi-streams:octets-to-string
|
|
|
- (drakma:http-request (http-default url) :force-binary t) :external-format :utf-8)))
|
|
|
-
|
|
|
-(defun find-rss-url (url)
|
|
|
+ (multiple-value-bind (body status headers uri stream)
|
|
|
+ (drakma:http-request (http-default url) :force-binary t)
|
|
|
+ (declare (ignore status headers stream))
|
|
|
+ (values
|
|
|
+ (plump:parse (flexi-streams:octets-to-string body :external-format :utf-8))
|
|
|
+ uri)))
|
|
|
+
|
|
|
+(defun find-rss-links (url)
|
|
|
(handler-case
|
|
|
- (multiple-value-bind (body status headers uri stream)
|
|
|
- (drakma:http-request (http-default url) :force-binary t)
|
|
|
- (declare (ignore status stream))
|
|
|
- (let ((root (plump:parse (flexi-streams:octets-to-string body :external-format :utf-8)))
|
|
|
- (content-type (aget :content-type headers)))
|
|
|
- (cond
|
|
|
- ((alexandria:starts-with-subseq "text/html" content-type)
|
|
|
- (loop for link in (get-by-tag root "link")
|
|
|
- when (string= "application/rss+xml" (plump:attribute link "type"))
|
|
|
- do (return (puri:render-uri
|
|
|
- (puri:merge-uris (puri:uri (plump:attribute link "href"))
|
|
|
- uri) nil))))
|
|
|
- ((string= "rss" (plump:tag-name (plump:first-element root)))
|
|
|
- (puri:render-uri uri nil)))))
|
|
|
+ (multiple-value-bind (root uri) (url-parse url)
|
|
|
+ (loop for link in (get-by-tag root "link")
|
|
|
+ when (string= "application/rss+xml" (plump:attribute link "type"))
|
|
|
+ collect (list (plump:attribute link "title")
|
|
|
+ (puri:render-uri
|
|
|
+ (puri:merge-uris
|
|
|
+ (puri:uri (plump:attribute link "href"))
|
|
|
+ uri) nil))))
|
|
|
(error (e) (log:error e))))
|
|
|
|
|
|
(defun build-feed (url)
|
|
|
(let ((root (url-parse url)))
|
|
|
- (make-feed :url url :title (child-text root "title"))))
|
|
|
+ (alexandria:when-let (rss (car (get-by-tag root "rss")))
|
|
|
+ (make-feed :url url :title (child-text rss "title")))))
|
|
|
|
|
|
(defun adjust-period (feed coeff)
|
|
|
"Adjust the period of feed based on whenever there were new items. With clamping"
|