@@ -14,14 +14,11 @@ import Control.Arrow (second)
1414import Control.Monad (liftM2, mplus)
1515import Control.Applicative ((<$>))
1616
17−import Data.Binary
1817
19−import Text.Hakyll.Hakyll (Hakyll)
20−import Text.Hakyll.Renderable
2118import Text.Hakyll.File
2219import Text.Hakyll.Context
23−import Text.Hakyll.Render
2420import Text.Hakyll.RenderAction
21+import Text.Hakyll.Render
2522import Text.Hakyll.Internal.Page
2623
2724-- | Create a custom page.
@@ -33,16 +30,17 @@ import Text.Hakyll.Internal.Page
3330-- cases.
3431createCustomPage :: String
3532 -> [FilePath]
36− -> [(String, Either String (Hakyll String))]
33+ -> [(String, Either String (RenderAction () String))]
3734 -> RenderAction () Context
3835createCustomPage url dependencies association = RenderAction
3936 { actionDependencies = dependencies
40− , actionDestination = Just $ return url
41− , actionFunction = actionFunction'
37+ , actionUrl = Just $ return url
38+ , actionFunction = \_ -> M.fromList <$> assoc'
4239 }
4340 where
4441 mtuple (a, b) = b >>= \b' -> return (a, b')
45− actionFunction' () = M.fromList <$> mapM (mtuple . second (either return id)) association
42+ toHakyllString = second (either return runRenderAction)
43+ assoc' = mapM (mtuple . toHakyllString) association
4644
4745-- | A @createCustomPage@ function specialized in creating listings.
4846--
@@ -57,10 +55,9 @@ createCustomPage url dependencies association = RenderAction
5755-- > -- render the items with.
5856-- > posts -- ^ Renderables to create the list with.
5957-- > [("title", "Home")] -- ^ Additional context
60−createListing :: (Renderable a)
61− => String -- ^ Destination of the page.
58+createListing :: String -- ^ Destination of the page.
6259 -> FilePath -- ^ Template to render all items with.
63− -> [a] -- ^ Renderables in the list.
60+ -> [RenderAction () Context] -- ^ Renderables in the list.
6461 -> [(String, String)] -- ^ Additional context.
6562 -> RenderAction () Context
6663createListing = createListingWith id
@@ -69,17 +66,16 @@ createListing = createListingWith id
6966--
7067-- In addition to @createListing@, this function allows you to specify an
7168-- extra @ContextManipulation@ for all @Renderable@s given.
72−createListingWith :: (Renderable a)
73− => ContextManipulation -- ^ Manipulation for the renderables.
69+createListingWith :: ContextManipulation -- ^ Manipulation for the renderables.
7470 -> String -- ^ Destination of the page.
7571 -> FilePath -- ^ Template to render all items with.
76− -> [a] -- ^ Renderables in the list.
72+ -> [RenderAction () Context] -- ^ Renderables in the list.
7773 -> [(String, String)] -- ^ Additional context.
7874 -> RenderAction () Context
7975createListingWith manipulation url template renderables additional =
8076 createCustomPage url dependencies context
8177 where
82− dependencies = template : concatMap getDependencies renderables
78+ dependencies = template : concatMap actionDependencies renderables
8379 context = ("body", Right concatenation) : additional'
8480 concatenation = renderAndConcatWith manipulation [template] renderables
8581 additional' = map (second Left) additional
@@ -93,7 +89,7 @@ newtype PagePath = PagePath FilePath
9389createPagePath :: FilePath -> RenderAction () Context
9490createPagePath path = RenderAction
9591 { actionDependencies = [path]
96− , actionDestination = Just $ toUrl path
92+ , actionUrl = Just $ toUrl path
9793 , actionFunction = const (readPage path)
9894 }
9995
@@ -112,38 +108,21 @@ combine :: RenderAction () Context -> RenderAction () Context
112108 -> RenderAction () Context
113109combine x y = RenderAction
114110 { actionDependencies = actionDependencies x ++ actionDependencies y
115− , actionDestination = actionDestination x `mplus` actionDestination y
116− , actionFunction = \_ -> liftM2 (M.union) (actionFunction x ()) (actionFunction y ())
111+ , actionUrl = actionUrl x `mplus` actionUrl y
112+ , actionFunction = \_ ->
113+ liftM2 (M.union) (runRenderAction x) (runRenderAction y)
117114 }
118115
119116-- | Combine two renderables and set a custom URL. This behaves like @combine@,
120117-- except that for the @url@ field, the given URL is always chosen.
121−combineWithUrl :: (Renderable a, Renderable b)
122− => FilePath
123− -> a
124− -> b
125− -> CombinedRenderable a b
126−combineWithUrl = CombinedRenderableWithUrl
127−
128−-- Render combinations.
129−instance (Renderable a, Renderable b)
130− => Renderable (CombinedRenderable a b) where
131−
132− -- Add the dependencies.
133− getDependencies (CombinedRenderable a b) =
134− getDependencies a ++ getDependencies b
135− getDependencies (CombinedRenderableWithUrl _ a b) =
136− getDependencies a ++ getDependencies b
137−
138− -- Take the url from the first renderable, or the specified URL.
139− getUrl (CombinedRenderable a _) = getUrl a
140− getUrl (CombinedRenderableWithUrl url _ _) = return url
141−
142− -- Take a union of the contexts.
143− toContext (CombinedRenderable a b) = do
144− c1 <- toContext a
145− c2 <- toContext b
146− return $ c1 `M.union` c2
147− toContext (CombinedRenderableWithUrl url a b) = do
148− c <- toContext (CombinedRenderable a b)
149− return $ M.singleton "url" url `M.union` c
118+combineWithUrl :: FilePath
119+ -> RenderAction () Context
120+ -> RenderAction () Context
121+ -> RenderAction () Context
122+combineWithUrl url x y = combine'
123+ { actionUrl = Just $ return url
124+ , actionFunction = \_ ->
125+ (M.insert "url" url) <$> runRenderAction combine'
126+ }
127+ where
128+ combine' = combine x y