@@ -25,16 +25,18 @@ module Hakyll.Core.Compiler.Internal
27--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
28−import Control.Applicative (Alternative (..),
28+import Control.Applicative (Alternative (..),
29− Applicative (..))
29+ Applicative (..), (<$>))
30−import Control.Exception (SomeException, handle)
30+import Control.Exception (SomeException, handle)
31−import Data.Monoid (Monoid (..))
31+import Data.Monoid (Monoid (..))
34--------------------------------------------------------------------------------
34--------------------------------------------------------------------------------
35import Hakyll.Core.Dependencies
35import Hakyll.Core.Dependencies
36import Hakyll.Core.Identifier
36import Hakyll.Core.Identifier
37+import Hakyll.Core.Identifier.Pattern
37import Hakyll.Core.Logger
38import Hakyll.Core.Logger
39+import Hakyll.Core.Metadata
38import Hakyll.Core.Provider
40import Hakyll.Core.Provider
39import Hakyll.Core.Routes
41import Hakyll.Core.Routes
40import Hakyll.Core.Store
42import Hakyll.Core.Store
@@ -127,6 +129,12 @@ instance Applicative Compiler where
127 {-# INLINE (<*>) #-}
129 {-# INLINE (<*>) #-}
132+--------------------------------------------------------------------------------
133+instance MonadMetadata Compiler where
134+ getMetadata = compilerGetMetadata
135+ getMatches = compilerGetMatches
130--------------------------------------------------------------------------------
138--------------------------------------------------------------------------------
131runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
139runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
132runCompiler compiler read' = handle handler $ unCompiler compiler read'
140runCompiler compiler read' = handle handler $ unCompiler compiler read'
@@ -195,3 +203,20 @@ compilerTellDependencies ds = compilerTell mempty {compilerDependencies = ds}
195compilerTellCacheHits :: Int -> Compiler ()
203compilerTellCacheHits :: Int -> Compiler ()
196compilerTellCacheHits ch = compilerTell mempty {compilerCacheHits = ch}
204compilerTellCacheHits ch = compilerTell mempty {compilerCacheHits = ch}
197{-# INLINE compilerTellCacheHits #-}
205{-# INLINE compilerTellCacheHits #-}
208+--------------------------------------------------------------------------------
209+compilerGetMetadata :: Identifier -> Compiler Metadata
210+compilerGetMetadata identifier = do
211+ provider <- compilerProvider <$> compilerAsk
212+ compilerTellDependencies [IdentifierDependency identifier]
213+ compilerUnsafeIO $ resourceMetadata provider identifier
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]