From c6fcb2f39d31261d99d97f2ff093180cf7512af5 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 7 Jan 2012 12:57:28 +0100 Subject: Include atom:updated in Atom feeds Closes gh-49 --- data/templates/atom-item.xml | 3 ++- data/templates/atom.xml | 2 +- data/templates/rss-item.xml | 2 +- data/templates/rss.xml | 2 +- src/Hakyll/Web/Feed.hs | 24 +++++++++++++++--------- 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$ $root$$url$ - $timestamp$ + $published$ + $updated$ 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 @@ $authorName$ - $timestamp$ + $updated$ $body$ 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$ $root$$url$ - $timestamp$ + $published$ $root$$url$ 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 @@ - $timestamp$ + $updated$ $body$ 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 -- cgit v1.2.3