@@ -1,6 +1,8 @@
1module Text.Hakyll.Renderables
1module Text.Hakyll.Renderables
2 ( CustomPage
2 ( CustomPage
3 , createCustomPage
3 , createCustomPage
5 , createPagePath
7 , createPagePath
6 , CombinedRenderable
8 , CombinedRenderable
@@ -9,11 +11,14 @@ module Text.Hakyll.Renderables
11import qualified Data.Map as M
13import qualified Data.Map as M
14+import Control.Arrow (second)
13import Text.Hakyll.Hakyll (Hakyll)
16import Text.Hakyll.Hakyll (Hakyll)
14import Text.Hakyll.Page
17import Text.Hakyll.Page
15import Text.Hakyll.Renderable
18import Text.Hakyll.Renderable
16import Text.Hakyll.File
19import Text.Hakyll.File
20+import Text.Hakyll.Context
21+import Text.Hakyll.Render
18-- | A custom page.
23-- | A custom page.
19data CustomPage = CustomPage
24data CustomPage = CustomPage
@@ -35,6 +40,39 @@ createCustomPage :: String -- ^ Destination of the page, relative to _site.
35 -> CustomPage
40 -> CustomPage
36createCustomPage = CustomPage
41createCustomPage = CustomPage
43+-- | A @createCustomPage@ function specialized in creating listings.
45+-- This function creates a listing of a certain list of @Renderable@s. Every
46+-- item in the list is created by applying the given template to every
47+-- renderable. You can also specify additional context to be included in the
49+createListing :: (Renderable a)
50+ => String -- ^ Destination of the page.
51+ -> FilePath -- ^ Template to render all items with.
52+ -> [a] -- ^ Renderables in the list.
53+ -> [(String, String)] -- ^ Additional context.
55+createListing = createListingWith id
57+-- | A @createCustomPage@ function specialized in creating listings.
59+-- In addition to @createListing@, this function allows you to specify an
60+-- extra @ContextManipulation@ for all @Renderable@s given.
61+createListingWith :: (Renderable a)
62+ => ContextManipulation -- ^ Manipulation for the renderables.
63+ -> String -- ^ Destination of the page.
64+ -> FilePath -- ^ Template to render all items with.
65+ -> [a] -- ^ Renderables in the list.
66+ -> [(String, String)] -- ^ Additional context.
68+createListingWith manipulation url template renderables additional =
69+ createCustomPage url dependencies context
71+ dependencies = template : concatMap getDependencies renderables
72+ context = ("body", Right concatenation) : additional'
73+ concatenation = renderAndConcatWith manipulation [template] renderables
74+ additional' = map (second Left) additional
38instance Renderable CustomPage where
76instance Renderable CustomPage where
39 getDependencies = customPageDependencies
77 getDependencies = customPageDependencies
40 getURL = customPageURL
78 getURL = customPageURL
@@ -62,15 +100,15 @@ data CombinedRenderable a b = CombinedRenderable a b
62 | CombinedRenderableWithURL FilePath a b
100 | CombinedRenderableWithURL FilePath a b
64-- | Combine two renderables. The url will always be taken from the first
102-- | Combine two renderables. The url will always be taken from the first
65−-- "Renderable". Also, if a `$key` is present in both renderables, the
103+-- @Renderable@. Also, if a `$key` is present in both renderables, the
66−-- value from the first "Renderable" will be taken as well.
104+-- value from the first @Renderable@ will be taken as well.
68-- Since renderables are always more or less key-value maps, you can see
106-- Since renderables are always more or less key-value maps, you can see
69-- this as a @union@ between two maps.
107-- this as a @union@ between two maps.
70combine :: (Renderable a, Renderable b) => a -> b -> CombinedRenderable a b
108combine :: (Renderable a, Renderable b) => a -> b -> CombinedRenderable a b
71combine = CombinedRenderable
109combine = CombinedRenderable
73−-- | Combine two renderables and set a custom URL. This behaves like "combine",
111+-- | Combine two renderables and set a custom URL. This behaves like @combine@,
74-- except that for the @url@ field, the given URL is always chosen.
112-- except that for the @url@ field, the given URL is always chosen.
75combineWithURL :: (Renderable a, Renderable b)
113combineWithURL :: (Renderable a, Renderable b)
76 => FilePath
114 => FilePath