@@ -20,9 +20,7 @@
2020module Text.Hakyll.Feed
2121 ( FeedConfiguration (..)
2222 , renderRss
23− , renderRssWith
2423 , renderAtom
25− , renderAtomWith
2624 ) where
2725
2826import Control.Arrow ((>>>), second)
@@ -31,9 +29,9 @@ import Data.Maybe (fromMaybe)
3129import qualified Data.Map as M
3230
3331import Text.Hakyll.Context (ContextManipulation, renderDate)
34−import Text.Hakyll.Hakyll (Hakyll)
32+import Text.Hakyll.Hakyll (Hakyll, Context)
3533import Text.Hakyll.Render (render, renderChain)
36−import Text.Hakyll.Renderables (createListingWith)
34+import Text.Hakyll.Renderables (createListing)
3735import Text.Hakyll.HakyllAction
3836
3937import Paths_hakyll
@@ -52,17 +50,16 @@ data FeedConfiguration = FeedConfiguration
5250
5351-- | This is an auxiliary function to create a listing that is, in fact, a feed.
5452-- The items should be sorted on date.
55−createFeedWith :: ContextManipulation -- ^ Manipulation to apply on the items.
56− -> FeedConfiguration -- ^ Feed configuration.
57− -> [Renderable] -- ^ Items to include.
58− -> FilePath -- ^ Feed template.
59− -> FilePath -- ^ Item template.
60− -> Renderable
61−createFeedWith manipulation configuration renderables template itemTemplate =
53+createFeed :: FeedConfiguration -- ^ Feed configuration.
54+ -> [HakyllAction () Context] -- ^ Items to include.
55+ -> FilePath -- ^ Feed template.
56+ -> FilePath -- ^ Item template.
57+ -> HakyllAction () Context
58+createFeed configuration renderables template itemTemplate =
6259 listing >>> render template
6360 where
64− listing = createListingWith manipulation (feedUrl configuration)
65− [itemTemplate] renderables additional
61+ listing = createListing (feedUrl configuration)
62+ [itemTemplate] renderables additional
6663
6764 additional = map (second $ Left . ($ configuration))
6865 [ ("title", feedTitle)
@@ -73,68 +70,41 @@ createFeedWith manipulation configuration renderables template itemTemplate =
7370 -- Take the first timestamp, which should be the most recent.
7471 updated = let action = createHakyllAction $
7572 return . fromMaybe "foo" . M.lookup "timestamp"
76− manip = createManipulationAction manipulation
77− toTuple r = ("timestamp", Right $ r >>> manip >>> action)
73+ toTuple r = ("timestamp", Right $ r >>> action)
7874 in map toTuple $ take 1 renderables
7975
8076
8177-- | Abstract function to render any feed.
82−renderFeedWith :: ContextManipulation -- ^ Manipulation to apply on the items.
83− -> FeedConfiguration -- ^ Feed configuration.
84− -> [Renderable] -- ^ Items to include in the feed.
85− -> FilePath -- ^ Feed template.
86− -> FilePath -- ^ Item template.
87− -> Hakyll ()
88−renderFeedWith manipulation configuration renderables template itemTemplate = do
78+renderFeed :: FeedConfiguration -- ^ Feed configuration.
79+ -> [HakyllAction () Context] -- ^ Items to include in the feed.
80+ -> FilePath -- ^ Feed template.
81+ -> FilePath -- ^ Item template.
82+ -> Hakyll ()
83+renderFeed configuration renderables template itemTemplate = do
8984 template' <- liftIO $ getDataFileName template
9085 itemTemplate' <- liftIO $ getDataFileName itemTemplate
91− let renderFeedWith' = createFeedWith manipulation configuration
92− renderables template' itemTemplate'
93− renderChain [] renderFeedWith'
86+ let renderFeed' = createFeed configuration renderables
87+ template' itemTemplate'
88+ renderChain [] renderFeed'
9489
9590-- | Render an RSS feed with a number of items.
96−renderRss :: FeedConfiguration -- ^ Feed configuration.
97− -> [Renderable] -- ^ Items to include in the RSS feed.
91+renderRss :: FeedConfiguration -- ^ Feed configuration.
92+ -> [HakyllAction () Context] -- ^ Items to include in the feed.
9893 -> Hakyll ()
99−renderRss = renderRssWith id
100−
101−-- | Render an RSS feed with a number of items. This function allows you to
102−-- specify a @ContextManipulation@ which will be applied on every
103−-- @Renderable@. Note that the given @Renderable@s should be sorted so the
104−-- most recent one is first.
105−renderRssWith :: ContextManipulation -- ^ Manipulation to apply on the items.
106− -> FeedConfiguration -- ^ Feed configuration.
107− -> [Renderable] -- ^ Items to include in the feed.
108− -> Hakyll ()
109−renderRssWith manipulation configuration renderables =
110− renderFeedWith manipulation' configuration renderables
111− "templates/rss.xml" "templates/rss-item.xml"
94+renderRss configuration renderables =
95+ renderFeed configuration (map (>>> renderRssDate) renderables)
96+ "templates/rss.xml" "templates/rss-item.xml"
11297 where
113− manipulation' = manipulation . renderRssDate
114−
115−-- | @ContextManipulation@ that renders a date to RSS format.
116−renderRssDate :: ContextManipulation
117−renderRssDate = renderDate "timestamp" "%a, %d %b %Y %H:%M:%S UT"
118− "No date found."
98+ renderRssDate = renderDate "timestamp" "%a, %d %b %Y %H:%M:%S UT"
99+ "No date found."
119100
120101-- | Render an Atom feed with a number of items.
121−renderAtom :: FeedConfiguration
122− -> [Renderable]
102+renderAtom :: FeedConfiguration -- ^ Feed configuration.
103+ -> [HakyllAction () Context] -- ^ Items to include in the feed.
123104 -> Hakyll ()
124−renderAtom = renderAtomWith id
125−
126−-- | A version of @renderAtom@ that allows you to specify a manipulation to
127−-- apply on the @Renderable@s.
128−renderAtomWith :: ContextManipulation -- ^ Manipulation to apply on the items.
129− -> FeedConfiguration -- ^ Feed configuration.
130− -> [Renderable] -- ^ Items to include in the feed.
131− -> Hakyll ()
132−renderAtomWith manipulation configuration renderables =
133− renderFeedWith manipulation' configuration renderables
134− "templates/atom.xml" "templates/atom-item.xml"
105+renderAtom configuration renderables =
106+ renderFeed configuration (map (>>> renderAtomDate) renderables)
107+ "templates/atom.xml" "templates/atom-item.xml"
135108 where
136− manipulation' = manipulation . renderAtomDate
137−
138−-- | Render a date to Atom format.
139−renderAtomDate :: ContextManipulation
140−renderAtomDate = renderDate "timestamp" "%Y-%m-%dT%H:%M:%SZ" "No date found."
109+ renderAtomDate = renderDate "timestamp" "%Y-%m-%dT%H:%M:%SZ"
110+ "No date found."