From 1736710b9e0685f3c3503519e38e9744ba9bb144 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 6 Mar 2010 15:39:45 +0100 Subject: Added RSS module. --- src/Text/Hakyll/Rss.hs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/Text/Hakyll/Rss.hs (limited to 'src/Text/Hakyll/Rss.hs') diff --git a/src/Text/Hakyll/Rss.hs b/src/Text/Hakyll/Rss.hs new file mode 100644 index 0000000..d3e5be2 --- /dev/null +++ b/src/Text/Hakyll/Rss.hs @@ -0,0 +1,57 @@ +-- | A Module that allows easy rendering of RSS feeds. +module Text.Hakyll.Rss + ( RssConfiguration (..) + , renderRss + , renderRssWith + ) where + +import Control.Arrow ((>>>), second) +import Control.Monad.Reader (liftIO) + +import Text.Hakyll.Context (ContextManipulation) +import Text.Hakyll.Hakyll (Hakyll) +import Text.Hakyll.Render (render, renderChain) +import Text.Hakyll.Renderables (createListingWith) +import Text.Hakyll.RenderAction (Renderable) + +import Paths_hakyll + +data RssConfiguration = RssConfiguration + { -- | Url of the RSS feed (relative to site root). For example, @rss.xml@. + rssUrl :: String + , -- | Title of the RSS feed. + rssTitle :: String + , -- | Description of the RSS feed. + rssDescription :: String + } + +createRssWith :: ContextManipulation + -> RssConfiguration + -> [Renderable] + -> FilePath + -> FilePath + -> Renderable +createRssWith manipulation configuration renderables template itemTemplate = + listing >>> render template + where + listing = createListingWith manipulation (rssUrl configuration) itemTemplate + renderables additional + + additional = map (second $ Left . ($ configuration)) + [ ("title", rssTitle) + , ("description", rssDescription) + ] + +renderRss :: RssConfiguration -> [Renderable] -> Hakyll () +renderRss = renderRssWith id + +renderRssWith :: ContextManipulation + -> RssConfiguration + -> [Renderable] + -> Hakyll () +renderRssWith manipulation configuration renderables = do + template <- liftIO $ getDataFileName "templates/rss.xml" + itemTemplate <- liftIO $ getDataFileName "templates/rss-item.xml" + let renderRssWith' = createRssWith manipulation configuration + renderables template itemTemplate + renderChain [] renderRssWith' -- cgit v1.2.3