on master help sign in
Aliased `RenderAction () Context` to Renderable, custompages now have correct dependencies.
commit034c659b91e49f9b4d30cc731fe8972ab36a50ae authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 5 Mar 2010, 16:18 (17 years ago) parent45eb746
5 files changed+45−35
src/Text/Hakyll/Paginate.hs+2−3 src/Text/Hakyll/Render.hs+4−4 src/Text/Hakyll/RenderAction.hs+3 src/Text/Hakyll/Renderables.hs+15−13 src/Text/Hakyll/Tags.hs+21−15
src/Text/Hakyll/Paginate.hs+2−3
@@ -7,7 +7,6 @@ module Text.Hakyll.Paginate
77
88import Control.Applicative ((<$>))
99
10−import Text.Hakyll.Context
1110import Text.Hakyll.Renderables
1211import Text.Hakyll.RenderAction
1312import Text.Hakyll.Util (link)
@@ -50,8 +49,8 @@ defaultPaginateConfiguration = PaginateConfiguration
5049-- without a link. The same goes for when we are on the first or last page for
5150-- @$first@ and @$last@.
5251paginate :: PaginateConfiguration
53− -> [RenderAction () Context]
54− -> [RenderAction () Context]
52+ -> [Renderable]
53+ -> [Renderable]
5554paginate configuration renderables = paginate' Nothing renderables (1 :: Int)
5655 where
5756 -- 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
5656-- * Concatenates the result.
5757--
5858renderAndConcat :: [FilePath] -- ^ Templates to apply on every renderable.
59− -> [RenderAction () Context] -- ^ Renderables to render.
59+ -> [Renderable] -- ^ Renderables to render.
6060 -> RenderAction () String
6161renderAndConcat = renderAndConcatWith id
6262
@@ -65,7 +65,7 @@ renderAndConcat = renderAndConcatWith id
6565-- apply on every @Renderable@.
6666renderAndConcatWith :: ContextManipulation
6767 -> [FilePath]
68− -> [RenderAction () Context]
68+ -> [Renderable]
6969 -> RenderAction () String
7070renderAndConcatWith manipulation templatePaths renderables = RenderAction
7171 { actionDependencies = renders >>= actionDependencies
@@ -91,14 +91,14 @@ renderAndConcatWith manipulation templatePaths renderables = RenderAction
9191--
9292-- This code will first render @warning.html@ using @templates/notice.html@,
9393-- and will then render the result with @templates/default.html@.
94−renderChain :: [FilePath] -> RenderAction () Context -> Hakyll ()
94+renderChain :: [FilePath] -> Renderable -> Hakyll ()
9595renderChain = renderChainWith id
9696
9797-- | A more custom render chain that allows you to specify a
9898-- @ContextManipulation@ which to apply on the context when it is read first.
9999renderChainWith :: ContextManipulation
100100 -> [FilePath]
101− -> RenderAction () Context
101+ -> Renderable
102102 -> Hakyll ()
103103renderChainWith manipulation templatePaths initial =
104104 runRenderActionIfNeeded renderChainWith'
src/Text/Hakyll/RenderAction.hs+3
@@ -7,6 +7,7 @@ module Text.Hakyll.RenderAction
77 , chain
88 , runRenderAction
99 , runRenderActionIfNeeded
10+ , Renderable
1011 ) where
1112
1213import Control.Category
@@ -69,3 +70,5 @@ runRenderActionIfNeeded action = do
6970 valid <- isFileMoreRecent destination $ actionDependencies action
7071 unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination
7172 runRenderAction action
73+
74+type Renderable = RenderAction () Context
src/Text/Hakyll/Renderables.hs+15−13
@@ -12,7 +12,6 @@ import Control.Arrow (second)
1212import Control.Monad (liftM2, mplus)
1313import Control.Applicative ((<$>))
1414
15−
1615import Text.Hakyll.File
1716import Text.Hakyll.Context
1817import Text.Hakyll.RenderAction
@@ -29,9 +28,9 @@ import Text.Hakyll.Internal.Page
2928createCustomPage :: String
3029 -> [FilePath]
3130 -> [(String, Either String (RenderAction () String))]
32− -> RenderAction () Context
31+ -> Renderable
3332createCustomPage url dependencies association = RenderAction
34− { actionDependencies = dependencies
33+ { actionDependencies = dependencies ++ dataDependencies
3534 , actionUrl = Just $ return url
3635 , actionFunction = \_ -> M.fromList <$> assoc'
3736 }
@@ -39,6 +38,9 @@ createCustomPage url dependencies association = RenderAction
3938 mtuple (a, b) = b >>= \b' -> return (a, b')
4039 toHakyllString = second (either return runRenderAction)
4140 assoc' = mapM (mtuple . toHakyllString) $ ("url", Left url) : association
41+ dataDependencies = (map snd association) >>= getDependencies
42+ getDependencies (Left _) = []
43+ getDependencies (Right x) = actionDependencies x
4244
4345-- | A @createCustomPage@ function specialized in creating listings.
4446--
@@ -55,9 +57,9 @@ createCustomPage url dependencies association = RenderAction
5557-- > [("title", "Home")] -- ^ Additional context
5658createListing :: String -- ^ Destination of the page.
5759 -> FilePath -- ^ Template to render all items with.
58− -> [RenderAction () Context] -- ^ Renderables in the list.
60+ -> [Renderable] -- ^ Renderables in the list.
5961 -> [(String, String)] -- ^ Additional context.
60− -> RenderAction () Context
62+ -> Renderable
6163createListing = createListingWith id
6264
6365-- | A @createCustomPage@ function specialized in creating listings.
@@ -67,9 +69,9 @@ createListing = createListingWith id
6769createListingWith :: ContextManipulation -- ^ Manipulation for the renderables.
6870 -> String -- ^ Destination of the page.
6971 -> FilePath -- ^ Template to render all items with.
70− -> [RenderAction () Context] -- ^ Renderables in the list.
72+ -> [Renderable] -- ^ Renderables in the list.
7173 -> [(String, String)] -- ^ Additional context.
72− -> RenderAction () Context
74+ -> Renderable
7375createListingWith manipulation url template renderables additional =
7476 createCustomPage url dependencies context
7577 where
@@ -79,7 +81,7 @@ createListingWith manipulation url template renderables additional =
7981 additional' = map (second Left) additional
8082
8183-- | Create a PagePath from a FilePath.
82−createPagePath :: FilePath -> RenderAction () Context
84+createPagePath :: FilePath -> Renderable
8385createPagePath path = RenderAction
8486 { actionDependencies = [path]
8587 , actionUrl = Just $ toUrl path
@@ -92,8 +94,8 @@ createPagePath path = RenderAction
9294--
9395-- Since renderables are always more or less key-value maps, you can see
9496-- this as a @union@ between two maps.
95−combine :: RenderAction () Context -> RenderAction () Context
96− -> RenderAction () Context
97+combine :: Renderable -> Renderable
98+ -> Renderable
9799combine x y = RenderAction
98100 { actionDependencies = actionDependencies x ++ actionDependencies y
99101 , actionUrl = actionUrl x `mplus` actionUrl y
@@ -104,9 +106,9 @@ combine x y = RenderAction
104106-- | Combine two renderables and set a custom URL. This behaves like @combine@,
105107-- except that for the @url@ field, the given URL is always chosen.
106108combineWithUrl :: FilePath
107− -> RenderAction () Context
108− -> RenderAction () Context
109− -> RenderAction () Context
109+ -> Renderable
110+ -> Renderable
111+ -> Renderable
110112combineWithUrl url x y = combine'
111113 { actionUrl = Just $ return url
112114 , actionFunction = \_ ->
src/Text/Hakyll/Tags.hs+21−15
@@ -45,11 +45,11 @@ import Control.Arrow (second)
4545import Control.Applicative ((<$>))
4646import System.FilePath
4747
48−import Text.Hakyll.Hakyll
4948import Text.Hakyll.Context
49+import Text.Hakyll.Hakyll
5050import Text.Hakyll.Regex
51−import Text.Hakyll.Renderable
5251import Text.Hakyll.Renderables
52+import Text.Hakyll.RenderAction
5353import Text.Hakyll.Util
5454import Text.Hakyll.Internal.Cache
5555import Text.Hakyll.Internal.Template
@@ -59,42 +59,48 @@ import Text.Hakyll.Internal.Template
5959-- This is a map associating tags or categories to the appropriate pages
6060-- using that tag or category. In the case of categories, each path will only
6161-- 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]
6363
6464-- | Read a tag map. This is a internally used function that can be used for
6565-- tags as well as for categories.
6666readMap :: (Context -> [String]) -- ^ Function to get tags from a context.
6767 -> String -- ^ Unique identifier for the tagmap.
68− -> [PagePath]
69− -> Hakyll TagMap
70−readMap getTagsFunction identifier paths = do
71− isCacheMoreRecent' <- isCacheMoreRecent fileName (getDependencies =<< paths)
72− if isCacheMoreRecent' then M.fromAscList <$> getFromCache fileName
73− else do tagMap <- readTagMap'
74− storeInCache (M.toAscList tagMap) fileName
75− return tagMap
68+ -> [FilePath]
69+ -> RenderAction () TagMap
70+readMap getTagsFunction identifier paths = RenderAction
71+ { actionDependencies = paths
72+ , actionUrl = Nothing
73+ , actionFunction = actionFunction'
74+ }
7675 where
7776 fileName = "tagmaps" </> identifier
7877
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+
7985 readTagMap' = foldM addPaths M.empty paths
8086 addPaths current path = do
81− context <- toContext path
87+ createPagePath path >>>
8288 let tags = getTagsFunction context
8389 addPaths' = flip (M.insertWith (++)) [path]
8490 return $ foldr addPaths' current tags
8591
8692-- | Read a @TagMap@, using the @tags@ metadata field.
8793readTagMap :: String -- ^ Unique identifier for the map.
88− -> [PagePath] -- ^ Paths to get tags from.
94+ -> [FilePath] -- ^ Paths to get tags from.
8995 -> Hakyll TagMap
90−readTagMap = readMap getTagsFunction
96+readTagMap = readMap getTagsFunction
9197 where
9298 getTagsFunction = map trim . splitRegex ","
9399 . fromMaybe [] . M.lookup "tags"
94100
95101-- | Read a @TagMap@, using the subdirectories the pages are placed in.
96102readCategoryMap :: String -- ^ Unique identifier for the map.
97− -> [PagePath] -- ^ Paths to get tags from.
103+ -> [FilePath] -- ^ Paths to get tags from.
98104 -> Hakyll TagMap
99105readCategoryMap = readMap $ maybeToList . M.lookup "category"
100106