blob: 57d37be2a4a0e530dd849f4ecab57ad341a0d652 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
module Hakyll.Util
(
-- * Route utils
dropParentRoute
, modifyDirRoute
, modifyDirRoute_
-- * Context utils
, transformContext
, transformContext_
) where
import Prolog
import Hakyll
import Hakyll.Core.Provider (resourceList)
import Hakyll.Core.Compiler.Internal
import System.FilePath
-- | Drop some number of parent directories
dropParentRoute :: Int -> Routes
dropParentRoute n = modifyDirRoute_ $ drop n
modifyDirRoute :: ([FilePath] -> FilePath) -> Routes
modifyDirRoute f = customRoute $ f . splitDirectories . toFilePath
modifyDirRoute_ :: ([FilePath] -> [FilePath]) -> Routes
modifyDirRoute_ f = modifyDirRoute $ joinPath . f
-- | General contramap
transformContext :: (Item b -> Compiler (Item a)) -> Context a -> Context b
transformContext f (Context c) = Context $ \n args itm -> c n args =<< f itm
-- | Slightly more general contramap
transformContext_ :: (b -> Compiler a) -> Context a -> Context b
transformContext_ = transformContext . traverse
|