on master help sign in
Aliased `RenderAction () Context` to Renderable, custompages now have correct dependencies.
034c659Jasper Van der Jeugt
src/Text/Hakyll/Paginate.hs+2−3
@@ -7,7 +7,6 @@ module Text.Hakyll.Paginate
7
7
8import Control.Applicative ((<$>))
8import Control.Applicative ((<$>))
9
9
10−import Text.Hakyll.Context
11import Text.Hakyll.Renderables
10import Text.Hakyll.Renderables
12import Text.Hakyll.RenderAction
11import Text.Hakyll.RenderAction
13import Text.Hakyll.Util (link)
12import Text.Hakyll.Util (link)
@@ -50,8 +49,8 @@ defaultPaginateConfiguration = PaginateConfiguration
50-- without a link. The same goes for when we are on the first or last page for
49-- without a link. The same goes for when we are on the first or last page for
51-- @$first@ and @$last@.
50-- @$first@ and @$last@.
52paginate :: PaginateConfiguration
51paginate :: PaginateConfiguration
53− -> [RenderAction () Context]
52+ -> [Renderable]
54− -> [RenderAction () Context]
53+ -> [Renderable]
55paginate configuration renderables = paginate' Nothing renderables (1 :: Int)
54paginate configuration renderables = paginate' Nothing renderables (1 :: Int)
56 where
55 where
57 -- Create a link with a given label, taken from the configuration.
56 -- Create a link with a given label, taken from the configuration.
src/Text/Hakyll/Render.hs+4−4
@@ -56,7 +56,7 @@ renderWith manipulation templatePath = RenderAction
56-- * Concatenates the result.
56-- * Concatenates the result.
57--
57--
58renderAndConcat :: [FilePath] -- ^ Templates to apply on every renderable.
58renderAndConcat :: [FilePath] -- ^ Templates to apply on every renderable.
59− -> [RenderAction () Context] -- ^ Renderables to render.
59+ -> [Renderable] -- ^ Renderables to render.
60 -> RenderAction () String
60 -> RenderAction () String
61renderAndConcat = renderAndConcatWith id
61renderAndConcat = renderAndConcatWith id
62
62
@@ -65,7 +65,7 @@ renderAndConcat = renderAndConcatWith id
65-- apply on every @Renderable@.
65-- apply on every @Renderable@.
66renderAndConcatWith :: ContextManipulation
66renderAndConcatWith :: ContextManipulation
67 -> [FilePath]
67 -> [FilePath]
68− -> [RenderAction () Context]
68+ -> [Renderable]
69 -> RenderAction () String
69 -> RenderAction () String
70renderAndConcatWith manipulation templatePaths renderables = RenderAction
70renderAndConcatWith manipulation templatePaths renderables = RenderAction
71 { actionDependencies = renders >>= actionDependencies
71 { actionDependencies = renders >>= actionDependencies
@@ -91,14 +91,14 @@ renderAndConcatWith manipulation templatePaths renderables = RenderAction
91--
91--
92-- This code will first render @warning.html@ using @templates/notice.html@,
92-- This code will first render @warning.html@ using @templates/notice.html@,
93-- and will then render the result with @templates/default.html@.
93-- and will then render the result with @templates/default.html@.
94−renderChain :: [FilePath] -> RenderAction () Context -> Hakyll ()
94+renderChain :: [FilePath] -> Renderable -> Hakyll ()
95renderChain = renderChainWith id
95renderChain = renderChainWith id
96
96
97-- | A more custom render chain that allows you to specify a
97-- | A more custom render chain that allows you to specify a
98-- @ContextManipulation@ which to apply on the context when it is read first.
98-- @ContextManipulation@ which to apply on the context when it is read first.
99renderChainWith :: ContextManipulation
99renderChainWith :: ContextManipulation
100 -> [FilePath]
100 -> [FilePath]
101− -> RenderAction () Context
101+ -> Renderable
102 -> Hakyll ()
102 -> Hakyll ()
103renderChainWith manipulation templatePaths initial =
103renderChainWith manipulation templatePaths initial =
104 runRenderActionIfNeeded renderChainWith'
104 runRenderActionIfNeeded renderChainWith'
src/Text/Hakyll/RenderAction.hs+3
@@ -7,6 +7,7 @@ module Text.Hakyll.RenderAction
7 , chain
7 , chain
8 , runRenderAction
8 , runRenderAction
9 , runRenderActionIfNeeded
9 , runRenderActionIfNeeded
10+ , Renderable
10 ) where
11 ) where
11
12
12import Control.Category
13import Control.Category
@@ -69,3 +70,5 @@ runRenderActionIfNeeded action = do
69 valid <- isFileMoreRecent destination $ actionDependencies action
70 valid <- isFileMoreRecent destination $ actionDependencies action
70 unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination
71 unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination
71 runRenderAction action
72 runRenderAction action
73+
74+type Renderable = RenderAction () Context
src/Text/Hakyll/Renderables.hs+15−13
@@ -12,7 +12,6 @@ import Control.Arrow (second)
12import Control.Monad (liftM2, mplus)
12import Control.Monad (liftM2, mplus)
13import Control.Applicative ((<$>))
13import Control.Applicative ((<$>))
14
14
15−
16import Text.Hakyll.File
15import Text.Hakyll.File
17import Text.Hakyll.Context
16import Text.Hakyll.Context
18import Text.Hakyll.RenderAction
17import Text.Hakyll.RenderAction
@@ -29,9 +28,9 @@ import Text.Hakyll.Internal.Page
29createCustomPage :: String
28createCustomPage :: String
30 -> [FilePath]
29 -> [FilePath]
31 -> [(String, Either String (RenderAction () String))]
30 -> [(String, Either String (RenderAction () String))]
32− -> RenderAction () Context
31+ -> Renderable
33createCustomPage url dependencies association = RenderAction
32createCustomPage url dependencies association = RenderAction
34− { actionDependencies = dependencies
33+ { actionDependencies = dependencies ++ dataDependencies
35 , actionUrl = Just $ return url
34 , actionUrl = Just $ return url
36 , actionFunction = \_ -> M.fromList <$> assoc'
35 , actionFunction = \_ -> M.fromList <$> assoc'
37 }
36 }
@@ -39,6 +38,9 @@ createCustomPage url dependencies association = RenderAction
39 mtuple (a, b) = b >>= \b' -> return (a, b')
38 mtuple (a, b) = b >>= \b' -> return (a, b')
40 toHakyllString = second (either return runRenderAction)
39 toHakyllString = second (either return runRenderAction)
41 assoc' = mapM (mtuple . toHakyllString) $ ("url", Left url) : association
40 assoc' = mapM (mtuple . toHakyllString) $ ("url", Left url) : association
41+ dataDependencies = (map snd association) >>= getDependencies
42+ getDependencies (Left _) = []
43+ getDependencies (Right x) = actionDependencies x
42
44
43-- | A @createCustomPage@ function specialized in creating listings.
45-- | A @createCustomPage@ function specialized in creating listings.
44--
46--
@@ -55,9 +57,9 @@ createCustomPage url dependencies association = RenderAction
55-- > [("title", "Home")] -- ^ Additional context
57-- > [("title", "Home")] -- ^ Additional context
56createListing :: String -- ^ Destination of the page.
58createListing :: String -- ^ Destination of the page.
57 -> FilePath -- ^ Template to render all items with.
59 -> FilePath -- ^ Template to render all items with.
58− -> [RenderAction () Context] -- ^ Renderables in the list.
60+ -> [Renderable] -- ^ Renderables in the list.
59 -> [(String, String)] -- ^ Additional context.
61 -> [(String, String)] -- ^ Additional context.
60− -> RenderAction () Context
62+ -> Renderable
61createListing = createListingWith id
63createListing = createListingWith id
62
64
63-- | A @createCustomPage@ function specialized in creating listings.
65-- | A @createCustomPage@ function specialized in creating listings.
@@ -67,9 +69,9 @@ createListing = createListingWith id
67createListingWith :: ContextManipulation -- ^ Manipulation for the renderables.
69createListingWith :: ContextManipulation -- ^ Manipulation for the renderables.
68 -> String -- ^ Destination of the page.
70 -> String -- ^ Destination of the page.
69 -> FilePath -- ^ Template to render all items with.
71 -> FilePath -- ^ Template to render all items with.
70− -> [RenderAction () Context] -- ^ Renderables in the list.
72+ -> [Renderable] -- ^ Renderables in the list.
71 -> [(String, String)] -- ^ Additional context.
73 -> [(String, String)] -- ^ Additional context.
72− -> RenderAction () Context
74+ -> Renderable
73createListingWith manipulation url template renderables additional =
75createListingWith manipulation url template renderables additional =
74 createCustomPage url dependencies context
76 createCustomPage url dependencies context
75 where
77 where
@@ -79,7 +81,7 @@ createListingWith manipulation url template renderables additional =
79 additional' = map (second Left) additional
81 additional' = map (second Left) additional
80
82
81-- | Create a PagePath from a FilePath.
83-- | Create a PagePath from a FilePath.
82−createPagePath :: FilePath -> RenderAction () Context
84+createPagePath :: FilePath -> Renderable
83createPagePath path = RenderAction
85createPagePath path = RenderAction
84 { actionDependencies = [path]
86 { actionDependencies = [path]
85 , actionUrl = Just $ toUrl path
87 , actionUrl = Just $ toUrl path
@@ -92,8 +94,8 @@ createPagePath path = RenderAction
92--
94--
93-- Since renderables are always more or less key-value maps, you can see
95-- Since renderables are always more or less key-value maps, you can see
94-- this as a @union@ between two maps.
96-- this as a @union@ between two maps.
95−combine :: RenderAction () Context -> RenderAction () Context
97+combine :: Renderable -> Renderable
96− -> RenderAction () Context
98+ -> Renderable
97combine x y = RenderAction
99combine x y = RenderAction
98 { actionDependencies = actionDependencies x ++ actionDependencies y
100 { actionDependencies = actionDependencies x ++ actionDependencies y
99 , actionUrl = actionUrl x `mplus` actionUrl y
101 , actionUrl = actionUrl x `mplus` actionUrl y
@@ -104,9 +106,9 @@ combine x y = RenderAction
104-- | Combine two renderables and set a custom URL. This behaves like @combine@,
106-- | Combine two renderables and set a custom URL. This behaves like @combine@,
105-- except that for the @url@ field, the given URL is always chosen.
107-- except that for the @url@ field, the given URL is always chosen.
106combineWithUrl :: FilePath
108combineWithUrl :: FilePath
107− -> RenderAction () Context
109+ -> Renderable
108− -> RenderAction () Context
110+ -> Renderable
109− -> RenderAction () Context
111+ -> Renderable
110combineWithUrl url x y = combine'
112combineWithUrl url x y = combine'
111 { actionUrl = Just $ return url
113 { actionUrl = Just $ return url
112 , actionFunction = \_ ->
114 , actionFunction = \_ ->
src/Text/Hakyll/Tags.hs+21−15
@@ -45,11 +45,11 @@ import Control.Arrow (second)
45import Control.Applicative ((<$>))
45import Control.Applicative ((<$>))
46import System.FilePath
46import System.FilePath
47
47
48−import Text.Hakyll.Hakyll
49import Text.Hakyll.Context
48import Text.Hakyll.Context
49+import Text.Hakyll.Hakyll
50import Text.Hakyll.Regex
50import Text.Hakyll.Regex
51−import Text.Hakyll.Renderable
52import Text.Hakyll.Renderables
51import Text.Hakyll.Renderables
52+import Text.Hakyll.RenderAction
53import Text.Hakyll.Util
53import Text.Hakyll.Util
54import Text.Hakyll.Internal.Cache
54import Text.Hakyll.Internal.Cache
55import Text.Hakyll.Internal.Template
55import Text.Hakyll.Internal.Template
@@ -59,42 +59,48 @@ import Text.Hakyll.Internal.Template
59-- This is a map associating tags or categories to the appropriate pages
59-- This is a map associating tags or categories to the appropriate pages
60-- using that tag or category. In the case of categories, each path will only
60-- using that tag or category. In the case of categories, each path will only
61-- appear under one category - this is not the case with tags.
61-- appear under one category - this is not the case with tags.
62−type TagMap = M.Map String [PagePath]
62+type TagMap = M.Map String [Renderable]
63
63
64-- | Read a tag map. This is a internally used function that can be used for
64-- | Read a tag map. This is a internally used function that can be used for
65-- tags as well as for categories.
65-- tags as well as for categories.
66readMap :: (Context -> [String]) -- ^ Function to get tags from a context.
66readMap :: (Context -> [String]) -- ^ Function to get tags from a context.
67 -> String -- ^ Unique identifier for the tagmap.
67 -> String -- ^ Unique identifier for the tagmap.
68− -> [PagePath]
68+ -> [FilePath]
69− -> Hakyll TagMap
69+ -> RenderAction () TagMap
70−readMap getTagsFunction identifier paths = do
70+readMap getTagsFunction identifier paths = RenderAction
71− isCacheMoreRecent' <- isCacheMoreRecent fileName (getDependencies =<< paths)
71+ { actionDependencies = paths
72− if isCacheMoreRecent' then M.fromAscList <$> getFromCache fileName
72+ , actionUrl = Nothing
73− else do tagMap <- readTagMap'
73+ , actionFunction = actionFunction'
74− storeInCache (M.toAscList tagMap) fileName
74+ }
75− return tagMap
76 where
75 where
77 fileName = "tagmaps" </> identifier
76 fileName = "tagmaps" </> identifier
78
77
78+ actionFunction' _ = do
79+ isCacheMoreRecent' <- isCacheMoreRecent fileName paths
80+ if isCacheMoreRecent' then M.fromAscList <$> getFromCache fileName
81+ else do tagMap <- readTagMap'
82+ storeInCache (M.toAscList tagMap) fileName
83+ return tagMap
84+
79 readTagMap' = foldM addPaths M.empty paths
85 readTagMap' = foldM addPaths M.empty paths
80 addPaths current path = do
86 addPaths current path = do
81− context <- toContext path
87+ createPagePath path >>>
82 let tags = getTagsFunction context
88 let tags = getTagsFunction context
83 addPaths' = flip (M.insertWith (++)) [path]
89 addPaths' = flip (M.insertWith (++)) [path]
84 return $ foldr addPaths' current tags
90 return $ foldr addPaths' current tags
85
91
86-- | Read a @TagMap@, using the @tags@ metadata field.
92-- | Read a @TagMap@, using the @tags@ metadata field.
87readTagMap :: String -- ^ Unique identifier for the map.
93readTagMap :: String -- ^ Unique identifier for the map.
88− -> [PagePath] -- ^ Paths to get tags from.
94+ -> [FilePath] -- ^ Paths to get tags from.
89 -> Hakyll TagMap
95 -> Hakyll TagMap
90−readTagMap = readMap getTagsFunction
96+readTagMap = readMap getTagsFunction
91 where
97 where
92 getTagsFunction = map trim . splitRegex ","
98 getTagsFunction = map trim . splitRegex ","
93 . fromMaybe [] . M.lookup "tags"
99 . fromMaybe [] . M.lookup "tags"
94
100
95-- | Read a @TagMap@, using the subdirectories the pages are placed in.
101-- | Read a @TagMap@, using the subdirectories the pages are placed in.
96readCategoryMap :: String -- ^ Unique identifier for the map.
102readCategoryMap :: String -- ^ Unique identifier for the map.
97− -> [PagePath] -- ^ Paths to get tags from.
103+ -> [FilePath] -- ^ Paths to get tags from.
98 -> Hakyll TagMap
104 -> Hakyll TagMap
99readCategoryMap = readMap $ maybeToList . M.lookup "category"
105readCategoryMap = readMap $ maybeToList . M.lookup "category"
100
106