on master help sign in
Removed xxxWith functions, they can be implemented more elegant using Arrows anyway.
23f9d1eJasper Van der Jeugt
src/Text/Hakyll/Context.hs+16−18
@@ -9,18 +9,17 @@ module Text.Hakyll.Context
9 , changeExtension
9 , changeExtension
10 ) where
10 ) where
11
11
12−import qualified Data.Map as M
12+import Control.Arrow (arr)
13−import Data.Map (Map)
14import System.Locale (defaultTimeLocale)
13import System.Locale (defaultTimeLocale)
15import System.FilePath (takeFileName, addExtension, dropExtension)
14import System.FilePath (takeFileName, addExtension, dropExtension)
16import Data.Time.Format (parseTime, formatTime)
15import Data.Time.Format (parseTime, formatTime)
17import Data.Time.Clock (UTCTime)
16import Data.Time.Clock (UTCTime)
18import Data.Maybe (fromMaybe)
17import Data.Maybe (fromMaybe)
18+import qualified Data.Map as M
19
19
20import Text.Hakyll.Regex (substituteRegex)
20import Text.Hakyll.Regex (substituteRegex)
21−
21+import Text.Hakyll.HakyllAction (HakyllAction)
22−-- | Type for a context.
22+import Text.Hakyll.Hakyll (Context)
23−type Context = Map String String
24
23
25-- | Type for context manipulating functions.
24-- | Type for context manipulating functions.
26type ContextManipulation = Context -> Context
25type ContextManipulation = Context -> Context
@@ -31,10 +30,11 @@ type ContextManipulation = Context -> Context
31renderValue :: String -- ^ Key of which the value should be copied.
30renderValue :: String -- ^ Key of which the value should be copied.
32 -> String -- ^ Key the value should be copied to.
31 -> String -- ^ Key the value should be copied to.
33 -> (String -> String) -- ^ Function to apply on the value.
32 -> (String -> String) -- ^ Function to apply on the value.
34− -> ContextManipulation
33+ -> HakyllAction Context Context
34+renderValue source destination f = arr $ \context ->
35−renderValue source destination f context = case M.lookup source context of
35+ case M.lookup source context of
36− Nothing -> context
36+ Nothing -> context
37− (Just value) -> M.insert destination (f value) context
37+ (Just value) -> M.insert destination (f value) context
38
38
39-- | Change a value in a @Context@.
39-- | Change a value in a @Context@.
40--
40--
@@ -44,13 +44,13 @@ renderValue source destination f context = case M.lookup source context of
44-- Will put the title in UPPERCASE.
44-- Will put the title in UPPERCASE.
45changeValue :: String -- ^ Key to change.
45changeValue :: String -- ^ Key to change.
46 -> (String -> String) -- ^ Function to apply on the value.
46 -> (String -> String) -- ^ Function to apply on the value.
47− -> ContextManipulation
47+ -> HakyllAction Context Context
48changeValue key = renderValue key key
48changeValue key = renderValue key key
49
49
50-- | Copy a value from one key to another in a @Context@.
50-- | Copy a value from one key to another in a @Context@.
51copyValue :: String -- ^ Source key.
51copyValue :: String -- ^ Source key.
52 -> String -- ^ Destination key.
52 -> String -- ^ Destination key.
53− -> ContextManipulation
53+ -> HakyllAction Context Context
54copyValue source destination = renderValue source destination id
54copyValue source destination = renderValue source destination id
55
55
56-- | When the context has a key called @path@ in a @yyyy-mm-dd-title.extension@
56-- | When the context has a key called @path@ in a @yyyy-mm-dd-title.extension@
@@ -61,13 +61,11 @@ copyValue source destination = renderValue source destination id
61-- Will render something like @January 32, 2010@.
61-- Will render something like @January 32, 2010@.
62renderDate :: String -- ^ Key in which the rendered date should be placed.
62renderDate :: String -- ^ Key in which the rendered date should be placed.
63 -> String -- ^ Format to use on the date.
63 -> String -- ^ Format to use on the date.
64− -> String -- ^ Default value when the date cannot be parsed.
64+ -> String -- ^ Default key, in case the date cannot be parsed.
65− -> ContextManipulation
65+ -> HakyllAction Context Context
66−renderDate key format defaultValue context = M.insert key value context
66+renderDate key format defaultValue = renderValue "path" key renderDate'
67 where
67 where
68− value = fromMaybe defaultValue pretty
68+ renderDate' filePath = fromMaybe defaultValue $ do
69− pretty = do
70− filePath <- M.lookup "path" context
71 let dateString = substituteRegex "^([0-9]*-[0-9]*-[0-9]*).*" "\\1"
69 let dateString = substituteRegex "^([0-9]*-[0-9]*-[0-9]*).*" "\\1"
72 (takeFileName filePath)
70 (takeFileName filePath)
73 time <- parseTime defaultTimeLocale
71 time <- parseTime defaultTimeLocale
@@ -84,7 +82,7 @@ renderDate key format defaultValue context = M.insert key value context
84--
82--
85-- Will render to @test.php@ instead of @test.html@.
83-- Will render to @test.php@ instead of @test.html@.
86changeExtension :: String -- ^ Extension to change to.
84changeExtension :: String -- ^ Extension to change to.
87− -> ContextManipulation
85+ -> HakyllAction Context Context
88changeExtension extension = changeValue "url" changeExtension'
86changeExtension extension = changeValue "url" changeExtension'
89 where
87 where
90 changeExtension' = flip addExtension extension . dropExtension
88 changeExtension' = flip addExtension extension . dropExtension
src/Text/Hakyll/Feed.hs+34−64
@@ -20,9 +20,7 @@
20module Text.Hakyll.Feed
20module Text.Hakyll.Feed
21 ( FeedConfiguration (..)
21 ( FeedConfiguration (..)
22 , renderRss
22 , renderRss
23− , renderRssWith
24 , renderAtom
23 , renderAtom
25− , renderAtomWith
26 ) where
24 ) where
27
25
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
32
30
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
38
36
39import Paths_hakyll
37import Paths_hakyll
@@ -52,17 +50,16 @@ data FeedConfiguration = FeedConfiguration
52
50
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
63 where
60 where
64− listing = createListingWith manipulation (feedUrl configuration)
61+ listing = createListing (feedUrl configuration)
65− [itemTemplate] renderables additional
62+ [itemTemplate] renderables additional
66
63
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
79
75
80
76
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'
94
89
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
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 =
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"
112 where
97 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"
98+ renderRssDate = renderDate "timestamp" "%a, %d %b %Y %H:%M:%S UT"
118− "No date found."
99+ "No date found."
119
100
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
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 =
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"
135 where
108 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."
src/Text/Hakyll/Hakyll.hs+5−2
@@ -1,6 +1,7 @@
1-- | Module describing the Hakyll monad stack.
1-- | Module describing the Hakyll monad stack.
2module Text.Hakyll.Hakyll
2module Text.Hakyll.Hakyll
3+ ( Context
3− ( HakyllConfiguration (..)
4+ , HakyllConfiguration (..)
4 , Hakyll
5 , Hakyll
5 , askHakyll
6 , askHakyll
6 , getAdditionalContext
7 , getAdditionalContext
@@ -8,9 +9,11 @@ module Text.Hakyll.Hakyll
8
9
9import Control.Monad.Reader (ReaderT, ask)
10import Control.Monad.Reader (ReaderT, ask)
10import Control.Monad (liftM)
11import Control.Monad (liftM)
12+import Data.Map (Map)
11import qualified Data.Map as M
13import qualified Data.Map as M
12
14
13−import Text.Hakyll.Context (Context)
15+-- | Type for a context.
16+type Context = Map String String
14
17
15-- | Hakyll global configuration type.
18-- | Hakyll global configuration type.
16data HakyllConfiguration = HakyllConfiguration
19data HakyllConfiguration = HakyllConfiguration
src/Text/Hakyll/HakyllAction.hs−12
@@ -4,11 +4,9 @@ module Text.Hakyll.HakyllAction
4 , createHakyllAction
4 , createHakyllAction
5 , createSimpleHakyllAction
5 , createSimpleHakyllAction
6 , createFileHakyllAction
6 , createFileHakyllAction
7− , createManipulationAction
8 , chain
7 , chain
9 , runHakyllAction
8 , runHakyllAction
10 , runHakyllActionIfNeeded
9 , runHakyllActionIfNeeded
11− , Renderable
12 ) where
10 ) where
13
11
14import Control.Arrow
12import Control.Arrow
@@ -18,7 +16,6 @@ import Control.Monad.Reader (liftIO)
18import Prelude hiding ((.), id)
16import Prelude hiding ((.), id)
19import System.IO (hPutStrLn, stderr)
17import System.IO (hPutStrLn, stderr)
20
18
21−import Text.Hakyll.Context
22import Text.Hakyll.File (toDestination, isFileMoreRecent)
19import Text.Hakyll.File (toDestination, isFileMoreRecent)
23import Text.Hakyll.Hakyll
20import Text.Hakyll.Hakyll
24
21
@@ -52,11 +49,6 @@ createFileHakyllAction path action = HakyllAction
52 , actionFunction = const action
49 , actionFunction = const action
53 }
50 }
54
51
55−-- | Create a @HakyllAction@ from a @ContextManipulation@.
56−createManipulationAction :: ContextManipulation -- ^ Manipulation to apply.
57− -> HakyllAction Context Context
58−createManipulationAction = createHakyllAction . (return .)
59−
60-- | Run a @HakyllAction@ now.
52-- | Run a @HakyllAction@ now.
61runHakyllAction :: HakyllAction () a -- ^ Render action to run.
53runHakyllAction :: HakyllAction () a -- ^ Render action to run.
62 -> Hakyll a -- ^ Result of the action.
54 -> Hakyll a -- ^ Result of the action.
@@ -81,10 +73,6 @@ chain :: [HakyllAction a a] -- ^ Actions to chain.
81chain [] = id
73chain [] = id
82chain list@(_:_) = foldl1 (>>>) list
74chain list@(_:_) = foldl1 (>>>) list
83
75
84−-- | This is a specialized version of @HakyllAction@, a @Context@ that can be
85−-- rendered.
86−type Renderable = HakyllAction () Context
87−
88instance Category HakyllAction where
76instance Category HakyllAction where
89 id = HakyllAction
77 id = HakyllAction
90 { actionDependencies = []
78 { actionDependencies = []
src/Text/Hakyll/Internal/Render.hs+6−11
@@ -1,9 +1,6 @@
1-- | Internal module do some low-level rendering.
1-- | Internal module do some low-level rendering.
2module Text.Hakyll.Internal.Render
2module Text.Hakyll.Internal.Render
3− ( substitute
3+ ( pureRender
4− , regularSubstitute
5− , finalSubstitute
6− , pureRenderWith
7 , writePage
4 , writePage
8 ) where
5 ) where
9
6
@@ -11,21 +8,19 @@ import qualified Data.Map as M
11import Control.Monad.Reader (liftIO)
8import Control.Monad.Reader (liftIO)
12import Data.Maybe (fromMaybe)
9import Data.Maybe (fromMaybe)
13
10
14−import Text.Hakyll.Context (Context, ContextManipulation)
15import Text.Hakyll.File
11import Text.Hakyll.File
16import Text.Hakyll.Hakyll
12import Text.Hakyll.Hakyll
17import Text.Hakyll.HakyllAction
13import Text.Hakyll.HakyllAction
18import Text.Hakyll.Internal.Template
14import Text.Hakyll.Internal.Template
19
15
20-- | A pure render function.
16-- | A pure render function.
21−pureRenderWith :: ContextManipulation -- ^ Manipulation to apply on the context.
22− -> Template -- ^ Template to use for rendering.
17+pureRender :: Template -- ^ Template to use for rendering.
23− -> Context -- ^ Renderable object to render with given template.
18+ -> Context -- ^ Renderable object to render with given template.
24− -> Context -- ^ The body of the result will contain the render.
19+ -> Context -- ^ The body of the result will contain the render.
25−pureRenderWith manipulation template context =
20+pureRender template context =
26 -- Ignore $root when substituting here. We will only replace that in the
21 -- Ignore $root when substituting here. We will only replace that in the
27 -- final render (just before writing).
22 -- final render (just before writing).
28− let contextIgnoringRoot = M.insert "root" "$root" (manipulation context)
23+ let contextIgnoringRoot = M.insert "root" "$root" context
29 body = regularSubstitute template contextIgnoringRoot
24 body = regularSubstitute template contextIgnoringRoot
30 in M.insert "body" body context
25 in M.insert "body" body context
31
26
src/Text/Hakyll/Paginate.hs+3−2
@@ -7,6 +7,7 @@ module Text.Hakyll.Paginate
7
7
8import Control.Applicative ((<$>))
8import Control.Applicative ((<$>))
9
9
10+import Text.Hakyll.Hakyll (Context)
10import Text.Hakyll.Renderables
11import Text.Hakyll.Renderables
11import Text.Hakyll.HakyllAction
12import Text.Hakyll.HakyllAction
12import Text.Hakyll.Util (link)
13import Text.Hakyll.Util (link)
@@ -54,8 +55,8 @@ defaultPaginateConfiguration = PaginateConfiguration
54-- without a link. The same goes for when we are on the first or last page for
55-- without a link. The same goes for when we are on the first or last page for
55-- @$first@ and @$last@.
56-- @$first@ and @$last@.
56paginate :: PaginateConfiguration
57paginate :: PaginateConfiguration
57− -> [Renderable]
58+ -> [HakyllAction () Context]
58− -> [Renderable]
59+ -> [HakyllAction () Context]
59paginate configuration renderables = paginate' Nothing renderables (1 :: Int)
60paginate configuration renderables = paginate' Nothing renderables (1 :: Int)
60 where
61 where
61 -- Create a link with a given label, taken from the configuration.
62 -- Create a link with a given label, taken from the configuration.
src/Text/Hakyll/Render.hs+13−41
@@ -2,11 +2,8 @@
2-- render files to the @_site@ directory.
2-- render files to the @_site@ directory.
3module Text.Hakyll.Render
3module Text.Hakyll.Render
4 ( render
4 ( render
5− , renderWith
6 , renderAndConcat
5 , renderAndConcat
7− , renderAndConcatWith
8 , renderChain
6 , renderChain
9− , renderChainWith
10 , static
7 , static
11 , css
8 , css
12 ) where
9 ) where
@@ -17,8 +14,7 @@ import System.Directory (copyFile)
17import Data.Maybe (fromMaybe)
14import Data.Maybe (fromMaybe)
18import qualified Data.Map as M
15import qualified Data.Map as M
19
16
20−import Text.Hakyll.Hakyll (Hakyll)
17+import Text.Hakyll.Hakyll (Hakyll, Context)
21−import Text.Hakyll.Context (ContextManipulation, Context)
22import Text.Hakyll.File
18import Text.Hakyll.File
23import Text.Hakyll.HakyllAction
19import Text.Hakyll.HakyllAction
24import Text.Hakyll.Internal.CompressCss
20import Text.Hakyll.Internal.CompressCss
@@ -28,14 +24,7 @@ import Text.Hakyll.Internal.Template (readTemplate)
28-- | Render to a Page.
24-- | Render to a Page.
29render :: FilePath -- ^ Template to use for rendering.
25render :: FilePath -- ^ Template to use for rendering.
30 -> HakyllAction Context Context -- ^ The render computation.
26 -> HakyllAction Context Context -- ^ The render computation.
31−render = renderWith id
32−
33−-- | Render to a Page. This function allows you to manipulate the context
34−-- first.
35−renderWith :: ContextManipulation -- ^ Manipulation to apply first.
36− -> FilePath -- ^ Template to use for rendering.
37− -> HakyllAction Context Context -- ^ The render computation.
38−renderWith manipulation templatePath = HakyllAction
27+render templatePath = HakyllAction
39 { actionDependencies = [templatePath]
28 { actionDependencies = [templatePath]
40 , actionUrl = Nothing
29 , actionUrl = Nothing
41 , actionFunction = actionFunction'
30 , actionFunction = actionFunction'
@@ -43,7 +32,7 @@ renderWith manipulation templatePath = HakyllAction
43 where
32 where
44 actionFunction' context = do
33 actionFunction' context = do
45 template <- readTemplate templatePath
34 template <- readTemplate templatePath
46− return $ pureRenderWith manipulation template context
35+ return $ pureRender template context
47
36
48-- | Render each renderable with the given templates, then concatenate the
37-- | Render each renderable with the given templates, then concatenate the
49-- result. So, basically this function:
38-- result. So, basically this function:
@@ -55,27 +44,17 @@ renderWith manipulation templatePath = HakyllAction
55--
44--
56-- * Concatenates the result.
45-- * Concatenates the result.
57--
46--
58−renderAndConcat :: [FilePath] -- ^ Templates to apply on every renderable.
47+renderAndConcat :: [FilePath]
59− -> [Renderable] -- ^ Renderables to render.
48+ -> [HakyllAction () Context]
60 -> HakyllAction () String
49 -> HakyllAction () String
61−renderAndConcat = renderAndConcatWith id
62−
63−-- | Render each renderable with the given templates, then concatenate the
64−-- result. This function allows you to specify a @ContextManipulation@ to
65−-- apply on every @Renderable@.
66−renderAndConcatWith :: ContextManipulation
67− -> [FilePath]
68− -> [Renderable]
69− -> HakyllAction () String
70−renderAndConcatWith manipulation templatePaths renderables = HakyllAction
50+renderAndConcat templatePaths renderables = HakyllAction
71 { actionDependencies = renders >>= actionDependencies
51 { actionDependencies = renders >>= actionDependencies
72− , actionUrl = Nothing
52+ , actionUrl = Nothing
73 , actionFunction = actionFunction'
53 , actionFunction = actionFunction'
74 }
54 }
75 where
55 where
76 render' = chain (map render templatePaths)
56 render' = chain (map render templatePaths)
77− renders = map (>>> manipulationAction >>> render') renderables
57+ renders = map (>>> render') renderables
78− manipulationAction = createManipulationAction manipulation
79
58
80 actionFunction' _ = do
59 actionFunction' _ = do
81 contexts <- mapM runHakyllAction renders
60 contexts <- mapM runHakyllAction renders
@@ -91,23 +70,16 @@ renderAndConcatWith manipulation templatePaths renderables = HakyllAction
91--
70--
92-- This code will first render @warning.html@ using @templates/notice.html@,
71-- This code will first render @warning.html@ using @templates/notice.html@,
93-- and will then render the result with @templates/default.html@.
72-- and will then render the result with @templates/default.html@.
94−renderChain :: [FilePath] -> Renderable -> Hakyll ()
73+renderChain :: [FilePath]
95−renderChain = renderChainWith id
74+ -> HakyllAction () Context
96−
97−-- | A more custom render chain that allows you to specify a
98−-- @ContextManipulation@ which to apply on the context when it is read first.
99−renderChainWith :: ContextManipulation
100− -> [FilePath]
101− -> Renderable
102− -> Hakyll ()
75+ -> Hakyll ()
103−renderChainWith manipulation templatePaths initial =
76+renderChain templatePaths initial =
104 runHakyllActionIfNeeded renderChainWith'
77 runHakyllActionIfNeeded renderChainWith'
105 where
78 where
106 renderChainWith' :: HakyllAction () ()
79 renderChainWith' :: HakyllAction () ()
107− renderChainWith' = initial >>> manipulationAction >>> chain' >>> writePage
80+ renderChainWith' = initial >>> chain' >>> writePage
108
81
109 chain' = chain (map render templatePaths)
82 chain' = chain (map render templatePaths)
110− manipulationAction = createManipulationAction manipulation
111
83
112
84
113-- | Mark a certain file as static, so it will just be copied when the site is
85-- | Mark a certain file as static, so it will just be copied when the site is
src/Text/Hakyll/Renderables.hs+15−28
@@ -1,7 +1,6 @@
1module Text.Hakyll.Renderables
1module Text.Hakyll.Renderables
2 ( createCustomPage
2 ( createCustomPage
3 , createListing
3 , createListing
4− , createListingWith
5 , createPagePath
4 , createPagePath
6 , combine
5 , combine
7 , combineWithUrl
6 , combineWithUrl
@@ -27,7 +26,7 @@ import Text.Hakyll.Internal.Page
27-- cases.
26-- cases.
28createCustomPage :: String
27createCustomPage :: String
29 -> [(String, Either String (HakyllAction () String))]
28 -> [(String, Either String (HakyllAction () String))]
30− -> Renderable
29+ -> HakyllAction () Context
31createCustomPage url association = HakyllAction
30createCustomPage url association = HakyllAction
32 { actionDependencies = dataDependencies
31 { actionDependencies = dataDependencies
33 , actionUrl = Just $ return url
32 , actionUrl = Just $ return url
@@ -43,42 +42,30 @@ createCustomPage url association = HakyllAction
43
42
44-- | A @createCustomPage@ function specialized in creating listings.
43-- | A @createCustomPage@ function specialized in creating listings.
45--
44--
46−-- This function creates a listing of a certain list of @Renderable@s. Every
45+-- This function creates a listing of a certain list of renderables. Every
47-- item in the list is created by applying the given template to every
46-- item in the list is created by applying the given template to every
48-- renderable. You can also specify additional context to be included in the
47-- renderable. You can also specify additional context to be included in the
49-- @CustomPage@.
48-- @CustomPage@.
50--
49--
51−-- > let customPage = createListingWith
50+-- > let customPage = createListing
52-- > "index.html" -- Destination of the page.
51-- > "index.html" -- Destination of the page.
53-- > ["templates/postitem.html"] -- Paths to templates to render the
52-- > ["templates/postitem.html"] -- Paths to templates to render the
54-- > -- items with.
53-- > -- items with.
55-- > posts -- Renderables to create the list with.
54-- > posts -- Renderables to create the list with.
56-- > [("title", Left "Home")] -- Additional context
55-- > [("title", Left "Home")] -- Additional context
57−createListing :: String -- ^ Destination of the page.
56+createListing :: String -- ^ Destination of the page.
58− -> [FilePath] -- ^ Templates to render all items with.
57+ -> [FilePath] -- ^ Templates to render items with.
59− -> [Renderable] -- ^ Renderables in the list.
58+ -> [HakyllAction () Context] -- ^ Renderables in the list.
60 -> [(String, Either String (HakyllAction () String))]
59 -> [(String, Either String (HakyllAction () String))]
61− -> Renderable
62−createListing = createListingWith id
63−
64−-- | A @createCustomPage@ function specialized in creating listings.
65−--
66−-- In addition to @createListing@, this function allows you to specify an
67−-- extra @ContextManipulation@ for all @Renderable@s given.
68−createListingWith :: ContextManipulation -- ^ Manipulation for the renderables.
69− -> String -- ^ Destination of the page.
70− -> [FilePath] -- ^ Templates to render all items with.
71− -> [Renderable] -- ^ Renderables in the list.
72− -> [(String, Either String (HakyllAction () String))]
60+ -> HakyllAction () Context
73− -> Renderable
74−createListingWith manipulation url templates renderables additional =
61+createListing url templates renderables additional =
75 createCustomPage url context
62 createCustomPage url context
76 where
63 where
77 context = ("body", Right concatenation) : additional
64 context = ("body", Right concatenation) : additional
78− concatenation = renderAndConcatWith manipulation templates renderables
65+ concatenation = renderAndConcat templates renderables
79
66
80-- | Create a PagePath from a FilePath.
67-- | Create a PagePath from a FilePath.
81−createPagePath :: FilePath -> Renderable
68+createPagePath :: FilePath -> HakyllAction () Context
82createPagePath path = HakyllAction
69createPagePath path = HakyllAction
83 { actionDependencies = [path]
70 { actionDependencies = [path]
84 , actionUrl = Just $ toUrl path
71 , actionUrl = Just $ toUrl path
@@ -91,8 +78,8 @@ createPagePath path = HakyllAction
91--
78--
92-- Since renderables are always more or less key-value maps, you can see
79-- Since renderables are always more or less key-value maps, you can see
93-- this as a @union@ between two maps.
80-- this as a @union@ between two maps.
94−combine :: Renderable -> Renderable
81+combine :: HakyllAction () Context -> HakyllAction () Context
95− -> Renderable
82+ -> HakyllAction () Context
96combine x y = HakyllAction
83combine x y = HakyllAction
97 { actionDependencies = actionDependencies x ++ actionDependencies y
84 { actionDependencies = actionDependencies x ++ actionDependencies y
98 , actionUrl = actionUrl x `mplus` actionUrl y
85 , actionUrl = actionUrl x `mplus` actionUrl y
@@ -103,9 +90,9 @@ combine x y = HakyllAction
103-- | Combine two renderables and set a custom URL. This behaves like @combine@,
90-- | Combine two renderables and set a custom URL. This behaves like @combine@,
104-- except that for the @url@ field, the given URL is always chosen.
91-- except that for the @url@ field, the given URL is always chosen.
105combineWithUrl :: FilePath
92combineWithUrl :: FilePath
106− -> Renderable
93+ -> HakyllAction () Context
107− -> Renderable
94+ -> HakyllAction () Context
108− -> Renderable
95+ -> HakyllAction () Context
109combineWithUrl url x y = combine'
96combineWithUrl url x y = combine'
110 { actionUrl = Just $ return url
97 { actionUrl = Just $ return url
111 , actionFunction = \_ ->
98 , actionFunction = \_ ->
src/Text/Hakyll/Tags.hs+3−3
@@ -58,7 +58,7 @@ import Text.Hakyll.Internal.Template
58-- This is a map associating tags or categories to the appropriate pages
58-- This is a map associating tags or categories to the appropriate pages
59-- using that tag or category. In the case of categories, each path will only
59-- using that tag or category. In the case of categories, each path will only
60-- appear under one category - this is not the case with tags.
60-- appear under one category - this is not the case with tags.
61−type TagMap = M.Map String [Renderable]
61+type TagMap = M.Map String [HakyllAction () Context]
62
62
63-- | Read a tag map. This is a internally used function that can be used for
63-- | Read a tag map. This is a internally used function that can be used for
64-- tags as well as for categories.
64-- tags as well as for categories.
@@ -106,7 +106,7 @@ readCategoryMap :: String -- ^ Unique identifier for the map.
106readCategoryMap = readMap $ maybeToList . M.lookup "category"
106readCategoryMap = readMap $ maybeToList . M.lookup "category"
107
107
108withTagMap :: HakyllAction () TagMap
108withTagMap :: HakyllAction () TagMap
109− -> (String -> [Renderable] -> Hakyll ())
109+ -> (String -> [HakyllAction () Context] -> Hakyll ())
110 -> Hakyll ()
110 -> Hakyll ()
111withTagMap tagMap function = runHakyllAction (tagMap >>> action)
111withTagMap tagMap function = runHakyllAction (tagMap >>> action)
112 where
112 where
@@ -154,7 +154,7 @@ renderTagCloud urlFunction minSize maxSize = createHakyllAction renderTagCloud'
154-- Note that it is your own responsibility to ensure a page with such an url
154-- Note that it is your own responsibility to ensure a page with such an url
155-- exists.
155-- exists.
156renderTagLinks :: (String -> String) -- ^ Function to produce an url for a tag.
156renderTagLinks :: (String -> String) -- ^ Function to produce an url for a tag.
157− -> ContextManipulation
157+ -> HakyllAction Context Context
158renderTagLinks urlFunction = changeValue "tags" renderTagLinks'
158renderTagLinks urlFunction = changeValue "tags" renderTagLinks'
159 where
159 where
160 renderTagLinks' = intercalate ", "
160 renderTagLinks' = intercalate ", "