on 877cb21 help sign in
hakyll/src/Hakyll/Core/Configuration.hs
82 lines 2.9 kB history raw
1--------------------------------------------------------------------------------
2-- | Exports a datastructure for the top-level hakyll configuration
3module Hakyll.Core.Configuration
4 ( Configuration (..)
5 , shouldIgnoreFile
6 , defaultConfiguration
7 ) where
10--------------------------------------------------------------------------------
11import Data.List (isPrefixOf, isSuffixOf)
12import System.FilePath (takeFileName)
15--------------------------------------------------------------------------------
16data Configuration = Configuration
17 { -- | Directory in which the output written
18 destinationDirectory :: FilePath
19 , -- | Directory where hakyll's internal store is kept
20 storeDirectory :: FilePath
21 , -- | Function to determine ignored files
22 --
23 -- In 'defaultHakyllConfiguration', the following files are ignored:
24 --
25 -- * files starting with a @.@
26 --
27 -- * files starting with a @#@
28 --
29 -- * files ending with a @~@
30 --
31 -- * files ending with @.swp@
32 --
33 -- Note that the files in @destinationDirectory@ and @storeDirectory@ will
34 -- also be ignored. Note that this is the configuration parameter, if you
35 -- want to use the test, you should use @shouldIgnoreFile@.
36 --
37 ignoreFile :: FilePath -> Bool
38 , -- | Here, you can plug in a system command to upload/deploy your site.
39 --
40 -- Example:
41 --
42 -- > rsync -ave 'ssh -p 2217' _site jaspervdj@jaspervdj.be:hakyll
43 --
44 -- You can execute this by using
45 --
46 -- > ./hakyll deploy
47 --
48 deployCommand :: String
49 , -- | Use an in-memory cache for items. This is faster but uses more
50 -- memory.
51 inMemoryCache :: Bool
52 }
55--------------------------------------------------------------------------------
56-- | Default configuration for a hakyll application
57defaultConfiguration :: Configuration
58defaultConfiguration = Configuration
59 { destinationDirectory = "_site"
60 , storeDirectory = "_cache"
61 , ignoreFile = ignoreFile'
62 , deployCommand = "echo 'No deploy command specified'"
63 , inMemoryCache = True
64 }
65 where
66 ignoreFile' path
67 | "." `isPrefixOf` fileName = True
68 | "#" `isPrefixOf` fileName = True
69 | "~" `isSuffixOf` fileName = True
70 | ".swp" `isSuffixOf` fileName = True
71 | otherwise = False
72 where
73 fileName = takeFileName path
76--------------------------------------------------------------------------------
77-- | Check if a file should be ignored
78shouldIgnoreFile :: Configuration -> FilePath -> Bool
79shouldIgnoreFile conf path =
80 destinationDirectory conf `isPrefixOf` path ||
81 storeDirectory conf `isPrefixOf` path ||
82 ignoreFile conf path