summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Resource/Provider.hs14
-rw-r--r--src/Hakyll/Core/Resource/Provider/Dummy.hs4
-rw-r--r--src/Hakyll/Core/Resource/Provider/File.hs10
3 files changed, 22 insertions, 6 deletions
diff --git a/src/Hakyll/Core/Resource/Provider.hs b/src/Hakyll/Core/Resource/Provider.hs
index 808719a..c3bc9ab 100644
--- a/src/Hakyll/Core/Resource/Provider.hs
+++ b/src/Hakyll/Core/Resource/Provider.hs
@@ -23,6 +23,7 @@ import Control.Concurrent (MVar, readMVar, modifyMVar_, newMVar)
import Data.Map (Map)
import qualified Data.Map as M
+import Data.Time (UTCTime)
import qualified Crypto.Hash.MD5 as MD5
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB
@@ -34,13 +35,15 @@ import Hakyll.Core.Resource
--
data ResourceProvider = ResourceProvider
{ -- | A list of all resources this provider is able to provide
- resourceList :: [Resource]
+ resourceList :: [Resource]
, -- | Retrieve a certain resource as string
- resourceString :: Resource -> IO String
+ resourceString :: Resource -> IO String
, -- | Retrieve a certain resource as lazy bytestring
- resourceLBS :: Resource -> IO LB.ByteString
+ resourceLBS :: Resource -> IO LB.ByteString
+ , -- | Check when a resource was last modified
+ resourceModificationTime :: Resource -> IO UTCTime
, -- | Cache keeping track of modified items
- resourceModifiedCache :: MVar (Map Resource Bool)
+ resourceModifiedCache :: MVar (Map Resource Bool)
}
-- | Create a resource provider
@@ -48,8 +51,9 @@ data ResourceProvider = ResourceProvider
makeResourceProvider :: [Resource] -- ^ Resource list
-> (Resource -> IO String) -- ^ String reader
-> (Resource -> IO LB.ByteString) -- ^ ByteString reader
+ -> (Resource -> IO UTCTime) -- ^ Time checker
-> IO ResourceProvider -- ^ Resulting provider
-makeResourceProvider l s b = ResourceProvider l s b <$> newMVar M.empty
+makeResourceProvider l s b t = ResourceProvider l s b t <$> newMVar M.empty
-- | Check if a given identifier has a resource
--
diff --git a/src/Hakyll/Core/Resource/Provider/Dummy.hs b/src/Hakyll/Core/Resource/Provider/Dummy.hs
index 9f15178..dad7b0b 100644
--- a/src/Hakyll/Core/Resource/Provider/Dummy.hs
+++ b/src/Hakyll/Core/Resource/Provider/Dummy.hs
@@ -7,9 +7,10 @@ module Hakyll.Core.Resource.Provider.Dummy
import Data.Map (Map)
import qualified Data.Map as M
+import Data.Time (getCurrentTime)
+import Data.ByteString.Lazy (ByteString)
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
-import Data.ByteString.Lazy (ByteString)
import Hakyll.Core.Resource
import Hakyll.Core.Resource.Provider
@@ -21,3 +22,4 @@ dummyResourceProvider vfs = makeResourceProvider
(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 c0e306a..abb7ebe 100644
--- a/src/Hakyll/Core/Resource/Provider/File.hs
+++ b/src/Hakyll/Core/Resource/Provider/File.hs
@@ -6,6 +6,10 @@ module Hakyll.Core.Resource.Provider.File
import Control.Applicative ((<$>))
+import Data.Time (readTime)
+import System.Directory (getModificationTime)
+import System.Locale (defaultTimeLocale)
+import System.Time (formatCalendarTime, toCalendarTime)
import qualified Data.ByteString.Lazy as LB
import Hakyll.Core.Resource
@@ -22,3 +26,9 @@ fileResourceProvider configuration = do
getRecursiveContents False "."
makeResourceProvider list (readFile . unResource)
(LB.readFile . unResource)
+ mtime
+ where
+ mtime (Resource r) = do
+ ct <- toCalendarTime =<< getModificationTime r
+ let str = formatCalendarTime defaultTimeLocale "%s" ct
+ return $ readTime defaultTimeLocale "%s" str