summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-01-07 12:57:28 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-01-07 12:59:51 +0100
commitc6fcb2f39d31261d99d97f2ff093180cf7512af5 (patch)
tree1c808055e39772c71d96b33a292edc34ea9f06e2 /src/Hakyll/Web
parentf2cb3a0038b1005eb8e2ba296b71985e7f36e06f (diff)
downloadhakyll-c6fcb2f39d31261d99d97f2ff093180cf7512af5.tar.gz
Include atom:updated in Atom feeds
Closes gh-49
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r--src/Hakyll/Web/Feed.hs24
1 files changed, 15 insertions, 9 deletions
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