@@ -7,32 +7,35 @@ module Hakyll.Core.Provider.Internal
7 , resourceExists
7 , resourceExists
8 , resourceMetadataResource
8 , resourceMetadataResource
10 , resourceString
11 , resourceString
11 , resourceLBS
12 , resourceLBS
15--------------------------------------------------------------------------------
16--------------------------------------------------------------------------------
16−import Control.Applicative ((<$>))
17+import Control.Applicative ((<$>))
17−import qualified Data.ByteString.Lazy as BL
18+import qualified Data.ByteString.Lazy as BL
18import Data.IORef
19import Data.IORef
19−import Data.Map (Map)
20+import Data.Map (Map)
20−import qualified Data.Map as M
21+import qualified Data.Map as M
21−import Data.Set (Set)
22+import Data.Set (Set)
22−import qualified Data.Set as S
23+import qualified Data.Set as S
23−import System.FilePath (addExtension)
24+import System.FilePath (addExtension, (</>))
26--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
28+import Hakyll.Core.Identifier
27import Hakyll.Core.Store
29import Hakyll.Core.Store
28import Hakyll.Core.Util.File
30import Hakyll.Core.Util.File
29−import Hakyll.Core.Identifier
32--------------------------------------------------------------------------------
33--------------------------------------------------------------------------------
33-- | Responsible for retrieving and listing resources
34-- | Responsible for retrieving and listing resources
34data Provider = Provider
35data Provider = Provider
36+ { -- Top of the provided directory
37+ providerDirectory :: FilePath
35− { -- | A list of all files found
38+ , -- | A list of all files found
36 providerSet :: Set Identifier
39 providerSet :: Set Identifier
37 , -- | Cache keeping track of modified files
40 , -- | Cache keeping track of modified files
38 providerModifiedCache :: IORef (Map Identifier Bool)
41 providerModifiedCache :: IORef (Map Identifier Bool)
@@ -49,9 +52,9 @@ newProvider :: Store -- ^ Store to use
49 -> IO Provider -- ^ Resulting provider
52 -> IO Provider -- ^ Resulting provider
50newProvider store ignore directory = do
53newProvider store ignore directory = do
51 list <- map fromFilePath . filter (not . ignore) <$>
54 list <- map fromFilePath . filter (not . ignore) <$>
52− getRecursiveContents False directory
55+ getRecursiveContents directory
53 cache <- newIORef M.empty
56 cache <- newIORef M.empty
54− return $ Provider (S.fromList list) cache store
57+ return $ Provider directory (S.fromList list) cache store
57--------------------------------------------------------------------------------
60--------------------------------------------------------------------------------
@@ -74,13 +77,18 @@ resourceMetadataResource =
74 fromFilePath . flip addExtension "metadata" . toFilePath
77 fromFilePath . flip addExtension "metadata" . toFilePath
80+--------------------------------------------------------------------------------
81+resourceFilePath :: Provider -> Identifier -> FilePath
82+resourceFilePath p i = providerDirectory p </> toFilePath i
77--------------------------------------------------------------------------------
85--------------------------------------------------------------------------------
78-- | Get the raw body of a resource as string
86-- | Get the raw body of a resource as string
79−resourceString :: Identifier -> IO String
87+resourceString :: Provider -> Identifier -> IO String
80−resourceString = readFile . toFilePath
88+resourceString p i = readFile $ resourceFilePath p i
83--------------------------------------------------------------------------------
91--------------------------------------------------------------------------------
84-- | Get the raw body of a resource of a lazy bytestring
92-- | Get the raw body of a resource of a lazy bytestring
85−resourceLBS :: Identifier -> IO BL.ByteString
93+resourceLBS :: Provider -> Identifier -> IO BL.ByteString
86−resourceLBS = BL.readFile . toFilePath
94+resourceLBS p i = BL.readFile $ resourceFilePath p i