on master help sign in
Various things...
555f510Jasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+24−7
@@ -6,6 +6,8 @@ module Hakyll.Core.Compiler
6 , getIdentifier
6 , getIdentifier
7 , getRoute
7 , getRoute
8 , getRouteFor
8 , getRouteFor
9+ , getMetadata
10+ , getMetadataFor
9 , getResourceBody
11 , getResourceBody
10 , getResourceString
12 , getResourceString
11 , getResourceLBS
13 , getResourceLBS
@@ -20,22 +22,24 @@ module Hakyll.Core.Compiler
20
22
21
23
22--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
23−import Control.Applicative ((<$>))
25+import Control.Applicative ((<$>))
24−import Data.Binary (Binary)
26+import Data.Binary (Binary)
25−import Data.ByteString.Lazy (ByteString)
27+import Data.ByteString.Lazy (ByteString)
26−import Data.Typeable (Typeable)
28+import Data.Typeable (Typeable)
27−import Prelude hiding (id, (.))
29+import Prelude hiding (id, (.))
28−import System.Environment (getProgName)
30+import System.Environment (getProgName)
29
31
30
32
31--------------------------------------------------------------------------------
33--------------------------------------------------------------------------------
32import Hakyll.Core.Compiler.Internal
34import Hakyll.Core.Compiler.Internal
33import Hakyll.Core.Compiler.Require
35import Hakyll.Core.Compiler.Require
36+import Hakyll.Core.Dependencies
34import Hakyll.Core.Identifier
37import Hakyll.Core.Identifier
35import Hakyll.Core.Logger
38import Hakyll.Core.Logger
39+import Hakyll.Core.Metadata
36import Hakyll.Core.ResourceProvider
40import Hakyll.Core.ResourceProvider
37import Hakyll.Core.Routes
41import Hakyll.Core.Routes
38−import qualified Hakyll.Core.Store as Store
42+import qualified Hakyll.Core.Store as Store
39import Hakyll.Core.Writable
43import Hakyll.Core.Writable
40
44
41
45
@@ -59,6 +63,19 @@ getRouteFor identifier = do
59 return $ runRoutes routes identifier
63 return $ runRoutes routes identifier
60
64
61
65
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+
62--------------------------------------------------------------------------------
79--------------------------------------------------------------------------------
63-- | Get the body of the underlying resource
80-- | Get the body of the underlying resource
64getResourceBody :: Compiler String
81getResourceBody :: Compiler String
src/Hakyll/Core/Compiler/Require.hs+2−2
@@ -31,7 +31,7 @@ require :: (Binary a, Typeable a) => Identifier -> Compiler a
31require id' = do
31require id' = do
32 store <- compilerStore <$> compilerAsk
32 store <- compilerStore <$> compilerAsk
33
33
34− compilerTell [Identifier id']
34+ compilerTell [IdentifierDependency id']
35 compilerResult $ CompilerRequire id' $ do
35 compilerResult $ CompilerRequire id' $ do
36 result <- compilerUnsafeIO $ Store.get store (key id')
36 result <- compilerUnsafeIO $ Store.get store (key id')
37 case result of
37 case result of
@@ -54,7 +54,7 @@ requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [a]
54requireAll pattern = do
54requireAll pattern = do
55 universe <- compilerUniverse <$> compilerAsk
55 universe <- compilerUniverse <$> compilerAsk
56 let matching = filterMatches pattern universe
56 let matching = filterMatches pattern universe
57− compilerTell [Pattern pattern matching]
57+ compilerTell [PatternDependency pattern matching]
58 mapM require matching
58 mapM require matching
59
59
60
60
src/Hakyll/Core/Dependencies.hs+11−11
@@ -32,18 +32,18 @@ import Hakyll.Core.Identifier.Pattern
32
32
33--------------------------------------------------------------------------------
33--------------------------------------------------------------------------------
34data Dependency
34data Dependency
35− = Pattern Pattern [Identifier]
35+ = PatternDependency Pattern [Identifier]
36− | Identifier Identifier
36+ | IdentifierDependency Identifier
37 deriving (Show, Typeable)
37 deriving (Show, Typeable)
38
38
39
39
40--------------------------------------------------------------------------------
40--------------------------------------------------------------------------------
41instance Binary Dependency where
41instance Binary Dependency where
42− put (Pattern p is) = putWord8 0 >> put p >> put is
42+ put (PatternDependency p is) = putWord8 0 >> put p >> put is
43− put (Identifier i) = putWord8 1 >> put i
43+ put (IdentifierDependency i) = putWord8 1 >> put i
44 get = getWord8 >>= \t -> case t of
44 get = getWord8 >>= \t -> case t of
45− 0 -> Pattern <$> get <*> get
45+ 0 -> PatternDependency <$> get <*> get
46− 1 -> Identifier <$> get
46+ 1 -> IdentifierDependency <$> get
47 _ -> error "Data.Binary.get: Invalid Dependency"
47 _ -> error "Data.Binary.get: Invalid Dependency"
48
48
49
49
@@ -89,7 +89,7 @@ dependenciesFor :: Identifier -> DependencyM [Identifier]
89dependenciesFor id' = do
89dependenciesFor id' = do
90 facts <- dependencyFacts <$> State.get
90 facts <- dependencyFacts <$> State.get
91 let relevant = fromMaybe [] $ M.lookup id' facts
91 let relevant = fromMaybe [] $ M.lookup id' facts
92− return [i | Identifier i <- relevant]
92+ return [i | IdentifierDependency i <- relevant]
93
93
94
94
95--------------------------------------------------------------------------------
95--------------------------------------------------------------------------------
@@ -111,16 +111,16 @@ checkChangedPatterns = do
111 State.modify $ \s -> s
111 State.modify $ \s -> s
112 {dependencyFacts = M.insert id' deps' $ dependencyFacts s}
112 {dependencyFacts = M.insert id' deps' $ dependencyFacts s}
113 where
113 where
114− go _ ds (Identifier i) = return $ Identifier i : ds
114+ go _ ds (IdentifierDependency i) = return $ IdentifierDependency i : ds
115− go id' ds (Pattern p ls) = do
115+ go id' ds (PatternDependency p ls) = do
116 universe <- ask
116 universe <- ask
117 let ls' = filterMatches p universe
117 let ls' = filterMatches p universe
118 if ls == ls'
118 if ls == ls'
119− then return $ Pattern p ls : ds
119+ then return $ PatternDependency p ls : ds
120 else do
120 else do
121 tell [show id' ++ " is out-of-date because a pattern changed"]
121 tell [show id' ++ " is out-of-date because a pattern changed"]
122 markOod id'
122 markOod id'
123− return $ Pattern p ls' : ds
123+ return $ PatternDependency p ls' : ds
124
124
125
125
126--------------------------------------------------------------------------------
126--------------------------------------------------------------------------------
src/Hakyll/Core/Metadata.hs+1−13
@@ -1,24 +1,12 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2module Hakyll.Core.Metadata
2module Hakyll.Core.Metadata
3 ( Metadata
3 ( Metadata
4− , MonadMetadata (..)
5 ) where
4 ) where
6
5
7
6
8--------------------------------------------------------------------------------
7--------------------------------------------------------------------------------
9−import Data.Map (Map)
8+import Data.Map (Map)
10−
11−
12−--------------------------------------------------------------------------------
13−import Hakyll.Core.Identifier
14
9
15
10
16--------------------------------------------------------------------------------
11--------------------------------------------------------------------------------
17type Metadata = Map String String
12type 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)]