@@ -1,6 +1,5 @@
1module Text.Hakyll.Renderables
1module Text.Hakyll.Renderables
3− , createCustomPage
2+ ( createCustomPage
4 , createListing
3 , createListing
5 , createListingWith
4 , createListingWith
@@ -12,7 +11,8 @@ module Text.Hakyll.Renderables
13import qualified Data.Map as M
12import qualified Data.Map as M
14import Control.Arrow (second)
13import Control.Arrow (second)
15−import Control.Monad (liftM)
14+import Control.Monad (liftM, liftM2, mplus)
15+import Control.Applicative ((<$>))
17import Data.Binary
17import Data.Binary
@@ -22,13 +22,7 @@ import Text.Hakyll.Renderable
22import Text.Hakyll.File
22import Text.Hakyll.File
23import Text.Hakyll.Context
23import Text.Hakyll.Context
24import Text.Hakyll.Render
24import Text.Hakyll.Render
25−
25+import Text.Hakyll.RenderAction
27−data CustomPage = CustomPage
28− { customPageUrl :: String,
29− customPageDependencies :: [FilePath],
30− customPageContext :: [(String, Either String (Hakyll String))]
33-- | Create a custom page.
27-- | Create a custom page.
@@ -37,11 +31,18 @@ data CustomPage = CustomPage
37-- A @Hakyll String@ is preferred for more complex data, since it allows
31-- A @Hakyll String@ is preferred for more complex data, since it allows
38-- dependency checking. A @String@ is obviously more simple to use in some
32-- dependency checking. A @String@ is obviously more simple to use in some
40−createCustomPage :: String -- ^ Destination of the page, relative to _site.
34+createCustomPage :: String
41− -> [FilePath] -- ^ Dependencies of the page.
35+ -> [FilePath]
42− -> [(String, Either String (Hakyll String))] -- ^ Mapping.
36+ -> [(String, Either String (Hakyll String))]
43− -> CustomPage
37+ -> RenderAction () Context
44−createCustomPage = CustomPage
38+createCustomPage url dependencies association = RenderAction
39+ { actionDependencies = dependencies
40+ , actionDestination = Just $ return url
41+ , actionFunction = actionFunction'
44+ mtuple (a, b) = b >>= \b' -> return (a, b')
45+ actionFunction' () = M.fromList <$> mapM (mtuple . second (either return id)) association
46-- | A @createCustomPage@ function specialized in creating listings.
47-- | A @createCustomPage@ function specialized in creating listings.
@@ -61,7 +62,7 @@ createListing :: (Renderable a)
61 -> FilePath -- ^ Template to render all items with.
62 -> FilePath -- ^ Template to render all items with.
62 -> [a] -- ^ Renderables in the list.
63 -> [a] -- ^ Renderables in the list.
63 -> [(String, String)] -- ^ Additional context.
64 -> [(String, String)] -- ^ Additional context.
64− -> CustomPage
65+ -> RenderAction () Context
65createListing = createListingWith id
66createListing = createListingWith id
67-- | A @createCustomPage@ function specialized in creating listings.
68-- | A @createCustomPage@ function specialized in creating listings.
@@ -74,7 +75,7 @@ createListingWith :: (Renderable a)
74 -> FilePath -- ^ Template to render all items with.
75 -> FilePath -- ^ Template to render all items with.
75 -> [a] -- ^ Renderables in the list.
76 -> [a] -- ^ Renderables in the list.
76 -> [(String, String)] -- ^ Additional context.
77 -> [(String, String)] -- ^ Additional context.
77− -> CustomPage
78+ -> RenderAction () Context
78createListingWith manipulation url template renderables additional =
79createListingWith manipulation url template renderables additional =
79 createCustomPage url dependencies context
80 createCustomPage url dependencies context
@@ -83,14 +84,6 @@ createListingWith manipulation url template renderables additional =
83 concatenation = renderAndConcatWith manipulation [template] renderables
84 concatenation = renderAndConcatWith manipulation [template] renderables
84 additional' = map (second Left) additional
85 additional' = map (second Left) additional
86−instance Renderable CustomPage where
87− getDependencies = customPageDependencies
88− getUrl = return . customPageUrl
90− values <- mapM (either return id . snd) (customPageContext page)
91− let pairs = zip (map fst $ customPageContext page) values
92− return $ M.fromList $ ("url", customPageUrl page) : pairs
94-- | PagePath is a class that wraps a FilePath. This is used to render Pages
87-- | PagePath is a class that wraps a FilePath. This is used to render Pages
95-- without reading them first through use of caching.
88-- without reading them first through use of caching.
96newtype PagePath = PagePath FilePath
89newtype PagePath = PagePath FilePath
@@ -122,8 +115,13 @@ data CombinedRenderable a b = CombinedRenderable a b
123-- Since renderables are always more or less key-value maps, you can see
116-- Since renderables are always more or less key-value maps, you can see
124-- this as a @union@ between two maps.
117-- this as a @union@ between two maps.
125−combine :: (Renderable a, Renderable b) => a -> b -> CombinedRenderable a b
118+combine :: RenderAction () Context -> RenderAction () Context
126−combine = CombinedRenderable
119+ -> RenderAction () Context
120+combine x y = RenderAction
121+ { actionDependencies = actionDependencies x ++ actionDependencies y
122+ , actionDestination = actionDestination x `mplus` actionDestination y
123+ , actionFunction = \_ -> liftM2 (M.union) (actionFunction x ()) (actionFunction y ())
128-- | Combine two renderables and set a custom URL. This behaves like @combine@,
126-- | Combine two renderables and set a custom URL. This behaves like @combine@,
129-- except that for the @url@ field, the given URL is always chosen.
127-- except that for the @url@ field, the given URL is always chosen.