@@ -14,14 +14,11 @@ import Control.Arrow (second)
14import Control.Monad (liftM2, mplus)
14import Control.Monad (liftM2, mplus)
15import Control.Applicative ((<$>))
15import Control.Applicative ((<$>))
19−import Text.Hakyll.Hakyll (Hakyll)
20−import Text.Hakyll.Renderable
21import Text.Hakyll.File
18import Text.Hakyll.File
22import Text.Hakyll.Context
19import Text.Hakyll.Context
23−import Text.Hakyll.Render
24import Text.Hakyll.RenderAction
20import Text.Hakyll.RenderAction
21+import Text.Hakyll.Render
25import Text.Hakyll.Internal.Page
22import Text.Hakyll.Internal.Page
27-- | Create a custom page.
24-- | Create a custom page.
@@ -33,16 +30,17 @@ import Text.Hakyll.Internal.Page
34createCustomPage :: String
31createCustomPage :: String
35 -> [FilePath]
32 -> [FilePath]
36− -> [(String, Either String (Hakyll String))]
33+ -> [(String, Either String (RenderAction () String))]
37 -> RenderAction () Context
34 -> RenderAction () Context
38createCustomPage url dependencies association = RenderAction
35createCustomPage url dependencies association = RenderAction
39 { actionDependencies = dependencies
36 { actionDependencies = dependencies
40− , actionDestination = Just $ return url
37+ , actionUrl = Just $ return url
41− , actionFunction = actionFunction'
38+ , actionFunction = \_ -> M.fromList <$> assoc'
44 mtuple (a, b) = b >>= \b' -> return (a, b')
41 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
47-- | A @createCustomPage@ function specialized in creating listings.
45-- | A @createCustomPage@ function specialized in creating listings.
@@ -57,10 +55,9 @@ createCustomPage url dependencies association = RenderAction
57-- > -- render the items with.
55-- > -- render the items with.
58-- > posts -- ^ Renderables to create the list with.
56-- > posts -- ^ Renderables to create the list with.
59-- > [("title", "Home")] -- ^ Additional context
57-- > [("title", "Home")] -- ^ Additional context
60−createListing :: (Renderable a)
61− => String -- ^ Destination of the page.
58+createListing :: String -- ^ Destination of the page.
62 -> FilePath -- ^ Template to render all items with.
59 -> FilePath -- ^ Template to render all items with.
63− -> [a] -- ^ Renderables in the list.
60+ -> [RenderAction () Context] -- ^ Renderables in the list.
64 -> [(String, String)] -- ^ Additional context.
61 -> [(String, String)] -- ^ Additional context.
65 -> RenderAction () Context
62 -> RenderAction () Context
66createListing = createListingWith id
63createListing = createListingWith id
@@ -69,17 +66,16 @@ createListing = createListingWith id
70-- In addition to @createListing@, this function allows you to specify an
67-- In addition to @createListing@, this function allows you to specify an
71-- extra @ContextManipulation@ for all @Renderable@s given.
68-- extra @ContextManipulation@ for all @Renderable@s given.
72−createListingWith :: (Renderable a)
73− => ContextManipulation -- ^ Manipulation for the renderables.
69+createListingWith :: ContextManipulation -- ^ Manipulation for the renderables.
74 -> String -- ^ Destination of the page.
70 -> String -- ^ Destination of the page.
75 -> FilePath -- ^ Template to render all items with.
71 -> FilePath -- ^ Template to render all items with.
76− -> [a] -- ^ Renderables in the list.
72+ -> [RenderAction () Context] -- ^ Renderables in the list.
77 -> [(String, String)] -- ^ Additional context.
73 -> [(String, String)] -- ^ Additional context.
78 -> RenderAction () Context
74 -> RenderAction () Context
79createListingWith manipulation url template renderables additional =
75createListingWith manipulation url template renderables additional =
80 createCustomPage url dependencies context
76 createCustomPage url dependencies context
82− dependencies = template : concatMap getDependencies renderables
78+ dependencies = template : concatMap actionDependencies renderables
83 context = ("body", Right concatenation) : additional'
79 context = ("body", Right concatenation) : additional'
84 concatenation = renderAndConcatWith manipulation [template] renderables
80 concatenation = renderAndConcatWith manipulation [template] renderables
85 additional' = map (second Left) additional
81 additional' = map (second Left) additional
@@ -93,7 +89,7 @@ newtype PagePath = PagePath FilePath
93createPagePath :: FilePath -> RenderAction () Context
89createPagePath :: FilePath -> RenderAction () Context
94createPagePath path = RenderAction
90createPagePath path = RenderAction
95 { actionDependencies = [path]
91 { actionDependencies = [path]
96− , actionDestination = Just $ toUrl path
92+ , actionUrl = Just $ toUrl path
97 , actionFunction = const (readPage path)
93 , actionFunction = const (readPage path)
@@ -112,38 +108,21 @@ combine :: RenderAction () Context -> RenderAction () Context
112 -> RenderAction () Context
108 -> RenderAction () Context
113combine x y = RenderAction
109combine x y = RenderAction
114 { actionDependencies = actionDependencies x ++ actionDependencies y
110 { actionDependencies = actionDependencies x ++ actionDependencies y
115− , actionDestination = actionDestination x `mplus` actionDestination y
111+ , actionUrl = actionUrl x `mplus` actionUrl y
116− , actionFunction = \_ -> liftM2 (M.union) (actionFunction x ()) (actionFunction y ())
112+ , actionFunction = \_ ->
113+ liftM2 (M.union) (runRenderAction x) (runRenderAction y)
119-- | Combine two renderables and set a custom URL. This behaves like @combine@,
116-- | Combine two renderables and set a custom URL. This behaves like @combine@,
120-- except that for the @url@ field, the given URL is always chosen.
117-- except that for the @url@ field, the given URL is always chosen.
121−combineWithUrl :: (Renderable a, Renderable b)
122− => FilePath
118+combineWithUrl :: FilePath
123− -> a
119+ -> RenderAction () Context
124− -> b
120+ -> RenderAction () Context
125− -> CombinedRenderable a b
121+ -> RenderAction () Context
126−combineWithUrl = CombinedRenderableWithUrl
122+combineWithUrl url x y = combine'
127−
123+ { actionUrl = Just $ return url
128−-- Render combinations.
124+ , actionFunction = \_ ->
129−instance (Renderable a, Renderable b)
125+ (M.insert "url" url) <$> runRenderAction combine'
130− => Renderable (CombinedRenderable a b) where
126+ }
132− -- Add the dependencies.
128+ combine' = combine x y
133− getDependencies (CombinedRenderable a b) =
134− getDependencies a ++ getDependencies b
135− getDependencies (CombinedRenderableWithUrl _ a b) =
136− getDependencies a ++ getDependencies b
138− -- Take the url from the first renderable, or the specified URL.
139− getUrl (CombinedRenderable a _) = getUrl a
140− getUrl (CombinedRenderableWithUrl url _ _) = return url
142− -- Take a union of the contexts.
143− toContext (CombinedRenderable a b) = do
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