@@ -25,16 +25,18 @@ module Hakyll.Core.Compiler.Internal
2525
2626
2727--------------------------------------------------------------------------------
28−import Control.Applicative (Alternative (..),
29− Applicative (..))
30−import Control.Exception (SomeException, handle)
31−import Data.Monoid (Monoid (..))
28+import Control.Applicative (Alternative (..),
29+ Applicative (..), (<$>))
30+import Control.Exception (SomeException, handle)
31+import Data.Monoid (Monoid (..))
3232
3333
3434--------------------------------------------------------------------------------
3535import Hakyll.Core.Dependencies
3636import Hakyll.Core.Identifier
37+import Hakyll.Core.Identifier.Pattern
3738import Hakyll.Core.Logger
39+import Hakyll.Core.Metadata
3840import Hakyll.Core.Provider
3941import Hakyll.Core.Routes
4042import Hakyll.Core.Store
@@ -127,6 +129,12 @@ instance Applicative Compiler where
127129 {-# INLINE (<*>) #-}
128130
129131
132+--------------------------------------------------------------------------------
133+instance MonadMetadata Compiler where
134+ getMetadata = compilerGetMetadata
135+ getMatches = compilerGetMatches
136+
137+
130138--------------------------------------------------------------------------------
131139runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
132140runCompiler compiler read' = handle handler $ unCompiler compiler read'
@@ -195,3 +203,20 @@ compilerTellDependencies ds = compilerTell mempty {compilerDependencies = ds}
195203compilerTellCacheHits :: Int -> Compiler ()
196204compilerTellCacheHits ch = compilerTell mempty {compilerCacheHits = ch}
197205{-# INLINE compilerTellCacheHits #-}
206+
207+
208+--------------------------------------------------------------------------------
209+compilerGetMetadata :: Identifier -> Compiler Metadata
210+compilerGetMetadata identifier = do
211+ provider <- compilerProvider <$> compilerAsk
212+ compilerTellDependencies [IdentifierDependency identifier]
213+ compilerUnsafeIO $ resourceMetadata provider identifier
214+
215+
216+--------------------------------------------------------------------------------
217+compilerGetMatches :: Pattern -> Compiler [Identifier]
218+compilerGetMatches pattern = do
219+ universe <- compilerUniverse <$> compilerAsk
220+ let matching = filterMatches pattern universe
221+ compilerTellDependencies [PatternDependency pattern matching]
222+ return matching