diff options
| -rw-r--r-- | hakyll.cabal | 1 | ||||
| -rw-r--r-- | src/Text/Hakyll/Tags.hs | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index 3312dc7..0f6d98e 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -27,3 +27,4 @@ library Text.Hakyll.File Text.Hakyll.Page Text.Hakyll.Util + Text.Hakyll.Tags diff --git a/src/Text/Hakyll/Tags.hs b/src/Text/Hakyll/Tags.hs new file mode 100644 index 0000000..98fda86 --- /dev/null +++ b/src/Text/Hakyll/Tags.hs @@ -0,0 +1,21 @@ +-- | Module containing some specialized functions to deal with tags. +module Text.Hakyll.Tags + ( readTagMap + ) where + +import qualified Data.Map as M +import qualified Data.ByteString.Lazy.Char8 as B +import Control.Monad + +import Text.Hakyll.Util +import Text.Hakyll.Page + +-- | Read a tag map. This creates a map from tags to page paths. This function +-- assumes the tags are located in the `tags` metadata field, separated by +-- commas. +readTagMap :: [FilePath] -> IO (M.Map String [FilePath]) +readTagMap paths = foldM addPaths M.empty paths + where addPaths current path = do + page <- readPage path + let tags = map trim $ split "," $ B.unpack $ getValue ("tags") page + return $ foldr (\t -> M.insertWith (++) t [path]) current tags |
