hakyll/src/Hakyll/Core/Configuration.hs

74 lines
2.3 KiB
Haskell
Raw Normal View History

2011-02-03 10:34:00 +00:00
-- | Exports a datastructure for the top-level hakyll configuration
--
module Hakyll.Core.Configuration
( HakyllConfiguration (..)
2011-05-16 21:09:06 +00:00
, shouldIgnoreFile
2011-02-03 10:34:00 +00:00
, defaultHakyllConfiguration
) where
2011-02-19 16:04:50 +00:00
import System.FilePath (takeFileName)
import Data.List (isPrefixOf, isSuffixOf)
2011-02-03 10:34:00 +00:00
data HakyllConfiguration = HakyllConfiguration
{ -- | Directory in which the output written
destinationDirectory :: FilePath
, -- | Directory where hakyll's internal store is kept
2011-06-15 06:53:47 +00:00
storeDirectory :: FilePath
2011-02-19 16:04:50 +00:00
, -- | Function to determine ignored files
--
-- In 'defaultHakyllConfiguration', the following files are ignored:
--
-- * files starting with a @.@
--
-- * files ending with a @~@
--
-- * files ending with @.swp@
--
2011-05-16 21:09:06 +00:00
-- Note that the files in @destinationDirectory@ and @storeDirectory@ will
-- also be ignored. Note that this is the configuration parameter, if you
-- want to use the test, you should use @shouldIgnoreFile@.
--
2011-06-15 06:53:47 +00:00
ignoreFile :: FilePath -> Bool
, -- | 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
--
-- > ./hakyll deploy
--
deployCommand :: String
2012-05-12 11:17:20 +00:00
, -- | Use an in-memory cache for items. This is faster but uses more
-- memory.
inMemoryCache :: Bool
2011-02-19 16:04:50 +00:00
}
2011-02-03 10:34:00 +00:00
-- | Default configuration for a hakyll application
--
defaultHakyllConfiguration :: HakyllConfiguration
defaultHakyllConfiguration = HakyllConfiguration
{ destinationDirectory = "_site"
, storeDirectory = "_cache"
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 11:17:20 +00:00
, inMemoryCache = False
2011-02-03 10:34:00 +00:00
}
2011-02-19 16:04:50 +00:00
where
ignoreFile' path
| "." `isPrefixOf` fileName = True
| "~" `isSuffixOf` fileName = True
| ".swp" `isSuffixOf` fileName = True
| otherwise = False
where
fileName = takeFileName path
2011-05-16 21:09:06 +00:00
-- | Check if a file should be ignored
--
shouldIgnoreFile :: HakyllConfiguration -> FilePath -> Bool
shouldIgnoreFile conf path =
destinationDirectory conf `isPrefixOf` path ||
storeDirectory conf `isPrefixOf` path ||
ignoreFile conf path