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. --- src/Text/Hakyll/Tags.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Text/Hakyll/Tags.hs (limited to 'src/Text') 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