@@ -24,6 +24,8 @@ import qualified Data.Map as M
24import Data.List (intercalate)
24import Data.List (intercalate)
25import Control.Monad (foldM)
25import Control.Monad (foldM)
26import Control.Arrow (second)
26import Control.Arrow (second)
27+import Control.Applicative ((<$>))
28+import System.FilePath ((</>))
28import Text.Hakyll.Hakyll (Hakyll)
30import Text.Hakyll.Hakyll (Hakyll)
29import Text.Hakyll.Context (ContextManipulation, changeValue)
31import Text.Hakyll.Context (ContextManipulation, changeValue)
@@ -31,11 +33,26 @@ import Text.Hakyll.Render.Internal (finalSubstitute)
31import Text.Hakyll.Regex
33import Text.Hakyll.Regex
32import Text.Hakyll.Util
34import Text.Hakyll.Util
33import Text.Hakyll.Page
35import Text.Hakyll.Page
36+import Text.Hakyll.Internal.Cache
35-- | Read a tag map. This creates a map from tags to page paths.
38-- | Read a tag map. This creates a map from tags to page paths.
40+-- You also have to give a unique identifier for every tagmap. This is for
41+-- caching reasons, so the tagmap will be stored in
42+-- @_cache/_tagmap/identifier@.
43+readTagMap :: String -- ^ Unique identifier for the tagmap.
36−readTagMap :: [FilePath] -> Hakyll (M.Map String [FilePath])
45+ -> Hakyll (M.Map String [FilePath])
37−readTagMap paths = foldM addPaths M.empty paths
46+readTagMap identifier paths = do
47+ isCacheMoreRecent' <- isCacheMoreRecent fileName paths
48+ if isCacheMoreRecent' then M.fromList <$> getFromCache fileName
49+ else do tagMap <- readTagMap'
50+ storeInCache (M.toList tagMap) fileName
53+ fileName = "_tagmap" </> identifier
55+ readTagMap' = foldM addPaths M.empty paths
39 addPaths current path = do
56 addPaths current path = do
40 page <- readPage path
57 page <- readPage path
41 let tags = map trim $ splitRegex "," $ getValue "tags" page
58 let tags = map trim $ splitRegex "," $ getValue "tags" page