atom: Add 'id' attribute to feed and entries.

This commit is contained in:
David Thompson 2019-06-28 08:28:40 -04:00
parent 794125e408
commit d92411f7c1
1 changed files with 46 additions and 35 deletions

View File

@ -35,6 +35,7 @@
#:use-module (haunt utils)
#:use-module (haunt html)
#:use-module (haunt serve mime-types)
#:use-module (web uri)
#:export (make-enclosure
enclosure?
enclosure-title
@ -137,16 +138,21 @@
(define* (post->atom-entry site post #:key (blog-prefix ""))
"Convert POST into an Atom <entry> XML node."
(let ((uri (uri->string
(build-uri (site-scheme site)
#:host (site-domain site)
#:path (string-append blog-prefix "/"
(site-post-slug site post)
".html")))))
`(entry
(title ,(post-ref post 'title))
(id ,uri)
(author
(name ,(post-ref post 'author))
,(let ((email (post-ref post 'email)))
(if email `(email ,email) '())))
(updated ,(date->string* (post-date post)))
(link (@ (href ,(string-append blog-prefix "/"
(site-post-slug site post) ".html"))
(rel "alternate")))
(link (@ (href ,uri) (rel "alternate")))
(summary (@ (type "html"))
,(sxml->html-string (post-sxml post)))
,@(map (lambda (enclosure)
@ -158,7 +164,7 @@
((key . value)
(list key value)))
(enclosure-extra enclosure)))))
(post-ref-all post 'enclosure))))
(post-ref-all post 'enclosure)))))
(define* (atom-feed #:key
(file-name "feed.xml")
@ -174,9 +180,14 @@ SUBTITLE: The feed subtitle
FILTER: The procedure called to manipulate the posts list before rendering
MAX-ENTRIES: The maximum number of posts to render in the feed"
(lambda (site posts)
(let ((uri (uri->string
(build-uri (site-scheme site)
#:host (site-domain site)
#:path (string-append "/" file-name)))))
(make-page file-name
`(feed (@ (xmlns "http://www.w3.org/2005/Atom"))
(title ,(site-title site))
(id ,uri)
(subtitle ,subtitle)
(updated ,(date->string* (current-date)))
(link (@ (href ,(string-append (site-domain site)
@ -186,7 +197,7 @@ MAX-ENTRIES: The maximum number of posts to render in the feed"
,@(map (cut post->atom-entry site <>
#:blog-prefix blog-prefix)
(take-up-to max-entries (filter posts))))
sxml->xml*)))
sxml->xml*))))
(define* (atom-feeds-by-tag #:key
(prefix "feeds/tags")