hakyll/src/Hakyll/Core/Provider.hs

46 lines
1.7 KiB
Haskell
Raw Normal View History

2012-10-29 14:01:58 +00:00
--------------------------------------------------------------------------------
2012-11-08 11:45:26 +00:00
-- | This module provides an wrapper API around the file system which does some
-- caching.
2012-11-18 20:56:52 +00:00
module Hakyll.Core.Provider
2012-11-08 11:45:26 +00:00
( -- * Constructing resource providers
2013-02-09 14:11:40 +00:00
Internal.Provider
2012-11-18 20:56:52 +00:00
, newProvider
2012-11-08 11:45:26 +00:00
-- * Querying resource properties
2013-02-09 14:11:40 +00:00
, Internal.resourceList
, Internal.resourceExists
, Internal.resourceModified
, Internal.resourceModificationTime
2012-10-29 14:01:58 +00:00
2012-11-08 11:45:26 +00:00
-- * Access to raw resource content
2013-02-09 14:11:40 +00:00
, Internal.resourceString
, Internal.resourceLBS
2012-11-08 11:45:26 +00:00
-- * Access to metadata and body content
2013-02-09 14:11:40 +00:00
, Internal.resourceMetadata
, Internal.resourceBody
2012-11-08 11:45:26 +00:00
) where
2010-12-31 12:28:31 +00:00
2012-10-29 14:01:58 +00:00
--------------------------------------------------------------------------------
2013-02-09 14:11:40 +00:00
import Control.Monad (forM_)
import qualified Hakyll.Core.Provider.Internal as Internal
2012-11-18 20:56:52 +00:00
import qualified Hakyll.Core.Provider.MetadataCache as Internal
2013-02-09 14:11:40 +00:00
import Hakyll.Core.Store (Store)
2012-10-29 14:01:58 +00:00
--------------------------------------------------------------------------------
2013-02-09 14:11:40 +00:00
-- | Create a resource provider
newProvider :: Store -- ^ Store to use
-> (FilePath -> Bool) -- ^ Should we ignore this file?
-> FilePath -- ^ Search directory
-> IO Internal.Provider -- ^ Resulting provider
newProvider store ignore directory = do
-- Delete metadata cache where necessary
provider <- Internal.newProvider store ignore directory
forM_ (Internal.resourceList provider) $ \identifier ->
if Internal.resourceModified provider identifier
then Internal.resourceInvalidateMetadataCache provider identifier
else return ()
return provider