@@ -20,9 +20,7 @@
20module Text.Hakyll.Feed
20module Text.Hakyll.Feed
21 ( FeedConfiguration (..)
21 ( FeedConfiguration (..)
22 , renderRss
22 , renderRss
24 , renderAtom
23 , renderAtom
28import Control.Arrow ((>>>), second)
26import Control.Arrow ((>>>), second)
@@ -31,9 +29,9 @@ import Data.Maybe (fromMaybe)
31import qualified Data.Map as M
29import qualified Data.Map as M
33import Text.Hakyll.Context (ContextManipulation, renderDate)
31import Text.Hakyll.Context (ContextManipulation, renderDate)
34−import Text.Hakyll.Hakyll (Hakyll)
32+import Text.Hakyll.Hakyll (Hakyll, Context)
35import Text.Hakyll.Render (render, renderChain)
33import Text.Hakyll.Render (render, renderChain)
36−import Text.Hakyll.Renderables (createListingWith)
34+import Text.Hakyll.Renderables (createListing)
37import Text.Hakyll.HakyllAction
35import Text.Hakyll.HakyllAction
39import Paths_hakyll
37import Paths_hakyll
@@ -52,17 +50,16 @@ data FeedConfiguration = FeedConfiguration
53-- | This is an auxiliary function to create a listing that is, in fact, a feed.
51-- | This is an auxiliary function to create a listing that is, in fact, a feed.
54-- The items should be sorted on date.
52-- The items should be sorted on date.
55−createFeedWith :: ContextManipulation -- ^ Manipulation to apply on the items.
56− -> FeedConfiguration -- ^ Feed configuration.
53+createFeed :: FeedConfiguration -- ^ Feed configuration.
57− -> [Renderable] -- ^ Items to include.
54+ -> [HakyllAction () Context] -- ^ Items to include.
58− -> FilePath -- ^ Feed template.
55+ -> FilePath -- ^ Feed template.
59− -> FilePath -- ^ Item template.
56+ -> FilePath -- ^ Item template.
60− -> Renderable
57+ -> HakyllAction () Context
61−createFeedWith manipulation configuration renderables template itemTemplate =
58+createFeed configuration renderables template itemTemplate =
62 listing >>> render template
59 listing >>> render template
64− listing = createListingWith manipulation (feedUrl configuration)
61+ listing = createListing (feedUrl configuration)
65− [itemTemplate] renderables additional
62+ [itemTemplate] renderables additional
67 additional = map (second $ Left . ($ configuration))
64 additional = map (second $ Left . ($ configuration))
68 [ ("title", feedTitle)
65 [ ("title", feedTitle)
@@ -73,68 +70,41 @@ createFeedWith manipulation configuration renderables template itemTemplate =
73 -- Take the first timestamp, which should be the most recent.
70 -- Take the first timestamp, which should be the most recent.
74 updated = let action = createHakyllAction $
71 updated = let action = createHakyllAction $
75 return . fromMaybe "foo" . M.lookup "timestamp"
72 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)
78 in map toTuple $ take 1 renderables
74 in map toTuple $ take 1 renderables
81-- | Abstract function to render any feed.
77-- | Abstract function to render any feed.
82−renderFeedWith :: ContextManipulation -- ^ Manipulation to apply on the items.
83− -> FeedConfiguration -- ^ Feed configuration.
78+renderFeed :: FeedConfiguration -- ^ Feed configuration.
84− -> [Renderable] -- ^ Items to include in the feed.
79+ -> [HakyllAction () Context] -- ^ Items to include in the feed.
85− -> FilePath -- ^ Feed template.
80+ -> FilePath -- ^ Feed template.
86− -> FilePath -- ^ Item template.
81+ -> FilePath -- ^ Item template.
87− -> Hakyll ()
82+ -> Hakyll ()
88−renderFeedWith manipulation configuration renderables template itemTemplate = do
83+renderFeed configuration renderables template itemTemplate = do
89 template' <- liftIO $ getDataFileName template
84 template' <- liftIO $ getDataFileName template
90 itemTemplate' <- liftIO $ getDataFileName itemTemplate
85 itemTemplate' <- liftIO $ getDataFileName itemTemplate
91− let renderFeedWith' = createFeedWith manipulation configuration
86+ let renderFeed' = createFeed configuration renderables
92− renderables template' itemTemplate'
87+ template' itemTemplate'
93− renderChain [] renderFeedWith'
88+ renderChain [] renderFeed'
95-- | Render an RSS feed with a number of items.
90-- | Render an RSS feed with a number of items.
96−renderRss :: FeedConfiguration -- ^ Feed configuration.
91+renderRss :: FeedConfiguration -- ^ Feed configuration.
97− -> [Renderable] -- ^ Items to include in the RSS feed.
92+ -> [HakyllAction () Context] -- ^ Items to include in the feed.
98 -> Hakyll ()
93 -> Hakyll ()
99−renderRss = renderRssWith id
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.
109−renderRssWith manipulation configuration renderables =
94+renderRss configuration renderables =
110− renderFeedWith manipulation' configuration renderables
95+ renderFeed configuration (map (>>> renderRssDate) renderables)
111− "templates/rss.xml" "templates/rss-item.xml"
96+ "templates/rss.xml" "templates/rss-item.xml"
113− manipulation' = manipulation . renderRssDate
115−-- | @ContextManipulation@ that renders a date to RSS format.
116−renderRssDate :: ContextManipulation
117−renderRssDate = renderDate "timestamp" "%a, %d %b %Y %H:%M:%S UT"
98+ renderRssDate = renderDate "timestamp" "%a, %d %b %Y %H:%M:%S UT"
118− "No date found."
99+ "No date found."
120-- | Render an Atom feed with a number of items.
101-- | Render an Atom feed with a number of items.
121−renderAtom :: FeedConfiguration
102+renderAtom :: FeedConfiguration -- ^ Feed configuration.
122− -> [Renderable]
103+ -> [HakyllAction () Context] -- ^ Items to include in the feed.
123 -> Hakyll ()
104 -> Hakyll ()
124−renderAtom = renderAtomWith id
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.
132−renderAtomWith manipulation configuration renderables =
105+renderAtom configuration renderables =
133− renderFeedWith manipulation' configuration renderables
106+ renderFeed configuration (map (>>> renderAtomDate) renderables)
134− "templates/atom.xml" "templates/atom-item.xml"
107+ "templates/atom.xml" "templates/atom-item.xml"
136− manipulation' = manipulation . renderAtomDate
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"