Handling of Atom relative & feed-self URLs

This commit is contained in:
Jaidyn Ann 2022-11-23 12:38:22 -06:00
parent fac63f9fe3
commit 56ce38a617

View File

@ -38,8 +38,8 @@
(updated-feed-string read-feed entries-since entry->string) (updated-feed-string read-feed entries-since entry->string)
(import scheme (import scheme
(chicken base) (chicken condition) (chicken io) (chicken port) (chicken base) (chicken condition) (chicken io) (chicken pathname) (chicken port)
srfi-1 srfi-19 srfi-69 srfi-1 srfi-13 srfi-19 srfi-69
date-strings date-strings
feedsnake-helpers feedsnake-helpers
http-client http-client
@ -130,7 +130,7 @@
;; Parse an atom feed into a feedsnake-friendly alist ;; Parse an atom feed into a feedsnake-friendly alist
(define (atom-doc->feedsnake-feed atom) (define (atom-doc->feedsnake-feed atom)
`((title ,(last (feed-title atom))) `((title ,(last (feed-title atom)))
(urls ,(feed-links atom)) (url ,(atom-feed-preferred-url atom))
(authors ,(map author-name (feed-authors atom))) (authors ,(map author-name (feed-authors atom)))
(updated ,(feed-updated atom)) (updated ,(feed-updated atom))
(entry-updated ,(atom-feed-latest-entry-date atom)) (entry-updated ,(atom-feed-latest-entry-date atom))
@ -140,6 +140,7 @@
(feed-entries atom))))) (feed-entries atom)))))
;; Parse an atom entry into a feedsnake entry :> ;; Parse an atom entry into a feedsnake entry :>
(define (atom-entry->feedsnake-entry entry atom) (define (atom-entry->feedsnake-entry entry atom)
(let ([published (rfc339-string->date (entry-published entry))] (let ([published (rfc339-string->date (entry-published entry))]
@ -150,11 +151,21 @@
(updated ,(or updated published)) (updated ,(or updated published))
(published ,(or published updated)) (published ,(or published updated))
(summary ,(last (entry-summary entry))) (summary ,(last (entry-summary entry)))
(urls ,(map link-uri (entry-links entry))) (urls ,(map (lambda (link) (atom-link->string link atom))
(entry-links entry)))
(authors ,(if (null? entry-authors) feed-authors entry-authors)) (authors ,(if (null? entry-authors) feed-authors entry-authors))
(feed-title ,(feed-title atom))))) (feed-title ,(feed-title atom)))))
;; The preferred/given URL for an atom feed
(define (atom-feed-preferred-url atom)
(car
(filter
(lambda (link)
(string=? (link-relation link) "self"))
(feed-links atom))))
;; Get an atom feed's latest date for an entry's updating/publishing ;; Get an atom feed's latest date for an entry's updating/publishing
(define (atom-feed-latest-entry-date atom) (define (atom-feed-latest-entry-date atom)
(let ([entry-date (let ([entry-date
@ -168,6 +179,15 @@
(map entry-date (feed-entries atom))))) (map entry-date (feed-entries atom)))))
;; Convert an atom-link into a proper, valid url
(define (atom-link->string link atom)
(if (string-contains (link-uri link) "://")
(link-uri link)
(string-append (pathname-directory (atom-feed-preferred-url atom))
"/"
(link-uri link))))
;; Download a file over HTTP to the given port. ;; Download a file over HTTP to the given port.
(define (fetch-http url out-port) (define (fetch-http url out-port)
(call-with-input-request (call-with-input-request