Include atom:updated in Atom feeds
Closes gh-49
This commit is contained in:
parent
f2cb3a0038
commit
c6fcb2f39d
5 changed files with 20 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
|||
<title>$title$</title>
|
||||
<link href="$root$$url$" />
|
||||
<id>$root$$url$</id>
|
||||
<published>$timestamp$</published>
|
||||
<published>$published$</published>
|
||||
<updated>$updated$</updated>
|
||||
<summary type="html"><![CDATA[$description$]]></summary>
|
||||
</entry>
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
<author>
|
||||
<name>$authorName$</name>
|
||||
</author>
|
||||
<updated>$timestamp$</updated>
|
||||
<updated>$updated$</updated>
|
||||
$body$
|
||||
</feed>
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
<title>$title$</title>
|
||||
<link>$root$$url$</link>
|
||||
<description><![CDATA[$description$]]></description>
|
||||
<pubDate>$timestamp$</pubDate>
|
||||
<pubDate>$published$</pubDate>
|
||||
<guid>$root$$url$</guid>
|
||||
</item>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<description><![CDATA[$description$]]></description>
|
||||
<atom:link href="$root$$url$" rel="self"
|
||||
type="application/rss+xml" />
|
||||
<lastBuildDate>$timestamp$</lastBuildDate>
|
||||
<lastBuildDate>$updated$</lastBuildDate>
|
||||
$body$
|
||||
</channel>
|
||||
</rss>
|
||||
|
|
|
@ -50,7 +50,8 @@ data FeedConfiguration = FeedConfiguration
|
|||
} deriving (Show, Eq)
|
||||
|
||||
-- | This is an auxiliary function to create a listing that is, in fact, a feed.
|
||||
-- The items should be sorted on date. The @$timestamp@ field should be set.
|
||||
-- The items should be sorted on date. The @$updated@ field should be set for
|
||||
-- each item.
|
||||
--
|
||||
createFeed :: Template -- ^ Feed template
|
||||
-> Template -- ^ Item template
|
||||
|
@ -60,7 +61,7 @@ createFeed :: Template -- ^ Feed template
|
|||
-> String -- ^ Resulting feed
|
||||
createFeed feedTemplate itemTemplate url configuration items =
|
||||
pageBody $ applyTemplate feedTemplate
|
||||
$ trySetField "timestamp" timestamp
|
||||
$ trySetField "updated" updated
|
||||
$ trySetField "title" (feedTitle configuration)
|
||||
$ trySetField "description" (feedDescription configuration)
|
||||
$ trySetField "authorName" (feedDescription configuration)
|
||||
|
@ -75,10 +76,10 @@ createFeed feedTemplate itemTemplate url configuration items =
|
|||
-- Body: concatenated items
|
||||
body = concat $ map pageBody items'
|
||||
|
||||
-- Take the first timestamp, which should be the most recent
|
||||
timestamp = fromMaybe "Unknown" $ do
|
||||
-- Take the first updated, which should be the most recent
|
||||
updated = fromMaybe "Unknown" $ do
|
||||
p <- listToMaybe items
|
||||
return $ getField "timestamp" p
|
||||
return $ getField "updated" p
|
||||
|
||||
|
||||
-- | Abstract function to render any feed.
|
||||
|
@ -107,18 +108,23 @@ renderFeed feedTemplate itemTemplate configuration =
|
|||
--
|
||||
renderRss :: FeedConfiguration -- ^ Feed configuration
|
||||
-> Compiler [Page String] String -- ^ Feed compiler
|
||||
renderRss configuration = arr (map renderDate)
|
||||
renderRss configuration = arr (map (addUpdated . renderDate))
|
||||
>>> renderFeed "templates/rss.xml" "templates/rss-item.xml" configuration
|
||||
where
|
||||
renderDate = renderDateField "timestamp" "%a, %d %b %Y %H:%M:%S UT"
|
||||
renderDate = renderDateField "published" "%a, %d %b %Y %H:%M:%S UT"
|
||||
"No date found."
|
||||
|
||||
-- | Render an Atom feed with a number of items.
|
||||
--
|
||||
renderAtom :: FeedConfiguration -- ^ Feed configuration
|
||||
-> Compiler [Page String] String -- ^ Feed compiler
|
||||
renderAtom configuration = arr (map renderDate)
|
||||
renderAtom configuration = arr (map (addUpdated . renderDate))
|
||||
>>> renderFeed "templates/atom.xml" "templates/atom-item.xml" configuration
|
||||
where
|
||||
renderDate = renderDateField "timestamp" "%Y-%m-%dT%H:%M:%SZ"
|
||||
renderDate = renderDateField "published" "%Y-%m-%dT%H:%M:%SZ"
|
||||
"No date found."
|
||||
|
||||
-- | Copies @$updated$@ from @$published$@ if it is not already set.
|
||||
--
|
||||
addUpdated :: Page a -> Page a
|
||||
addUpdated page = trySetField "updated" (getField "published" page) page
|
||||
|
|
Loading…
Reference in a new issue