@@ -0,0 +1,21 @@
1+-- | Module containing some specialized functions to deal with tags.
2+module Text.Hakyll.Tags
6+import qualified Data.Map as M
7+import qualified Data.ByteString.Lazy.Char8 as B
10+import Text.Hakyll.Util
11+import Text.Hakyll.Page
13+-- | Read a tag map. This creates a map from tags to page paths. This function
14+-- assumes the tags are located in the `tags` metadata field, separated by
16+readTagMap :: [FilePath] -> IO (M.Map String [FilePath])
17+readTagMap paths = foldM addPaths M.empty paths
18+ where addPaths current path = do
19+ page <- readPage path
20+ let tags = map trim $ split "," $ B.unpack $ getValue ("tags") page
21+ return $ foldr (\t -> M.insertWith (++) t [path]) current tags