summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-26 11:53:25 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-26 11:53:25 +0100
commitbeeac9b1011dd57bcc12f316bf9483faa5c38744 (patch)
tree4358dcd1d9032e98de495823f9748587f3ab3176 /src/Text
parentc790065b464234454773bbe98ab85111634311ae (diff)
downloadhakyll-beeac9b1011dd57bcc12f316bf9483faa5c38744.tar.gz
Added module to deal with tags.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Hakyll/Tags.hs21
1 files changed, 21 insertions, 0 deletions
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