on master help sign in
byIdentifier -> byPattern
75b8c3eJasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+14−14
@@ -111,7 +111,7 @@ module Hakyll.Core.Compiler
111 , traceShowCompiler
111 , traceShowCompiler
112 , mapCompiler
112 , mapCompiler
113 , timedCompiler
113 , timedCompiler
114− , byIdentifier
114+ , byPattern
115 , byExtension
115 , byExtension
116 ) where
116 ) where
117
117
@@ -348,20 +348,19 @@ timedCompiler msg (Compiler d j) = Compiler d $ \x -> CompilerM $ do
348-- For example, assume that most content files need to be compiled
348-- For example, assume that most content files need to be compiled
349-- normally, but a select few need an extra step in the pipeline:
349-- normally, but a select few need an extra step in the pipeline:
350--
350--
351−-- > compile $ pageCompiler
351+-- > compile $ pageCompiler >>> byPattern id
352−-- > >>> byIdentifier id
353−-- > [ ((=="projects.md") . toFilePath, addProjectListCompiler)
352+-- > [ ("projects.md", addProjectListCompiler)
354−-- > , ((=="sitemap.md") . toFilePath, addSiteMapCompiler)
353+-- > , ("sitemap.md", addSiteMapCompiler)
355−-- > ]
354+-- > ]
356--
355--
357−byIdentifier :: Compiler a b -- ^ Default compiler
356+byPattern :: Compiler a b -- ^ Default compiler
358− -> [(Identifier a -> Bool, Compiler a b)] -- ^ Choices
357+ -> [(Pattern (), Compiler a b)] -- ^ Choices
359− -> Compiler a b -- ^ Resulting compiler
358+ -> Compiler a b -- ^ Resulting compiler
360−byIdentifier defaultCompiler choices = Compiler deps job
359+byPattern defaultCompiler choices = Compiler deps job
361 where
360 where
362 -- Lookup the compiler, give an error when it is not found
361 -- Lookup the compiler, give an error when it is not found
363− lookup' identifier =
362+ lookup' identifier = maybe defaultCompiler snd $
364− maybe defaultCompiler snd $ find (\(f,_) -> f identifier) choices
363+ find (\(p, _) -> matches p identifier) choices
365 -- Collect the dependencies of the choice
364 -- Collect the dependencies of the choice
366 deps = do
365 deps = do
367 identifier <- castIdentifier . dependencyIdentifier <$> ask
366 identifier <- castIdentifier . dependencyIdentifier <$> ask
@@ -388,5 +387,6 @@ byIdentifier defaultCompiler choices = Compiler deps job
388byExtension :: Compiler a b -- ^ Default compiler
387byExtension :: Compiler a b -- ^ Default compiler
389 -> [(String, Compiler a b)] -- ^ Choices
388 -> [(String, Compiler a b)] -- ^ Choices
390 -> Compiler a b -- ^ Resulting compiler
389 -> Compiler a b -- ^ Resulting compiler
391−byExtension defaultCompiler = byIdentifier defaultCompiler . map (first cmp)
390+byExtension defaultCompiler = byPattern defaultCompiler . map (first extPattern)
391+ where
392− where cmp c = (==c) . takeExtension . toFilePath
392+ extPattern c = predicate $ (== c) . takeExtension . toFilePath