@@ -1,7 +1,10 @@
1−module Text.Hakyll.Renderables
2− ( createCustomPage
1+-- | A module that provides different ways to create a @Context@. These
2+-- functions all use the @HakyllAction@ arrow, so they produce values of the
3+-- type @HakyllAction () Context@.
4+module Text.Hakyll.CreateContext
5+ ( createPage
6+ , createCustomPage
37 , createListing
4− , createPagePath
58 , combine
69 , combineWithUrl
710 ) where
@@ -17,13 +20,22 @@ import Text.Hakyll.HakyllAction
1720import Text.Hakyll.Render
1821import Text.Hakyll.Internal.Page
1922
20−-- | Create a custom page.
23+-- | Create a @Context@ from a page file stored on the disk. This is probably
24+-- the most common way to create a @Context@.
25+createPage :: FilePath -> HakyllAction () Context
26+createPage path = HakyllAction
27+ { actionDependencies = [path]
28+ , actionUrl = Just $ toUrl path
29+ , actionFunction = const (readPage path)
30+ }
31+
32+-- | Create a "custom page" @Context@.
2133--
2234-- The association list given maps keys to values for substitution. Note
23−-- that as value, you can either give a @String@ or a @Hakyll String@.
24−-- A @Hakyll String@ is preferred for more complex data, since it allows
25−-- dependency checking. A @String@ is obviously more simple to use in some
26−-- cases.
35+-- that as value, you can either give a @String@ or a
36+-- @HakyllAction () String@. The latter is preferred for more complex data,
37+-- since it allows dependency checking. A @String@ is obviously more simple
38+-- to use in some cases.
2739createCustomPage :: String
2840 -> [(String, Either String (HakyllAction () String))]
2941 -> HakyllAction () Context
@@ -42,17 +54,10 @@ createCustomPage url association = HakyllAction
4254
4355-- | A @createCustomPage@ function specialized in creating listings.
4456--
45−-- This function creates a listing of a certain list of renderables. Every
57+-- This function creates a listing of a certain list of @Context@s. Every
4658-- item in the list is created by applying the given template to every
4759-- renderable. You can also specify additional context to be included in the
4860-- @CustomPage@.
49−--
50−-- > let customPage = createListing
51−-- > "index.html" -- Destination of the page.
52−-- > ["templates/postitem.html"] -- Paths to templates to render the
53−-- > -- items with.
54−-- > posts -- Renderables to create the list with.
55−-- > [("title", Left "Home")] -- Additional context
5661createListing :: String -- ^ Destination of the page.
5762 -> [FilePath] -- ^ Templates to render items with.
5863 -> [HakyllAction () Context] -- ^ Renderables in the list.
@@ -64,14 +69,6 @@ createListing url templates renderables additional =
6469 context = ("body", Right concatenation) : additional
6570 concatenation = renderAndConcat templates renderables
6671
67−-- | Create a PagePath from a FilePath.
68−createPagePath :: FilePath -> HakyllAction () Context
69−createPagePath path = HakyllAction
70− { actionDependencies = [path]
71− , actionUrl = Just $ toUrl path
72− , actionFunction = const (readPage path)
73− }
74−
7572-- | Combine two renderables. The url will always be taken from the first
7673-- @Renderable@. Also, if a `$key` is present in both renderables, the
7774-- value from the first @Renderable@ will be taken as well.