on master help sign in
Merge pull request #300 from ohbadiah/master
27c3942Jasper Van der Jeugt
src/Hakyll/Core/Rules.hs+14−3
@@ -19,6 +19,7 @@
19module Hakyll.Core.Rules
19module Hakyll.Core.Rules
20 ( Rules
20 ( Rules
21 , match
21 , match
22+ , matchMetadata
22 , create
23 , create
23 , version
24 , version
24 , compile
25 , compile
@@ -120,16 +121,26 @@ flush = Rules $ do
120
121
121
122
122--------------------------------------------------------------------------------
123--------------------------------------------------------------------------------
123−match :: Pattern -> Rules () -> Rules ()
124+matchInternal :: Pattern -> Rules [Identifier] -> Rules () -> Rules ()
124−match pattern rules = do
125+matchInternal pattern getIDs rules = do
125 tellPattern pattern
126 tellPattern pattern
126 flush
127 flush
127− ids <- getMatches pattern
128+ ids <- getIDs
128 tellResources ids
129 tellResources ids
129 Rules $ local (setMatches ids) $ unRules $ rules >> flush
130 Rules $ local (setMatches ids) $ unRules $ rules >> flush
130 where
131 where
131 setMatches ids env = env {rulesMatches = ids}
132 setMatches ids env = env {rulesMatches = ids}
132
133
134+--------------------------------------------------------------------------------
135+match :: Pattern -> Rules () -> Rules ()
136+match pattern = matchInternal pattern $ getMatches pattern
137+
138+
139+--------------------------------------------------------------------------------
140+matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules ()
141+matchMetadata pattern metadataPred = matchInternal pattern $
142+ map fst . filter (metadataPred . snd) <$> getAllMetadata pattern
143+
133
144
134--------------------------------------------------------------------------------
145--------------------------------------------------------------------------------
135create :: [Identifier] -> Rules () -> Rules ()
146create :: [Identifier] -> Rules () -> Rules ()