on 792fcdf help sign in
hakyll/src/Hakyll/Core/Configuration.hs
109 lines 4.0 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 Control.Monad (void)
12import Data.Default (Default(..))
13import Data.List (isPrefixOf, isSuffixOf)
14import System.FilePath (normalise, takeFileName)
15import System.Process (system)
18--------------------------------------------------------------------------------
19data Configuration = Configuration
20 { -- | Directory in which the output written
21 destinationDirectory :: FilePath
22 , -- | Directory where hakyll's internal store is kept
23 storeDirectory :: FilePath
24 , -- | Directory in which some temporary files will be kept
25 tmpDirectory :: 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 , -- | Function to deploy the site from Haskell.
58 --
59 -- By default, this command executes the shell command stored in
60 -- 'deployCommand'. If you override it, 'deployCommand' will not
61 -- be used implicitely.
62 --
63 -- The 'Configuration' object is passed as a parameter to this
64 -- function.
65 --
66 deploySite :: Configuration -> IO ()
67 , -- | Use an in-memory cache for items. This is faster but uses more
68 -- memory.
69 inMemoryCache :: Bool
70 }
72--------------------------------------------------------------------------------
73instance Default Configuration where
74 def = defaultConfiguration
76--------------------------------------------------------------------------------
77-- | Default configuration for a hakyll application
78defaultConfiguration :: Configuration
79defaultConfiguration = Configuration
80 { destinationDirectory = "_site"
81 , storeDirectory = "_cache"
82 , tmpDirectory = "_cache/tmp"
83 , providerDirectory = "."
84 , ignoreFile = ignoreFile'
85 , deployCommand = "echo 'No deploy command specified'"
86 , deploySite = void . system . deployCommand
87 , inMemoryCache = True
88 }
89 where
90 ignoreFile' path
91 | "." `isPrefixOf` fileName = True
92 | "#" `isPrefixOf` fileName = True
93 | "~" `isSuffixOf` fileName = True
94 | ".swp" `isSuffixOf` fileName = True
95 | otherwise = False
96 where
97 fileName = takeFileName path
100--------------------------------------------------------------------------------
101-- | Check if a file should be ignored
102shouldIgnoreFile :: Configuration -> FilePath -> Bool
103shouldIgnoreFile conf path =
104 destinationDirectory conf `isPrefixOf` path' ||
105 storeDirectory conf `isPrefixOf` path' ||
106 tmpDirectory conf `isPrefixOf` path' ||
107 ignoreFile conf path'
108 where
109 path' = normalise path