on master help sign in
Include atom:updated in Atom feeds
c6fcb2fJasper Van der Jeugt
data/templates/atom-item.xml+2−1
@@ -2,6 +2,7 @@
2 <title>$title$</title>
2 <title>$title$</title>
3 <link href="$root$$url$" />
3 <link href="$root$$url$" />
4 <id>$root$$url$</id>
4 <id>$root$$url$</id>
5− <published>$timestamp$</published>
5+ <published>$published$</published>
6+ <updated>$updated$</updated>
6 <summary type="html"><![CDATA[$description$]]></summary>
7 <summary type="html"><![CDATA[$description$]]></summary>
7</entry>
8</entry>
data/templates/atom.xml+1−1
@@ -7,6 +7,6 @@
7 <author>
7 <author>
8 <name>$authorName$</name>
8 <name>$authorName$</name>
9 </author>
9 </author>
10− <updated>$timestamp$</updated>
10+ <updated>$updated$</updated>
11 $body$
11 $body$
12</feed>
12</feed>
data/templates/rss-item.xml+1−1
@@ -2,6 +2,6 @@
2 <title>$title$</title>
2 <title>$title$</title>
3 <link>$root$$url$</link>
3 <link>$root$$url$</link>
4 <description><![CDATA[$description$]]></description>
4 <description><![CDATA[$description$]]></description>
5− <pubDate>$timestamp$</pubDate>
5+ <pubDate>$published$</pubDate>
6 <guid>$root$$url$</guid>
6 <guid>$root$$url$</guid>
7</item>
7</item>
data/templates/rss.xml+1−1
@@ -6,7 +6,7 @@
6 <description><![CDATA[$description$]]></description>
6 <description><![CDATA[$description$]]></description>
7 <atom:link href="$root$$url$" rel="self"
7 <atom:link href="$root$$url$" rel="self"
8 type="application/rss+xml" />
8 type="application/rss+xml" />
9− <lastBuildDate>$timestamp$</lastBuildDate>
9+ <lastBuildDate>$updated$</lastBuildDate>
10 $body$
10 $body$
11 </channel>
11 </channel>
12</rss>
12</rss>
src/Hakyll/Web/Feed.hs+15−9
@@ -50,7 +50,8 @@ data FeedConfiguration = FeedConfiguration
50 } deriving (Show, Eq)
50 } deriving (Show, Eq)
51
51
52-- | This is an auxiliary function to create a listing that is, in fact, a feed.
52-- | This is an auxiliary function to create a listing that is, in fact, a feed.
53−-- The items should be sorted on date. The @$timestamp@ field should be set.
53+-- The items should be sorted on date. The @$updated@ field should be set for
54+-- each item.
54--
55--
55createFeed :: Template -- ^ Feed template
56createFeed :: Template -- ^ Feed template
56 -> Template -- ^ Item template
57 -> Template -- ^ Item template
@@ -60,7 +61,7 @@ createFeed :: Template -- ^ Feed template
60 -> String -- ^ Resulting feed
61 -> String -- ^ Resulting feed
61createFeed feedTemplate itemTemplate url configuration items =
62createFeed feedTemplate itemTemplate url configuration items =
62 pageBody $ applyTemplate feedTemplate
63 pageBody $ applyTemplate feedTemplate
63− $ trySetField "timestamp" timestamp
64+ $ trySetField "updated" updated
64 $ trySetField "title" (feedTitle configuration)
65 $ trySetField "title" (feedTitle configuration)
65 $ trySetField "description" (feedDescription configuration)
66 $ trySetField "description" (feedDescription configuration)
66 $ trySetField "authorName" (feedDescription configuration)
67 $ trySetField "authorName" (feedDescription configuration)
@@ -75,10 +76,10 @@ createFeed feedTemplate itemTemplate url configuration items =
75 -- Body: concatenated items
76 -- Body: concatenated items
76 body = concat $ map pageBody items'
77 body = concat $ map pageBody items'
77
78
78− -- Take the first timestamp, which should be the most recent
79+ -- Take the first updated, which should be the most recent
79− timestamp = fromMaybe "Unknown" $ do
80+ updated = fromMaybe "Unknown" $ do
80 p <- listToMaybe items
81 p <- listToMaybe items
81− return $ getField "timestamp" p
82+ return $ getField "updated" p
82
83
83
84
84-- | Abstract function to render any feed.
85-- | Abstract function to render any feed.
@@ -107,18 +108,23 @@ renderFeed feedTemplate itemTemplate configuration =
107--
108--
108renderRss :: FeedConfiguration -- ^ Feed configuration
109renderRss :: FeedConfiguration -- ^ Feed configuration
109 -> Compiler [Page String] String -- ^ Feed compiler
110 -> Compiler [Page String] String -- ^ Feed compiler
110−renderRss configuration = arr (map renderDate)
111+renderRss configuration = arr (map (addUpdated . renderDate))
111 >>> renderFeed "templates/rss.xml" "templates/rss-item.xml" configuration
112 >>> renderFeed "templates/rss.xml" "templates/rss-item.xml" configuration
112 where
113 where
113− renderDate = renderDateField "timestamp" "%a, %d %b %Y %H:%M:%S UT"
114+ renderDate = renderDateField "published" "%a, %d %b %Y %H:%M:%S UT"
114 "No date found."
115 "No date found."
115
116
116-- | Render an Atom feed with a number of items.
117-- | Render an Atom feed with a number of items.
117--
118--
118renderAtom :: FeedConfiguration -- ^ Feed configuration
119renderAtom :: FeedConfiguration -- ^ Feed configuration
119 -> Compiler [Page String] String -- ^ Feed compiler
120 -> Compiler [Page String] String -- ^ Feed compiler
120−renderAtom configuration = arr (map renderDate)
121+renderAtom configuration = arr (map (addUpdated . renderDate))
121 >>> renderFeed "templates/atom.xml" "templates/atom-item.xml" configuration
122 >>> renderFeed "templates/atom.xml" "templates/atom-item.xml" configuration
122 where
123 where
123− renderDate = renderDateField "timestamp" "%Y-%m-%dT%H:%M:%SZ"
124+ renderDate = renderDateField "published" "%Y-%m-%dT%H:%M:%SZ"
124 "No date found."
125 "No date found."
126+
127+-- | Copies @$updated$@ from @$published$@ if it is not already set.
128+--
129+addUpdated :: Page a -> Page a
130+addUpdated page = trySetField "updated" (getField "published" page) page