summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/atom-item.xml3
-rw-r--r--data/templates/atom.xml2
-rw-r--r--data/templates/rss-item.xml2
-rw-r--r--data/templates/rss.xml2
-rw-r--r--src/Hakyll/Web/Feed.hs24
5 files changed, 20 insertions, 13 deletions
diff --git a/data/templates/atom-item.xml b/data/templates/atom-item.xml
index 4f5aeaf..ab26432 100644
--- a/data/templates/atom-item.xml
+++ b/data/templates/atom-item.xml
@@ -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>
diff --git a/data/templates/atom.xml b/data/templates/atom.xml
index 5a7c0cf..4a4eaaf 100644
--- a/data/templates/atom.xml
+++ b/data/templates/atom.xml
@@ -7,6 +7,6 @@
<author>
<name>$authorName$</name>
</author>
- <updated>$timestamp$</updated>
+ <updated>$updated$</updated>
$body$
</feed>
diff --git a/data/templates/rss-item.xml b/data/templates/rss-item.xml
index f8f9fcf..70126ac 100644
--- a/data/templates/rss-item.xml
+++ b/data/templates/rss-item.xml
@@ -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>
diff --git a/data/templates/rss.xml b/data/templates/rss.xml
index d2f3915..c6f3b08 100644
--- a/data/templates/rss.xml
+++ b/data/templates/rss.xml
@@ -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>
diff --git a/src/Hakyll/Web/Feed.hs b/src/Hakyll/Web/Feed.hs
index cd71029..77c97d3 100644
--- a/src/Hakyll/Web/Feed.hs
+++ b/src/Hakyll/Web/Feed.hs
@@ -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