diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-05-18 18:24:57 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-05-18 18:24:57 +0200 |
commit | 7052768e4bc490d63503f6b7edf7a84bcccdf968 (patch) | |
tree | 2c3fdf868f20da1b8a8327cdb532c1c1a1dc02bd | |
parent | 264aeed33d0bd8772a16fc5461d3bfabcf4eb16a (diff) | |
download | hakyll-7052768e4bc490d63503f6b7edf7a84bcccdf968.tar.gz |
Resource invariant: / as path separator
-rw-r--r-- | src/Hakyll/Core/Compiler.hs | 10 | ||||
-rw-r--r-- | src/Hakyll/Core/Resource.hs | 13 | ||||
-rw-r--r-- | src/Hakyll/Core/Resource/Provider.hs | 16 | ||||
-rw-r--r-- | src/Hakyll/Core/Resource/Provider/Dummy.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Core/Resource/Provider/File.hs | 6 |
5 files changed, 27 insertions, 20 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs index 069c873..99c7d97 100644 --- a/src/Hakyll/Core/Compiler.hs +++ b/src/Hakyll/Core/Compiler.hs @@ -211,12 +211,12 @@ getResourceLBS = getResourceWith resourceLBS -- getResourceWith :: (ResourceProvider -> Resource -> IO a) -> Compiler Resource a -getResourceWith reader = fromJob $ \resource -> CompilerM $ do - let identifier = unResource resource +getResourceWith reader = fromJob $ \r -> CompilerM $ do + let filePath = unResource r provider <- compilerResourceProvider <$> ask - if resourceExists provider resource - then liftIO $ reader provider resource - else throwError $ error' identifier + if resourceExists provider r + then liftIO $ reader provider r + else throwError $ error' filePath where error' id' = "Hakyll.Core.Compiler.getResourceWith: resource " ++ show id' ++ " not found" diff --git a/src/Hakyll/Core/Resource.hs b/src/Hakyll/Core/Resource.hs index ce5da81..566bb26 100644 --- a/src/Hakyll/Core/Resource.hs +++ b/src/Hakyll/Core/Resource.hs @@ -1,7 +1,9 @@ -- | Module exporting the simple 'Resource' type -- module Hakyll.Core.Resource - ( Resource (..) + ( Resource + , unResource + , resource , fromIdentifier , toIdentifier ) where @@ -10,8 +12,13 @@ import Hakyll.Core.Identifier -- | A resource -- -newtype Resource = Resource {unResource :: String} - deriving (Eq, Show, Ord) +newtype Resource = Resource {unResource :: FilePath} + deriving (Eq, Show, Ord) + +-- | Smart constructor to ensure we have @/@ as path separator +-- +resource :: FilePath -> Resource +resource = fromIdentifier . parseIdentifier -- | Create a resource from an identifier -- diff --git a/src/Hakyll/Core/Resource/Provider.hs b/src/Hakyll/Core/Resource/Provider.hs index c3bc9ab..d91c374 100644 --- a/src/Hakyll/Core/Resource/Provider.hs +++ b/src/Hakyll/Core/Resource/Provider.hs @@ -68,17 +68,17 @@ resourceDigest provider = fmap MD5.hashlazy . resourceLBS provider -- | Check if a resource was modified -- resourceModified :: ResourceProvider -> Store -> Resource -> IO Bool -resourceModified provider store resource = do +resourceModified provider store r = do cache <- readMVar mvar - case M.lookup resource cache of + case M.lookup r cache of -- Already in the cache Just m -> return m -- Not yet in the cache, check digests (if it exists) Nothing -> do - m <- if resourceExists provider resource - then digestModified provider store resource + m <- if resourceExists provider r + then digestModified provider store r else return False - modifyMVar_ mvar (return . M.insert resource m) + modifyMVar_ mvar (return . M.insert r m) return m where mvar = resourceModifiedCache provider @@ -86,11 +86,11 @@ resourceModified provider store resource = do -- | Check if a resource digest was modified -- digestModified :: ResourceProvider -> Store -> Resource -> IO Bool -digestModified provider store resource = do +digestModified provider store r = do -- Get the latest seen digest from the store lastDigest <- storeGet store itemName identifier -- Calculate the digest for the resource - newDigest <- resourceDigest provider resource + newDigest <- resourceDigest provider r -- Check digests if Found newDigest == lastDigest -- All is fine, not modified @@ -99,5 +99,5 @@ digestModified provider store resource = do else do storeSet store itemName identifier newDigest return True where - identifier = toIdentifier resource + identifier = toIdentifier r itemName = "Hakyll.Core.ResourceProvider.digestModified" diff --git a/src/Hakyll/Core/Resource/Provider/Dummy.hs b/src/Hakyll/Core/Resource/Provider/Dummy.hs index dad7b0b..548f845 100644 --- a/src/Hakyll/Core/Resource/Provider/Dummy.hs +++ b/src/Hakyll/Core/Resource/Provider/Dummy.hs @@ -19,7 +19,7 @@ import Hakyll.Core.Resource.Provider -- dummyResourceProvider :: Map String ByteString -> IO ResourceProvider dummyResourceProvider vfs = makeResourceProvider - (map Resource (M.keys vfs)) + (map resource (M.keys vfs)) (return . TL.unpack . TL.decodeUtf8 . (vfs M.!) . unResource) (return . (vfs M.!) . unResource) (const getCurrentTime) diff --git a/src/Hakyll/Core/Resource/Provider/File.hs b/src/Hakyll/Core/Resource/Provider/File.hs index abb7ebe..b2172b8 100644 --- a/src/Hakyll/Core/Resource/Provider/File.hs +++ b/src/Hakyll/Core/Resource/Provider/File.hs @@ -22,13 +22,13 @@ import Hakyll.Core.Configuration fileResourceProvider :: HakyllConfiguration -> IO ResourceProvider fileResourceProvider configuration = do -- Retrieve a list of paths - list <- map Resource . filter (not . shouldIgnoreFile configuration) <$> + list <- map resource . filter (not . shouldIgnoreFile configuration) <$> getRecursiveContents False "." makeResourceProvider list (readFile . unResource) (LB.readFile . unResource) - mtime + (mtime . unResource) where - mtime (Resource r) = do + mtime r = do ct <- toCalendarTime =<< getModificationTime r let str = formatCalendarTime defaultTimeLocale "%s" ct return $ readTime defaultTimeLocale "%s" str |