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