diff options
author | Nick McAvoy <nicholas.mcavoy@gmail.com> | 2014-09-16 22:20:11 -0400 |
---|---|---|
committer | Nick McAvoy <nicholas.mcavoy@gmail.com> | 2014-09-16 22:20:11 -0400 |
commit | d0af1024d008113347183024df41c739d7644c02 (patch) | |
tree | 1f8ec14d37109eeb76896574b3207eef001a1ab7 /src | |
parent | 06aa7c4d2e7459b98b841e84b14422bec4208550 (diff) | |
download | hakyll-d0af1024d008113347183024df41c739d7644c02.tar.gz |
matchMetadata for examining metadata when defining rules
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Core/Rules.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index c248a9b..1c8b93c 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -19,6 +19,7 @@ module Hakyll.Core.Rules ( Rules , match + , matchMetadata , create , version , compile @@ -132,6 +133,19 @@ match pattern rules = do -------------------------------------------------------------------------------- +matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules () +matchMetadata pattern metadataPred rules = do + tellPattern pattern + flush + idsAndMetadata <- getAllMetadata pattern + let ids = map fst . filter (metadataPred . snd) $ idsAndMetadata + tellResources ids + Rules $ local (setMatches ids) $ unRules $ rules >> flush + where + setMatches ids env = env {rulesMatches = ids} + + +-------------------------------------------------------------------------------- create :: [Identifier] -> Rules () -> Rules () create ids rules = do flush |