@@ -0,0 +1,53 @@
1+-- | A store for stroing and retreiving items
3+module Hakyll.Core.Store
10+import Control.Applicative ((<$>))
11+import System.FilePath ((</>))
12+import System.Directory (doesFileExist)
14+import Data.Binary (Binary, encodeFile, decodeFile)
16+import Hakyll.Core.Identifier
17+import Hakyll.Core.Util.File
19+-- | Data structure used for the store
22+ { storeDirectory :: FilePath
25+-- | Initialize the store
27+makeStore :: FilePath -> IO Store
28+makeStore directory = return Store {storeDirectory = directory}
32+makePath :: Store -> String -> Identifier -> FilePath
33+makePath store name identifier =
34+ storeDirectory store </> name </> toFilePath identifier
38+storeSet :: Binary a => Store -> String -> Identifier -> a -> IO ()
39+storeSet store name identifier value = do
41+ encodeFile path value
43+ path = makePath store name identifier
47+storeGet :: Binary a => Store -> String -> Identifier -> IO (Maybe a)
48+storeGet store name identifier = do
49+ exists <- doesFileExist path
50+ if exists then Just <$> decodeFile path
53+ path = makePath store name identifier