2012-11-13 14:10:01 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2011-02-03 10:34:00 +00:00
|
|
|
-- | Exports a datastructure for the top-level hakyll configuration
|
|
|
|
module Hakyll.Core.Configuration
|
2012-12-31 14:16:14 +00:00
|
|
|
( Configuration (..)
|
2011-05-16 21:09:06 +00:00
|
|
|
, shouldIgnoreFile
|
2012-11-13 14:10:01 +00:00
|
|
|
, defaultConfiguration
|
2011-02-03 10:34:00 +00:00
|
|
|
) where
|
|
|
|
|
2011-02-19 16:04:50 +00:00
|
|
|
|
2012-11-13 14:10:01 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2013-03-07 12:26:56 +00:00
|
|
|
import Data.Default (Default(..))
|
2012-11-21 19:41:19 +00:00
|
|
|
import Data.List (isPrefixOf, isSuffixOf)
|
2012-11-25 09:45:55 +00:00
|
|
|
import System.FilePath (normalise, takeFileName)
|
2012-11-21 19:41:19 +00:00
|
|
|
|
|
|
|
|
2012-11-13 14:10:01 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
data Configuration = Configuration
|
2011-02-03 10:34:00 +00:00
|
|
|
{ -- | Directory in which the output written
|
|
|
|
destinationDirectory :: FilePath
|
|
|
|
, -- | Directory where hakyll's internal store is kept
|
2012-11-13 14:10:01 +00:00
|
|
|
storeDirectory :: FilePath
|
2013-01-06 17:33:00 +00:00
|
|
|
, -- | Directory in which some temporary files will be kept
|
|
|
|
tmpDirectory :: FilePath
|
2012-11-21 19:38:13 +00:00
|
|
|
, -- | Directory where hakyll finds the files to compile. This is @.@ by
|
|
|
|
-- default.
|
|
|
|
providerDirectory :: FilePath
|
2011-02-19 16:04:50 +00:00
|
|
|
, -- | Function to determine ignored files
|
|
|
|
--
|
2012-12-14 12:49:51 +00:00
|
|
|
-- In 'defaultConfiguration', the following files are ignored:
|
2011-02-19 16:04:50 +00:00
|
|
|
--
|
|
|
|
-- * files starting with a @.@
|
|
|
|
--
|
2012-08-12 23:23:04 +00:00
|
|
|
-- * files starting with a @#@
|
|
|
|
--
|
2011-02-19 16:04:50 +00:00
|
|
|
-- * files ending with a @~@
|
|
|
|
--
|
|
|
|
-- * files ending with @.swp@
|
|
|
|
--
|
2012-12-14 12:49:51 +00:00
|
|
|
-- Note that the files in 'destinationDirectory' and 'storeDirectory' will
|
2011-05-16 21:09:06 +00:00
|
|
|
-- also be ignored. Note that this is the configuration parameter, if you
|
2013-02-06 21:40:18 +00:00
|
|
|
-- want to use the test, you should use 'shouldIgnoreFile'.
|
2011-05-16 21:09:06 +00:00
|
|
|
--
|
2012-11-13 14:10:01 +00:00
|
|
|
ignoreFile :: FilePath -> Bool
|
2011-06-15 06:53:47 +00:00
|
|
|
, -- | Here, you can plug in a system command to upload/deploy your site.
|
|
|
|
--
|
|
|
|
-- Example:
|
|
|
|
--
|
|
|
|
-- > rsync -ave 'ssh -p 2217' _site jaspervdj@jaspervdj.be:hakyll
|
|
|
|
--
|
|
|
|
-- You can execute this by using
|
|
|
|
--
|
2012-12-14 12:49:51 +00:00
|
|
|
-- > ./site deploy
|
2011-06-15 06:53:47 +00:00
|
|
|
--
|
2012-11-13 14:10:01 +00:00
|
|
|
deployCommand :: String
|
2012-05-12 11:17:20 +00:00
|
|
|
, -- | Use an in-memory cache for items. This is faster but uses more
|
|
|
|
-- memory.
|
2012-11-13 14:10:01 +00:00
|
|
|
inMemoryCache :: Bool
|
2011-02-19 16:04:50 +00:00
|
|
|
}
|
2011-02-03 10:34:00 +00:00
|
|
|
|
2013-03-07 12:26:56 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2013-03-07 11:13:53 +00:00
|
|
|
instance Default Configuration where
|
2013-03-07 12:34:21 +00:00
|
|
|
def = defaultConfiguration
|
2012-11-13 14:10:01 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2011-02-03 10:34:00 +00:00
|
|
|
-- | Default configuration for a hakyll application
|
2012-11-13 14:10:01 +00:00
|
|
|
defaultConfiguration :: Configuration
|
|
|
|
defaultConfiguration = Configuration
|
2011-02-03 10:34:00 +00:00
|
|
|
{ destinationDirectory = "_site"
|
|
|
|
, storeDirectory = "_cache"
|
2013-01-06 17:33:00 +00:00
|
|
|
, tmpDirectory = "_cache/tmp"
|
2012-11-21 19:38:13 +00:00
|
|
|
, providerDirectory = "."
|
2011-02-19 16:04:50 +00:00
|
|
|
, ignoreFile = ignoreFile'
|
2011-06-15 06:53:47 +00:00
|
|
|
, deployCommand = "echo 'No deploy command specified'"
|
2012-05-12 12:03:43 +00:00
|
|
|
, inMemoryCache = True
|
2011-02-03 10:34:00 +00:00
|
|
|
}
|
2011-02-19 16:04:50 +00:00
|
|
|
where
|
|
|
|
ignoreFile' path
|
2012-08-12 23:23:04 +00:00
|
|
|
| "." `isPrefixOf` fileName = True
|
|
|
|
| "#" `isPrefixOf` fileName = True
|
|
|
|
| "~" `isSuffixOf` fileName = True
|
2011-02-19 16:04:50 +00:00
|
|
|
| ".swp" `isSuffixOf` fileName = True
|
2012-11-25 09:45:55 +00:00
|
|
|
| otherwise = False
|
2011-02-19 16:04:50 +00:00
|
|
|
where
|
|
|
|
fileName = takeFileName path
|
2011-05-16 21:09:06 +00:00
|
|
|
|
2012-11-13 14:10:01 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2011-05-16 21:09:06 +00:00
|
|
|
-- | Check if a file should be ignored
|
2012-11-13 14:10:01 +00:00
|
|
|
shouldIgnoreFile :: Configuration -> FilePath -> Bool
|
2011-05-16 21:09:06 +00:00
|
|
|
shouldIgnoreFile conf path =
|
2012-11-25 09:45:55 +00:00
|
|
|
destinationDirectory conf `isPrefixOf` path' ||
|
|
|
|
storeDirectory conf `isPrefixOf` path' ||
|
2013-01-06 17:33:00 +00:00
|
|
|
tmpDirectory conf `isPrefixOf` path' ||
|
2012-11-25 09:45:55 +00:00
|
|
|
ignoreFile conf path'
|
|
|
|
where
|
|
|
|
path' = normalise path
|