on master help sign in
Added module to deal with tags.
commitbeeac9b1011dd57bcc12f316bf9483faa5c38744 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 26 Dec 2009, 11:53 (17 years ago) parentc790065
2 files changed+22
hakyll.cabal+1 src/Text/Hakyll/Tags.hs+21
hakyll.cabal+1
@@ -27,3 +27,4 @@ library
2727 Text.Hakyll.File
2828 Text.Hakyll.Page
2929 Text.Hakyll.Util
30+ Text.Hakyll.Tags
src/Text/Hakyll/Tags.hsnew file+21
@@ -0,0 +1,21 @@
1+-- | Module containing some specialized functions to deal with tags.
2+module Text.Hakyll.Tags
3+ ( readTagMap
4+ ) where
5+
6+import qualified Data.Map as M
7+import qualified Data.ByteString.Lazy.Char8 as B
8+import Control.Monad
9+
10+import Text.Hakyll.Util
11+import Text.Hakyll.Page
12+
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
15+-- commas.
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