summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Rules.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2015-01-06 13:42:08 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2015-01-06 13:42:08 +0100
commit27c39423692637a4818d7c19da028cdd92c307ba (patch)
treeb10cfa7382bb59983939b3e3e383e31a35c29a06 /src/Hakyll/Core/Rules.hs
parentff16bd5d1a1af4d852113b98f43500b617f34590 (diff)
parent26113fba0f246643496fec51b0133c9a2a7a4856 (diff)
downloadhakyll-27c39423692637a4818d7c19da028cdd92c307ba.tar.gz
Merge pull request #300 from ohbadiah/master
matchMetadata for examining metadata when defining rules
Diffstat (limited to 'src/Hakyll/Core/Rules.hs')
-rw-r--r--src/Hakyll/Core/Rules.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs
index 1b1e4ae..14befde 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
@@ -120,16 +121,26 @@ flush = Rules $ do
--------------------------------------------------------------------------------
-match :: Pattern -> Rules () -> Rules ()
-match pattern rules = do
+matchInternal :: Pattern -> Rules [Identifier] -> Rules () -> Rules ()
+matchInternal pattern getIDs rules = do
tellPattern pattern
flush
- ids <- getMatches pattern
+ ids <- getIDs
tellResources ids
Rules $ local (setMatches ids) $ unRules $ rules >> flush
where
setMatches ids env = env {rulesMatches = ids}
+--------------------------------------------------------------------------------
+match :: Pattern -> Rules () -> Rules ()
+match pattern = matchInternal pattern $ getMatches pattern
+
+
+--------------------------------------------------------------------------------
+matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules ()
+matchMetadata pattern metadataPred = matchInternal pattern $
+ map fst . filter (metadataPred . snd) <$> getAllMetadata pattern
+
--------------------------------------------------------------------------------
create :: [Identifier] -> Rules () -> Rules ()