From beeac9b1011dd57bcc12f316bf9483faa5c38744 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 26 Dec 2009 11:53:25 +0100 Subject: Added module to deal with tags. --- hakyll.cabal | 1 + src/Text/Hakyll/Tags.hs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/Text/Hakyll/Tags.hs 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 -- cgit v1.2.3