1-- | A store for stroing and retreiving items
3module Hakyll.Core.Store
10import Control.Concurrent.MVar (MVar, newMVar, readMVar, modifyMVar_)
11import System.FilePath ((</>))
12import System.Directory (doesFileExist)
14import qualified Data.Map as M
16import Data.Binary (Binary, encodeFile, decodeFile)
17import Data.Typeable (Typeable)
19import Hakyll.Core.CompiledItem
20import Hakyll.Core.Writable
21import Hakyll.Core.Identifier
22import Hakyll.Core.Util.File
24-- | Data structure used for the store
27 { -- | All items are stored on the filesystem
28 storeDirectory :: FilePath
29 , -- | And some items are also kept in-memory
30 storeMap :: MVar (Map FilePath CompiledItem)
33-- | Initialize the store
35makeStore :: FilePath -> IO Store
36makeStore directory = do
37 mvar <- newMVar M.empty
39 { storeDirectory = directory
43-- | Auxiliary: add an item to the map
45addToMap :: (Binary a, Typeable a, Writable a)
46 => Store -> FilePath -> a -> IO ()
47addToMap store path value =
48 modifyMVar_ (storeMap store) $ return . M.insert path (compiledItem value)
52makePath :: Store -> String -> Identifier -> FilePath
53makePath store name identifier =
54 storeDirectory store </> name </> toFilePath identifier
58storeSet :: (Binary a, Typeable a, Writable a)
59 => Store -> String -> Identifier -> a -> IO ()
60storeSet store name identifier value = do
63 addToMap store path value
65 path = makePath store name identifier
69storeGet :: (Binary a, Typeable a, Writable a)
70 => Store -> String -> Identifier -> IO (Maybe a)
71storeGet store name identifier = do
72 -- First check the in-memory map
73 map' <- readMVar $ storeMap store
74 case M.lookup path map' of
75 -- Found in the in-memory map
76 Just c -> return $ Just $ unCompiledItem c
77 -- Not found in the map, try the filesystem
79 exists <- doesFileExist path
81 -- Not found in the filesystem either
83 -- Found in the filesystem
84 else do v <- decodeFile path
88 path = makePath store name identifier
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list