summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Rss.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-06 15:39:45 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-06 15:39:45 +0100
commit1736710b9e0685f3c3503519e38e9744ba9bb144 (patch)
tree1c79256afb9840a4ba7ce28aaeae41939f3615e6 /src/Text/Hakyll/Rss.hs
parentf47fd1a967bb54fb09472287bcb97306979a88b1 (diff)
downloadhakyll-1736710b9e0685f3c3503519e38e9744ba9bb144.tar.gz
Added RSS module.
Diffstat (limited to 'src/Text/Hakyll/Rss.hs')
-rw-r--r--src/Text/Hakyll/Rss.hs57
1 files changed, 57 insertions, 0 deletions
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'