on master help sign in
Various things...
commit555f510e547cf2496bf909bd578c77f4c3b1a5d5 authorJasper Van der Jeugt <m@jaspervdj.be> dateTue 13 Nov 2012, 23:59 (14 years ago) parent50f8f81
4 files changed+38−33
src/Hakyll/Core/Compiler.hs+24−7 src/Hakyll/Core/Compiler/Require.hs+2−2 src/Hakyll/Core/Dependencies.hs+11−11 src/Hakyll/Core/Metadata.hs+1−13
src/Hakyll/Core/Compiler.hs+24−7
@@ -6,6 +6,8 @@ module Hakyll.Core.Compiler
66 , getIdentifier
77 , getRoute
88 , getRouteFor
9+ , getMetadata
10+ , getMetadataFor
911 , getResourceBody
1012 , getResourceString
1113 , getResourceLBS
@@ -20,22 +22,24 @@ module Hakyll.Core.Compiler
2022
2123
2224--------------------------------------------------------------------------------
23−import Control.Applicative ((<$>))
24−import Data.Binary (Binary)
25−import Data.ByteString.Lazy (ByteString)
26−import Data.Typeable (Typeable)
27−import Prelude hiding (id, (.))
28−import System.Environment (getProgName)
25+import Control.Applicative ((<$>))
26+import Data.Binary (Binary)
27+import Data.ByteString.Lazy (ByteString)
28+import Data.Typeable (Typeable)
29+import Prelude hiding (id, (.))
30+import System.Environment (getProgName)
2931
3032
3133--------------------------------------------------------------------------------
3234import Hakyll.Core.Compiler.Internal
3335import Hakyll.Core.Compiler.Require
36+import Hakyll.Core.Dependencies
3437import Hakyll.Core.Identifier
3538import Hakyll.Core.Logger
39+import Hakyll.Core.Metadata
3640import Hakyll.Core.ResourceProvider
3741import Hakyll.Core.Routes
38−import qualified Hakyll.Core.Store as Store
42+import qualified Hakyll.Core.Store as Store
3943import Hakyll.Core.Writable
4044
4145
@@ -59,6 +63,19 @@ getRouteFor identifier = do
5963 return $ runRoutes routes identifier
6064
6165
66+--------------------------------------------------------------------------------
67+getMetadata :: Compiler Metadata
68+getMetadata = getIdentifier >>= getMetadataFor
69+
70+
71+--------------------------------------------------------------------------------
72+getMetadataFor :: Identifier -> Compiler Metadata
73+getMetadataFor identifier = do
74+ provider <- compilerProvider <$> compilerAsk
75+ compilerTell [IdentifierDependency identifier]
76+ compilerUnsafeIO $ resourceMetadata provider identifier
77+
78+
6279--------------------------------------------------------------------------------
6380-- | Get the body of the underlying resource
6481getResourceBody :: Compiler String
src/Hakyll/Core/Compiler/Require.hs+2−2
@@ -31,7 +31,7 @@ require :: (Binary a, Typeable a) => Identifier -> Compiler a
3131require id' = do
3232 store <- compilerStore <$> compilerAsk
3333
34− compilerTell [Identifier id']
34+ compilerTell [IdentifierDependency id']
3535 compilerResult $ CompilerRequire id' $ do
3636 result <- compilerUnsafeIO $ Store.get store (key id')
3737 case result of
@@ -54,7 +54,7 @@ requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [a]
5454requireAll pattern = do
5555 universe <- compilerUniverse <$> compilerAsk
5656 let matching = filterMatches pattern universe
57− compilerTell [Pattern pattern matching]
57+ compilerTell [PatternDependency pattern matching]
5858 mapM require matching
5959
6060
src/Hakyll/Core/Dependencies.hs+11−11
@@ -32,18 +32,18 @@ import Hakyll.Core.Identifier.Pattern
3232
3333--------------------------------------------------------------------------------
3434data Dependency
35− = Pattern Pattern [Identifier]
36− | Identifier Identifier
35+ = PatternDependency Pattern [Identifier]
36+ | IdentifierDependency Identifier
3737 deriving (Show, Typeable)
3838
3939
4040--------------------------------------------------------------------------------
4141instance Binary Dependency where
42− put (Pattern p is) = putWord8 0 >> put p >> put is
43− put (Identifier i) = putWord8 1 >> put i
42+ put (PatternDependency p is) = putWord8 0 >> put p >> put is
43+ put (IdentifierDependency i) = putWord8 1 >> put i
4444 get = getWord8 >>= \t -> case t of
45− 0 -> Pattern <$> get <*> get
46− 1 -> Identifier <$> get
45+ 0 -> PatternDependency <$> get <*> get
46+ 1 -> IdentifierDependency <$> get
4747 _ -> error "Data.Binary.get: Invalid Dependency"
4848
4949
@@ -89,7 +89,7 @@ dependenciesFor :: Identifier -> DependencyM [Identifier]
8989dependenciesFor id' = do
9090 facts <- dependencyFacts <$> State.get
9191 let relevant = fromMaybe [] $ M.lookup id' facts
92− return [i | Identifier i <- relevant]
92+ return [i | IdentifierDependency i <- relevant]
9393
9494
9595--------------------------------------------------------------------------------
@@ -111,16 +111,16 @@ checkChangedPatterns = do
111111 State.modify $ \s -> s
112112 {dependencyFacts = M.insert id' deps' $ dependencyFacts s}
113113 where
114− go _ ds (Identifier i) = return $ Identifier i : ds
115− go id' ds (Pattern p ls) = do
114+ go _ ds (IdentifierDependency i) = return $ IdentifierDependency i : ds
115+ go id' ds (PatternDependency p ls) = do
116116 universe <- ask
117117 let ls' = filterMatches p universe
118118 if ls == ls'
119− then return $ Pattern p ls : ds
119+ then return $ PatternDependency p ls : ds
120120 else do
121121 tell [show id' ++ " is out-of-date because a pattern changed"]
122122 markOod id'
123− return $ Pattern p ls' : ds
123+ return $ PatternDependency p ls' : ds
124124
125125
126126--------------------------------------------------------------------------------
src/Hakyll/Core/Metadata.hs+1−13
@@ -1,24 +1,12 @@
11--------------------------------------------------------------------------------
22module Hakyll.Core.Metadata
33 ( Metadata
4− , MonadMetadata (..)
54 ) where
65
76
87--------------------------------------------------------------------------------
9−import Data.Map (Map)
10−
11−
12−--------------------------------------------------------------------------------
13−import Hakyll.Core.Identifier
8+import Data.Map (Map)
149
1510
1611--------------------------------------------------------------------------------
1712type Metadata = Map String String
18−
19−
20−--------------------------------------------------------------------------------
21−class MonadMetadata m where
22− identifierMetadata :: Identifier -> m Metadata
23− -- allMetadata :: m [(Resource, Metadata)]
24− -- patternMetadata :: Pattern a -> m [(Resource, Metadata)]