summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Hakyll/Core/Configuration.hs25
-rw-r--r--src/Hakyll/Core/ResourceProvider/FileResourceProvider.hs8
-rw-r--r--src/Hakyll/Core/Run.hs2
-rw-r--r--src/Hakyll/Main.hs4
-rw-r--r--src/Hakyll/Web/Preview/INotify.hs7
5 files changed, 37 insertions, 9 deletions
diff --git a/src/Hakyll/Core/Configuration.hs b/src/Hakyll/Core/Configuration.hs
index 3a7456f..242b68f 100644
--- a/src/Hakyll/Core/Configuration.hs
+++ b/src/Hakyll/Core/Configuration.hs
@@ -5,12 +5,26 @@ module Hakyll.Core.Configuration
, defaultHakyllConfiguration
) where
+import System.FilePath (takeFileName)
+import Data.List (isPrefixOf, isSuffixOf)
+
data HakyllConfiguration = HakyllConfiguration
{ -- | Directory in which the output written
destinationDirectory :: FilePath
, -- | Directory where hakyll's internal store is kept
storeDirectory :: FilePath
- } deriving (Show)
+ , -- | Function to determine ignored files
+ --
+ -- In 'defaultHakyllConfiguration', the following files are ignored:
+ --
+ -- * files starting with a @.@
+ --
+ -- * files ending with a @~@
+ --
+ -- * files ending with @.swp@
+ --
+ ignoreFile :: FilePath -> Bool
+ }
-- | Default configuration for a hakyll application
--
@@ -18,4 +32,13 @@ defaultHakyllConfiguration :: HakyllConfiguration
defaultHakyllConfiguration = HakyllConfiguration
{ destinationDirectory = "_site"
, storeDirectory = "_cache"
+ , ignoreFile = ignoreFile'
}
+ where
+ ignoreFile' path
+ | "." `isPrefixOf` fileName = True
+ | "~" `isSuffixOf` fileName = True
+ | ".swp" `isSuffixOf` fileName = True
+ | otherwise = False
+ where
+ fileName = takeFileName path
diff --git a/src/Hakyll/Core/ResourceProvider/FileResourceProvider.hs b/src/Hakyll/Core/ResourceProvider/FileResourceProvider.hs
index 2f040b3..0d89b21 100644
--- a/src/Hakyll/Core/ResourceProvider/FileResourceProvider.hs
+++ b/src/Hakyll/Core/ResourceProvider/FileResourceProvider.hs
@@ -11,13 +11,15 @@ import qualified Data.ByteString.Lazy as LB
import Hakyll.Core.ResourceProvider
import Hakyll.Core.Identifier
import Hakyll.Core.Util.File
+import Hakyll.Core.Configuration
-- | Create a filesystem-based 'ResourceProvider'
--
-fileResourceProvider :: IO ResourceProvider
-fileResourceProvider = do
+fileResourceProvider :: HakyllConfiguration -> IO ResourceProvider
+fileResourceProvider configuration = do
-- Retrieve a list of identifiers
- list <- map parseIdentifier <$> getRecursiveContents False "."
+ list <- map parseIdentifier . filter (not . ignoreFile configuration) <$>
+ getRecursiveContents False "."
-- Construct a resource provider
return ResourceProvider
diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs
index b59fdac..b4c69f1 100644
--- a/src/Hakyll/Core/Run.hs
+++ b/src/Hakyll/Core/Run.hs
@@ -37,7 +37,7 @@ import Hakyll.Core.Configuration
run :: HakyllConfiguration -> Rules -> IO RuleSet
run configuration rules = do
store <- makeStore $ storeDirectory configuration
- provider <- fileResourceProvider
+ provider <- fileResourceProvider configuration
let ruleSet = runRules rules provider
compilers = rulesCompilers ruleSet
diff --git a/src/Hakyll/Main.hs b/src/Hakyll/Main.hs
index 8cec42e..13ec0dd 100644
--- a/src/Hakyll/Main.hs
+++ b/src/Hakyll/Main.hs
@@ -88,7 +88,9 @@ preview configuration rules port = do
-- Get the resource list and a callback for the preview poll
let resources = rulesResources ruleSet
- callback = build configuration rules
+ callback = do
+ putStrLn "In TL callback"
+ build configuration rules
-- Fork a thread polling for changes
_ <- forkIO $ previewPoll configuration resources callback
diff --git a/src/Hakyll/Web/Preview/INotify.hs b/src/Hakyll/Web/Preview/INotify.hs
index 9af6def..e21b767 100644
--- a/src/Hakyll/Web/Preview/INotify.hs
+++ b/src/Hakyll/Web/Preview/INotify.hs
@@ -8,6 +8,7 @@ import Control.Monad (forM_, when)
import Data.Set (Set)
import qualified Data.Set as S
import System.FilePath (takeDirectory, (</>))
+import Data.List (isPrefixOf)
import System.INotify
@@ -38,9 +39,9 @@ previewPoll _ resources callback = do
notEmpty x = x
-- Execute the callback when path is known
- ifResource path = when (path `S.member` paths) $ do
- putStrLn $ "Changed: " ++ path
- callback
+ ifResource path =
+ let path' = if "./" `isPrefixOf` path then drop 2 path else path
+ in when (path' `S.member` paths) callback
-- Add a watcher for every directory
forM_ directories $ \directory -> do