on master help sign in
Documentation++, added copyValue function.
commit89d6cb26bb946c4b186f05f24c819fb5568431e3 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 6 Mar 2010, 18:11 (17 years ago) parent1736710
4 files changed+32−13
data/templates/rss.xml+1−1 src/Text/Hakyll/Context.hs+9−2 src/Text/Hakyll/RenderAction.hs+1 src/Text/Hakyll/Rss.hs+21−10
data/templates/rss.xml+1−1
@@ -1,4 +1,4 @@
1−<?xml version="1.0" ?>
1+<?xml version="1.0" encoding="utf8"?>
22<rss version="2.0">
33 <channel>
44 <title>$title</title>
src/Text/Hakyll/Context.hs+9−2
@@ -4,6 +4,7 @@ module Text.Hakyll.Context
44 , ContextManipulation
55 , renderValue
66 , changeValue
7+ , copyValue
78 , renderDate
89 , changeExtension
910 ) where
@@ -31,9 +32,9 @@ renderValue :: String -- ^ Key of which the value should be copied.
3132 -> String -- ^ Key the value should be copied to.
3233 -> (String -> String) -- ^ Function to apply on the value.
3334 -> ContextManipulation
34−renderValue src dst f context = case M.lookup src context of
35+renderValue source destination f context = case M.lookup source context of
3536 Nothing -> context
36− (Just value) -> M.insert dst (f value) context
37+ (Just value) -> M.insert destination (f value) context
3738
3839-- | Change a value in a @Context@.
3940--
@@ -46,6 +47,12 @@ changeValue :: String -- ^ Key to change.
4647 -> ContextManipulation
4748changeValue key = renderValue key key
4849
50+-- | Copy a value from one key to another in a @Context@.
51+copyValue :: String -- ^ Source key.
52+ -> String -- ^ Destination key.
53+ -> ContextManipulation
54+copyValue source destination = renderValue source destination id
55+
4956-- | When the context has a key called @path@ in a @yyyy-mm-dd-title.extension@
5057-- format (default for pages), this function can render the date.
5158--
src/Text/Hakyll/RenderAction.hs+1
@@ -1,3 +1,4 @@
1+-- | This is the module which exports @RenderAction@.
12module Text.Hakyll.RenderAction
23 ( RenderAction (..)
34 , createRenderAction
src/Text/Hakyll/Rss.hs+21−10
@@ -1,4 +1,6 @@
1−-- | A Module that allows easy rendering of RSS feeds.
1+-- | A Module that allows easy rendering of RSS feeds. If you use this module,
2+-- you must make sure you set the `absoluteUrl` field in the main Hakyll
3+-- configuration.
24module Text.Hakyll.Rss
35 ( RssConfiguration (..)
46 , renderRss
@@ -16,6 +18,7 @@ import Text.Hakyll.RenderAction (Renderable)
1618
1719import Paths_hakyll
1820
21+-- | This is a data structure to keep the configuration of an RSS feed.
1922data RssConfiguration = RssConfiguration
2023 { -- | Url of the RSS feed (relative to site root). For example, @rss.xml@.
2124 rssUrl :: String
@@ -25,11 +28,13 @@ data RssConfiguration = RssConfiguration
2528 rssDescription :: String
2629 }
2730
28−createRssWith :: ContextManipulation
29− -> RssConfiguration
30− -> [Renderable]
31− -> FilePath
32− -> FilePath
31+-- | This is an auxiliary function to create a listing that is, in fact, an RSS
32+-- feed.
33+createRssWith :: ContextManipulation -- ^ Manipulation to apply on the items.
34+ -> RssConfiguration -- ^ Feed configuration.
35+ -> [Renderable] -- ^ Items to include.
36+ -> FilePath -- ^ RSS feed template.
37+ -> FilePath -- ^ RSS item template.
3338 -> Renderable
3439createRssWith manipulation configuration renderables template itemTemplate =
3540 listing >>> render template
@@ -42,12 +47,18 @@ createRssWith manipulation configuration renderables template itemTemplate =
4247 , ("description", rssDescription)
4348 ]
4449
45−renderRss :: RssConfiguration -> [Renderable] -> Hakyll ()
50+-- | Render an RSS feed with a number of items.
51+renderRss :: RssConfiguration -- ^ Feed configuration.
52+ -> [Renderable] -- ^ Items to include in the feed.
53+ -> Hakyll ()
4654renderRss = renderRssWith id
4755
48−renderRssWith :: ContextManipulation
49− -> RssConfiguration
50− -> [Renderable]
56+-- | Render an RSS feed with a number of items. This function allows you to
57+-- specify a @ContextManipulation@ which will be applied on every
58+-- @Renderable@.
59+renderRssWith :: ContextManipulation -- ^ Manipulation to apply on the items.
60+ -> RssConfiguration -- ^ Feed configuration.
61+ -> [Renderable] -- ^ Items to include in the feed.
5162 -> Hakyll ()
5263renderRssWith manipulation configuration renderables = do
5364 template <- liftIO $ getDataFileName "templates/rss.xml"