diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-03-07 11:18:34 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-03-07 11:18:34 +0100 |
commit | a48b53c385192dd21e4a49269206cdd5cdc45757 (patch) | |
tree | c9a4085233548606d3a5ffede6e11d48f4bd32bf /src/Hakyll/Core | |
parent | be7a5e6afdc983ae2956fafb5c69afd0ebfe2cfe (diff) | |
download | hakyll-a48b53c385192dd21e4a49269206cdd5cdc45757.tar.gz |
Add utility getMetadataField
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r-- | src/Hakyll/Core/Metadata.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Metadata.hs b/src/Hakyll/Core/Metadata.hs index 9fc2d3e..7902b94 100644 --- a/src/Hakyll/Core/Metadata.hs +++ b/src/Hakyll/Core/Metadata.hs @@ -2,6 +2,8 @@ module Hakyll.Core.Metadata ( Metadata , MonadMetadata (..) + , getMetadataField + , getMetadataField' , makePatternDependency ) where @@ -9,6 +11,7 @@ module Hakyll.Core.Metadata -------------------------------------------------------------------------------- import Control.Monad (forM) import Data.Map (Map) +import qualified Data.Map as M -------------------------------------------------------------------------------- @@ -35,6 +38,25 @@ class Monad m => MonadMetadata m where -------------------------------------------------------------------------------- +getMetadataField :: MonadMetadata m => Identifier -> String -> m (Maybe String) +getMetadataField identifier key = do + metadata <- getMetadata identifier + return $ M.lookup key metadata + + +-------------------------------------------------------------------------------- +-- | Version of 'getMetadataField' which throws an error if the field does not +-- exist. +getMetadataField' :: MonadMetadata m => Identifier -> String -> m String +getMetadataField' identifier key = do + field <- getMetadataField identifier key + case field of + Just v -> return v + Nothing -> fail $ "Hakyll.Core.Metadata.getMetadataField': " ++ + "Item " ++ show identifier ++ " has no metadata field " ++ show key + + +-------------------------------------------------------------------------------- makePatternDependency :: MonadMetadata m => Pattern -> m Dependency makePatternDependency pattern = do matches' <- getMatches pattern |