on master help sign in
Remove Resource type
1319bbfJasper Van der Jeugt
hakyll.cabal+6−6
@@ -99,8 +99,8 @@ Library
99 Hakyll.Core.Identifier
99 Hakyll.Core.Identifier
100 Hakyll.Core.Identifier.Pattern
100 Hakyll.Core.Identifier.Pattern
101 Hakyll.Core.Logger
101 Hakyll.Core.Logger
102− Hakyll.Core.Resource
102+ Hakyll.Core.Metadata
103− Hakyll.Core.Resource.Provider
103+ Hakyll.Core.ResourceProvider
104 Hakyll.Core.Routes
104 Hakyll.Core.Routes
105 Hakyll.Core.Rules
105 Hakyll.Core.Rules
106 Hakyll.Core.Run
106 Hakyll.Core.Run
@@ -132,10 +132,10 @@ Library
132 Other-Modules:
132 Other-Modules:
133 Hakyll.Core.Compiler.Internal
133 Hakyll.Core.Compiler.Internal
134 Hakyll.Core.DirectedGraph.Internal
134 Hakyll.Core.DirectedGraph.Internal
135− Hakyll.Core.Resource.Metadata
135+ Hakyll.Core.ResourceProvider.Internal
136+ Hakyll.Core.ResourceProvider.Metadata
136− Hakyll.Core.Resource.MetadataCache
137+ Hakyll.Core.ResourceProvider.MetadataCache
137− Hakyll.Core.Resource.Modified
138+ Hakyll.Core.ResourceProvider.Modified
138− Hakyll.Core.Resource.Provider.Internal
139 Hakyll.Core.Rules.Internal
139 Hakyll.Core.Rules.Internal
140 Hakyll.Web.Page.Internal
140 Hakyll.Web.Page.Internal
141 Hakyll.Web.Template.Internal
141 Hakyll.Web.Template.Internal
src/Hakyll.hs+4−4
@@ -6,8 +6,8 @@ module Hakyll
6 , module Hakyll.Core.Configuration
6 , module Hakyll.Core.Configuration
7 , module Hakyll.Core.Identifier
7 , module Hakyll.Core.Identifier
8 , module Hakyll.Core.Identifier.Pattern
8 , module Hakyll.Core.Identifier.Pattern
9− , module Hakyll.Core.Resource
9+ , module Hakyll.Core.Metadata
10− , module Hakyll.Core.Resource.Provider
10+ , module Hakyll.Core.ResourceProvider
11 , module Hakyll.Core.Routes
11 , module Hakyll.Core.Routes
12 , module Hakyll.Core.Rules
12 , module Hakyll.Core.Rules
13#ifdef UNIX_FILTER
13#ifdef UNIX_FILTER
@@ -42,8 +42,8 @@ import Hakyll.Core.Compiler
42import Hakyll.Core.Configuration
42import Hakyll.Core.Configuration
43import Hakyll.Core.Identifier
43import Hakyll.Core.Identifier
44import Hakyll.Core.Identifier.Pattern
44import Hakyll.Core.Identifier.Pattern
45−import Hakyll.Core.Resource
45+import Hakyll.Core.Metadata
46−import Hakyll.Core.Resource.Provider
46+import Hakyll.Core.ResourceProvider
47import Hakyll.Core.Routes
47import Hakyll.Core.Routes
48import Hakyll.Core.Rules
48import Hakyll.Core.Rules
49#ifdef UNIX_FILTER
49#ifdef UNIX_FILTER
src/Hakyll/Core/Compiler.hs+15−21
@@ -93,7 +93,6 @@ module Hakyll.Core.Compiler
93 ( Compiler
93 ( Compiler
94 , runCompiler
94 , runCompiler
95 , getIdentifier
95 , getIdentifier
96− , getResource
97 , getRoute
96 , getRoute
98 , getRouteFor
97 , getRouteFor
99 , getResourceString
98 , getResourceString
@@ -135,8 +134,7 @@ import Hakyll.Core.Identifier
135import Hakyll.Core.Identifier.Pattern
134import Hakyll.Core.Identifier.Pattern
136import Hakyll.Core.CompiledItem
135import Hakyll.Core.CompiledItem
137import Hakyll.Core.Writable
136import Hakyll.Core.Writable
138−import Hakyll.Core.Resource
137+import Hakyll.Core.ResourceProvider
139−import Hakyll.Core.Resource.Provider
140import Hakyll.Core.Compiler.Internal
138import Hakyll.Core.Compiler.Internal
141import Hakyll.Core.Store (Store)
139import Hakyll.Core.Store (Store)
142import Hakyll.Core.Rules.Internal
140import Hakyll.Core.Rules.Internal
@@ -181,11 +179,6 @@ getIdentifier :: Compiler a (Identifier b)
181getIdentifier = fromJob $ const $ CompilerM $
179getIdentifier = fromJob $ const $ CompilerM $
182 castIdentifier . compilerIdentifier <$> ask
180 castIdentifier . compilerIdentifier <$> ask
183
181
184−-- | Get the resource that is currently being compiled
185−--
186−getResource :: Compiler a Resource
187−getResource = getIdentifier >>> arr fromIdentifier
188−
189-- | Get the route we are using for this item
182-- | Get the route we are using for this item
190--
183--
191getRoute :: Compiler a (Maybe FilePath)
184getRoute :: Compiler a (Maybe FilePath)
@@ -200,22 +193,23 @@ getRouteFor = fromJob $ \identifier -> CompilerM $ do
200
193
201-- | Get the resource we are compiling as a string
194-- | Get the resource we are compiling as a string
202--
195--
203−getResourceString :: Compiler Resource String
196+getResourceString :: Compiler a String
204getResourceString = getResourceWith resourceString
197getResourceString = getResourceWith resourceString
205
198
206-- | Get the resource we are compiling as a lazy bytestring
199-- | Get the resource we are compiling as a lazy bytestring
207--
200--
208−getResourceLBS :: Compiler Resource ByteString
201+getResourceLBS :: Compiler a ByteString
209getResourceLBS = getResourceWith resourceLBS
202getResourceLBS = getResourceWith resourceLBS
210
203
211-- | Overloadable function for 'getResourceString' and 'getResourceLBS'
204-- | Overloadable function for 'getResourceString' and 'getResourceLBS'
212--
205--
213−getResourceWith :: (Resource -> IO a) -> Compiler Resource a
206+getResourceWith :: (Identifier a -> IO b) -> Compiler c b
214−getResourceWith reader = fromJob $ \r -> CompilerM $ do
207+getResourceWith reader = fromJob $ \_ -> CompilerM $ do
215− let filePath = unResource r
216 provider <- compilerResourceProvider <$> ask
208 provider <- compilerResourceProvider <$> ask
209+ r <- compilerIdentifier <$> ask
210+ let filePath = toFilePath r
217 if resourceExists provider r
211 if resourceExists provider r
218− then liftIO $ reader r
212+ then liftIO $ reader $ castIdentifier r
219 else throwError $ error' filePath
213 else throwError $ error' filePath
220 where
214 where
221 error' id' = "Hakyll.Core.Compiler.getResourceWith: resource "
215 error' id' = "Hakyll.Core.Compiler.getResourceWith: resource "
@@ -299,17 +293,17 @@ requireAllA pattern = (id &&& requireAll_ pattern >>>)
299
293
300cached :: (Binary a, Typeable a, Writable a)
294cached :: (Binary a, Typeable a, Writable a)
301 => String
295 => String
302− -> Compiler Resource a
296+ -> Compiler () a
303− -> Compiler Resource a
297+ -> Compiler () a
304cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
298cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
305− logger <- compilerLogger <$> ask
299+ logger <- compilerLogger <$> ask
306 identifier <- castIdentifier . compilerIdentifier <$> ask
300 identifier <- castIdentifier . compilerIdentifier <$> ask
307− store <- compilerStore <$> ask
301+ store <- compilerStore <$> ask
308− modified <- compilerResourceModified <$> ask
302+ modified <- compilerResourceModified <$> ask
309− progName <- liftIO getProgName
303+ progName <- liftIO getProgName
310 report logger $ "Checking cache: " ++ if modified then "modified" else "OK"
304 report logger $ "Checking cache: " ++ if modified then "modified" else "OK"
311 if modified
305 if modified
312− then do v <- unCompilerM $ j $ fromIdentifier identifier
306+ then do v <- unCompilerM $ j ()
313 liftIO $ Store.set store [name, show identifier] v
307 liftIO $ Store.set store [name, show identifier] v
314 return v
308 return v
315 else do v <- liftIO $ Store.get store [name, show identifier]
309 else do v <- liftIO $ Store.get store [name, show identifier]
src/Hakyll/Core/Compiler/Internal.hs+1−1
@@ -26,7 +26,7 @@ import Control.Category (Category, (.), id)
26import Control.Arrow (Arrow, ArrowChoice, arr, first, left)
26import Control.Arrow (Arrow, ArrowChoice, arr, first, left)
27
27
28import Hakyll.Core.Identifier
28import Hakyll.Core.Identifier
29−import Hakyll.Core.Resource.Provider
29+import Hakyll.Core.ResourceProvider
30import Hakyll.Core.Store
30import Hakyll.Core.Store
31import Hakyll.Core.Routes
31import Hakyll.Core.Routes
32import Hakyll.Core.Logger
32import Hakyll.Core.Logger
src/Hakyll/Core/Identifier.hs+13−4
@@ -34,6 +34,7 @@ module Hakyll.Core.Identifier
34 ( Identifier (..)
34 ( Identifier (..)
35 , castIdentifier
35 , castIdentifier
36 , parseIdentifier
36 , parseIdentifier
37+ , fromFilePath
37 , toFilePath
38 , toFilePath
38 , setGroup
39 , setGroup
39 ) where
40 ) where
@@ -77,16 +78,24 @@ castIdentifier :: Identifier a -> Identifier b
77castIdentifier (Identifier g p) = Identifier g p
78castIdentifier (Identifier g p) = Identifier g p
78{-# INLINE castIdentifier #-}
79{-# INLINE castIdentifier #-}
79
80
81+
82+--------------------------------------------------------------------------------
80-- | Parse an identifier from a string
83-- | Parse an identifier from a string
81−--
82parseIdentifier :: String -> Identifier a
84parseIdentifier :: String -> Identifier a
83−parseIdentifier = Identifier Nothing
85+parseIdentifier = Identifier Nothing .
84− . intercalate "/" . filter (not . null) . split'
86+ intercalate "/" . filter (not . null) . split'
85 where
87 where
86 split' = map dropTrailingPathSeparator . splitPath
88 split' = map dropTrailingPathSeparator . splitPath
87
89
90+
91+--------------------------------------------------------------------------------
92+-- | Create an identifier from a filepath
93+fromFilePath :: FilePath -> Identifier a
94+fromFilePath = parseIdentifier
95+
96+
97+--------------------------------------------------------------------------------
88-- | Convert an identifier to a relative 'FilePath'
98-- | Convert an identifier to a relative 'FilePath'
89−--
90toFilePath :: Identifier a -> FilePath
99toFilePath :: Identifier a -> FilePath
91toFilePath = identifierPath
100toFilePath = identifierPath
92
101
src/Hakyll/Core/Metadata.hsnew file+24
@@ -0,0 +1,24 @@
1+--------------------------------------------------------------------------------
2+module Hakyll.Core.Metadata
3+ ( Metadata
4+ , MonadMetadata (..)
5+ ) where
6+
7+
8+--------------------------------------------------------------------------------
9+import Data.Map (Map)
10+
11+
12+--------------------------------------------------------------------------------
13+import Hakyll.Core.Identifier
14+
15+
16+--------------------------------------------------------------------------------
17+type Metadata = Map String String
18+
19+
20+--------------------------------------------------------------------------------
21+class MonadMetadata m where
22+ identifierMetadata :: Identifier a -> m Metadata
23+ -- allMetadata :: m [(Resource, Metadata)]
24+ -- patternMetadata :: Pattern a -> m [(Resource, Metadata)]
src/Hakyll/Core/Resource.hsdeleted−51
@@ -1,51 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Module exporting the simple 'Resource' type
3−module Hakyll.Core.Resource
4− ( -- * Constructing and deconstructing resources
5− Resource
6− , resource
7− , unResource
8−
9− -- * Conversions to and from identifiers
10− , fromIdentifier
11− , toIdentifier
12−
13− -- * TODO: Move me
14− , Metadata
15− ) where
16−
17−
18−--------------------------------------------------------------------------------
19−import Data.Map (Map)
20−
21−
22−--------------------------------------------------------------------------------
23−import Hakyll.Core.Identifier
24−
25−
26−--------------------------------------------------------------------------------
27−-- | A resource
28−newtype Resource = Resource {unResource :: FilePath}
29− deriving (Eq, Show, Ord)
30−
31−
32−--------------------------------------------------------------------------------
33−-- | Smart constructor to ensure we have @/@ as path separator
34−resource :: FilePath -> Resource
35−resource = fromIdentifier . parseIdentifier
36−
37−
38−--------------------------------------------------------------------------------
39−-- | Find the resource for an identifier
40−fromIdentifier :: Identifier a -> Resource
41−fromIdentifier = Resource . toFilePath
42−
43−
44−--------------------------------------------------------------------------------
45−-- | Convert a resource to an identifier
46−toIdentifier :: Resource -> Identifier a
47−toIdentifier = parseIdentifier . unResource
48−
49−
50−--------------------------------------------------------------------------------
51−type Metadata = Map String String
src/Hakyll/Core/Resource/Pattern.hsdeleted−160
@@ -1,160 +0,0 @@
1−--------------------------------------------------------------------------------
2−-- | Module providing pattern matching and capturing on file names.
3−-- 'Pattern's come in two kinds:
4−--
5−-- * Simple glob patterns, like @foo\/*@;
6−--
7−-- * Custom, arbitrary predicates of the type @Identifier -> Bool@.
8−--
9−-- They both have advantages and disadvantages. By default, globs are used,
10−-- unless you construct your 'Pattern' using the 'predicate' function.
11−--
12−-- A very simple pattern could be, for example, @foo\/bar@. This pattern will
13−-- only match the exact @foo\/bar@ identifier.
14−--
15−-- To match more than one identifier, there are different captures that one can
16−-- use:
17−--
18−-- * @*@: matches at most one element of an identifier;
19−--
20−-- * @**@: matches one or more elements of an identifier.
21−--
22−-- Some examples:
23−--
24−-- * @foo\/*@ will match @foo\/bar@ and @foo\/foo@, but not @foo\/bar\/qux@;
25−--
26−-- * @**@ will match any identifier;
27−--
28−-- * @foo\/**@ will match @foo\/bar@ and @foo\/bar\/qux@, but not @bar\/foo@;
29−--
30−-- * @foo\/*.html@ will match all HTML files in the @foo\/@ directory.
31−--
32−-- The 'capture' function allows the user to get access to the elements captured
33−-- by the capture elements in the pattern.
34−--
35−-- Like an 'Identifier', a 'Pattern' also has a type parameter. This is simply
36−-- an extra layer of safety, and can be discarded using the 'castPattern'
37−-- function.
38−module Hakyll.Core.Resource.Pattern
39− ( Pattern
40− , parsePattern
41− , capture
42− ) where
43−
44−
45−--------------------------------------------------------------------------------
46−import Control.Arrow ((&&&), (>>>))
47−import Control.Monad (msum)
48−import Data.List (inits, isPrefixOf, tails)
49−import GHC.Exts (IsString, fromString)
50−
51−
52−--------------------------------------------------------------------------------
53−import Hakyll.Core.Resource
54−
55−
56−--------------------------------------------------------------------------------
57−-- | One base element of a pattern
58−data GlobComponent
59− = Capture
60− | CaptureMany
61− | Literal String
62− deriving (Eq, Show)
63−
64−
65−--------------------------------------------------------------------------------
66−-- | Type that allows matching on identifiers
67−newtype Pattern = Pattern [GlobComponent]
68− deriving (Show)
69−
70−
71−--------------------------------------------------------------------------------
72−instance IsString Pattern where
73− fromString = parsePattern
74−
75−
76−--------------------------------------------------------------------------------
77−-- | Parse a pattern from a string
78−parsePattern :: String -> Pattern
79−parsePattern = Pattern . parse
80− where
81− parse str =
82− let (chunk, rest) = break (`elem` "\\*") str
83− in case rest of
84− ('\\' : x : xs) -> Literal (chunk ++ [x]) : parse xs
85− ('*' : '*' : xs) -> Literal chunk : CaptureMany : parse xs
86− ('*' : xs) -> Literal chunk : Capture : parse xs
87− xs -> Literal chunk : Literal xs : []
88−
89−
90−--------------------------------------------------------------------------------
91−-- | Split a list at every possible point, generate a list of (init, tail)
92−-- cases. The result is sorted with inits decreasing in length.
93−splits :: [a] -> [([a], [a])]
94−splits = inits &&& tails >>> uncurry zip >>> reverse
95−
96−
97−--------------------------------------------------------------------------------
98−-- | Match a glob against a pattern, generating a list of captures
99−capture :: Pattern -> Resource -> Maybe [String]
100−capture (Pattern p) rs = capture' p (unResource rs)
101−
102−
103−--------------------------------------------------------------------------------
104−-- | Internal verion of 'capture'
105−capture' :: [GlobComponent] -> String -> Maybe [String]
106−capture' [] [] = Just [] -- An empty match
107−capture' [] _ = Nothing -- No match
108−capture' (Literal l : ms) str
109− -- Match the literal against the string
110− | l `isPrefixOf` str = capture' ms $ drop (length l) str
111− | otherwise = Nothing
112−capture' (Capture : ms) str =
113− -- Match until the next /
114− let (chunk, rest) = break (== '/') str
115− in msum $ [ fmap (i :) (capture' ms (t ++ rest)) | (i, t) <- splits chunk ]
116−capture' (CaptureMany : ms) str =
117− -- Match everything
118− msum $ [ fmap (i :) (capture' ms t) | (i, t) <- splits str ]
119−
120−
121−--------------------------------------------------------------------------------
122−-- | Create an identifier from a pattern by filling in the captures with a given
123−-- string
124−--
125−-- Example:
126−--
127−-- > fromCapture (parsePattern "tags/*") "foo"
128−--
129−-- Result:
130−--
131−-- > "tags/foo"
132−{-
133−fromCapture :: Pattern -> String -> Identifier
134−fromCapture pattern = fromCaptures pattern . repeat
135−-}
136−
137−
138−--------------------------------------------------------------------------------
139−-- | Create an identifier from a pattern by filling in the captures with the
140−-- given list of strings
141−--
142−{-
143−fromCaptures :: Pattern -> [String] -> String
144−fromCaptures (Pattern p) = fromCaptures' p
145−-}
146−
147−
148−--------------------------------------------------------------------------------
149−-- | Internally used version of 'fromCaptures'
150−{-
151−fromCaptures' :: [GlobComponent] -> [String] -> String
152−fromCaptures' [] _ = mempty
153−fromCaptures' (m : ms) [] = case m of
154− Literal l -> l `mappend` fromCaptures' ms []
155− _ -> error $ "Hakyll.Core.Identifier.Pattern.fromCaptures': "
156− ++ "identifier list exhausted"
157−fromCaptures' (m : ms) ids@(i : is) = case m of
158− Literal l -> l `mappend` fromCaptures' ms ids
159− _ -> i `mappend` fromCaptures' ms is
160−-}
src/Hakyll/Core/Resource/Provider.hs → src/Hakyll/Core/ResourceProvider.hsrenamed+8−7
@@ -1,7 +1,7 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2-- | This module provides an wrapper API around the file system which does some
2-- | This module provides an wrapper API around the file system which does some
3-- caching.
3-- caching.
4−module Hakyll.Core.Resource.Provider
4+module Hakyll.Core.ResourceProvider
5 ( -- * Constructing resource providers
5 ( -- * Constructing resource providers
6 ResourceProvider
6 ResourceProvider
7 , newResourceProvider
7 , newResourceProvider
@@ -23,15 +23,16 @@ module Hakyll.Core.Resource.Provider
23
23
24
24
25--------------------------------------------------------------------------------
25--------------------------------------------------------------------------------
26−import Hakyll.Core.Resource
26+import Hakyll.Core.Identifier
27+import Hakyll.Core.Metadata
28+import Hakyll.Core.ResourceProvider.Internal
27−import qualified Hakyll.Core.Resource.MetadataCache as Internal
29+import qualified Hakyll.Core.ResourceProvider.MetadataCache as Internal
28−import Hakyll.Core.Resource.Modified
30+import Hakyll.Core.ResourceProvider.Modified
29−import Hakyll.Core.Resource.Provider.Internal
30
31
31
32
32--------------------------------------------------------------------------------
33--------------------------------------------------------------------------------
33-- | Wrapper to ensure metadata cache is invalidated if necessary
34-- | Wrapper to ensure metadata cache is invalidated if necessary
34−resourceMetadata :: ResourceProvider -> Resource -> IO Metadata
35+resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata
35resourceMetadata rp r = do
36resourceMetadata rp r = do
36 _ <- resourceModified rp r
37 _ <- resourceModified rp r
37 Internal.resourceMetadata rp r
38 Internal.resourceMetadata rp r
@@ -39,7 +40,7 @@ resourceMetadata rp r = do
39
40
40--------------------------------------------------------------------------------
41--------------------------------------------------------------------------------
41-- | Wrapper to ensure metadata cache is invalidated if necessary
42-- | Wrapper to ensure metadata cache is invalidated if necessary
42−resourceBody :: ResourceProvider -> Resource -> IO String
43+resourceBody :: ResourceProvider -> Identifier a -> IO String
43resourceBody rp r = do
44resourceBody rp r = do
44 _ <- resourceModified rp r
45 _ <- resourceModified rp r
45 Internal.resourceBody rp r
46 Internal.resourceBody rp r
src/Hakyll/Core/Resource/Provider/Internal.hs → src/Hakyll/Core/ResourceProvider/Internal.hsrenamed+16−14
@@ -1,5 +1,5 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−module Hakyll.Core.Resource.Provider.Internal
2+module Hakyll.Core.ResourceProvider.Internal
3 ( ResourceProvider (..)
3 ( ResourceProvider (..)
4 , newResourceProvider
4 , newResourceProvider
5
5
@@ -24,18 +24,18 @@ import System.FilePath (addExtension)
24
24
25
25
26--------------------------------------------------------------------------------
26--------------------------------------------------------------------------------
27−import Hakyll.Core.Resource
28import Hakyll.Core.Store
27import Hakyll.Core.Store
29import Hakyll.Core.Util.File
28import Hakyll.Core.Util.File
29+import Hakyll.Core.Identifier
30
30
31
31
32--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
33-- | Responsible for retrieving and listing resources
33-- | Responsible for retrieving and listing resources
34data ResourceProvider = ResourceProvider
34data ResourceProvider = ResourceProvider
35 { -- | A list of all files found
35 { -- | A list of all files found
36− resourceSet :: Set Resource
36+ resourceSet :: Set (Identifier ())
37 , -- | Cache keeping track of modified files
37 , -- | Cache keeping track of modified files
38− resourceModifiedCache :: IORef (Map Resource Bool)
38+ resourceModifiedCache :: IORef (Map (Identifier ()) Bool)
39 , -- | Underlying persistent store for caching
39 , -- | Underlying persistent store for caching
40 resourceStore :: Store
40 resourceStore :: Store
41 }
41 }
@@ -48,37 +48,39 @@ newResourceProvider :: Store -- ^ Store to use
48 -> FilePath -- ^ Search directory
48 -> FilePath -- ^ Search directory
49 -> IO ResourceProvider -- ^ Resulting provider
49 -> IO ResourceProvider -- ^ Resulting provider
50newResourceProvider store ignore directory = do
50newResourceProvider store ignore directory = do
51− list <- map resource . filter (not . ignore) <$>
51+ list <- map parseIdentifier . filter (not . ignore) <$>
52 getRecursiveContents False directory
52 getRecursiveContents False directory
53 cache <- newIORef M.empty
53 cache <- newIORef M.empty
54 return $ ResourceProvider (S.fromList list) cache store
54 return $ ResourceProvider (S.fromList list) cache store
55
55
56
56
57--------------------------------------------------------------------------------
57--------------------------------------------------------------------------------
58−resourceList :: ResourceProvider -> [Resource]
58+resourceList :: ResourceProvider -> [Identifier ()]
59resourceList = S.toList . resourceSet
59resourceList = S.toList . resourceSet
60
60
61
61
62--------------------------------------------------------------------------------
62--------------------------------------------------------------------------------
63-- | Check if a given resiyrce exists
63-- | Check if a given resiyrce exists
64−resourceExists :: ResourceProvider -> Resource -> Bool
64+resourceExists :: ResourceProvider -> Identifier a -> Bool
65−resourceExists provider = (`S.member` resourceSet provider)
65+resourceExists provider =
66+ (`S.member` resourceSet provider) . setGroup Nothing . castIdentifier
66
67
67
68
68--------------------------------------------------------------------------------
69--------------------------------------------------------------------------------
69-- | Each resource may have an associated metadata resource (with a @.metadata@
70-- | Each resource may have an associated metadata resource (with a @.metadata@
70-- filename)
71-- filename)
71−resourceMetadataResource :: Resource -> Resource
72+resourceMetadataResource :: Identifier a -> Identifier ()
72−resourceMetadataResource = resource . flip addExtension "metadata" . unResource
73+resourceMetadataResource =
74+ parseIdentifier . flip addExtension "metadata" . toFilePath
73
75
74
76
75--------------------------------------------------------------------------------
77--------------------------------------------------------------------------------
76-- | Get the raw body of a resource as string
78-- | Get the raw body of a resource as string
77−resourceString :: Resource -> IO String
79+resourceString :: Identifier a -> IO String
78−resourceString = readFile . unResource
80+resourceString = readFile . toFilePath
79
81
80
82
81--------------------------------------------------------------------------------
83--------------------------------------------------------------------------------
82-- | Get the raw body of a resource of a lazy bytestring
84-- | Get the raw body of a resource of a lazy bytestring
83−resourceLBS :: Resource -> IO BL.ByteString
85+resourceLBS :: Identifier a -> IO BL.ByteString
84−resourceLBS = BL.readFile . unResource
86+resourceLBS = BL.readFile . toFilePath
src/Hakyll/Core/Resource/Metadata.hs → src/Hakyll/Core/ResourceProvider/Metadata.hsrenamed+18−17
@@ -1,42 +1,43 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2-- | Internal module to parse metadata
2-- | Internal module to parse metadata
3−module Hakyll.Core.Resource.Metadata
3+module Hakyll.Core.ResourceProvider.Metadata
4 ( loadMetadata
4 ( loadMetadata
5 ) where
5 ) where
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Control.Applicative ((<$>), (<*), (<*>))
9+import Control.Applicative ((<$>), (<*), (<*>))
10−import Control.Arrow (second)
10+import Control.Arrow (second)
11−import qualified Data.ByteString.Char8 as BC
11+import qualified Data.ByteString.Char8 as BC
12−import qualified Data.Map as M
12+import qualified Data.Map as M
13−import System.IO as IO
13+import System.IO as IO
14−import Text.Parsec ((<?>))
14+import Text.Parsec ((<?>))
15−import qualified Text.Parsec as P
15+import qualified Text.Parsec as P
16−import Text.Parsec.String (Parser)
16+import Text.Parsec.String (Parser)
17
17
18
18
19--------------------------------------------------------------------------------
19--------------------------------------------------------------------------------
20−import Hakyll.Core.Resource
20+import Hakyll.Core.Identifier
21−import Hakyll.Core.Resource.Provider.Internal
21+import Hakyll.Core.Metadata
22+import Hakyll.Core.ResourceProvider.Internal
22import Hakyll.Core.Util.String
23import Hakyll.Core.Util.String
23
24
24
25
25--------------------------------------------------------------------------------
26--------------------------------------------------------------------------------
26−loadMetadata :: ResourceProvider -> Resource -> IO (Metadata, Maybe String)
27+loadMetadata :: ResourceProvider -> Identifier a -> IO (Metadata, Maybe String)
27−loadMetadata rp r = do
28+loadMetadata rp identifier = do
28 hasHeader <- probablyHasMetadataHeader fp
29 hasHeader <- probablyHasMetadataHeader fp
29 (md, body) <- if hasHeader
30 (md, body) <- if hasHeader
30 then second Just <$> loadMetadataHeader fp
31 then second Just <$> loadMetadataHeader fp
31 else return (M.empty, Nothing)
32 else return (M.empty, Nothing)
32
33
33− emd <- if resourceExists rp mr then loadMetadataFile mfp else return M.empty
34+ emd <- if resourceExists rp mi then loadMetadataFile mfp else return M.empty
34
35
35 return (M.union md emd, body)
36 return (M.union md emd, body)
36 where
37 where
37− fp = unResource r
38+ fp = toFilePath identifier
38− mr = resourceMetadataResource r
39+ mi = resourceMetadataResource identifier
39− mfp = unResource mr
40+ mfp = toFilePath mi
40
41
41
42
42--------------------------------------------------------------------------------
43--------------------------------------------------------------------------------
src/Hakyll/Core/Resource/MetadataCache.hs → src/Hakyll/Core/ResourceProvider/MetadataCache.hsrenamed+16−15
@@ -1,5 +1,5 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−module Hakyll.Core.Resource.MetadataCache
2+module Hakyll.Core.ResourceProvider.MetadataCache
3 ( resourceMetadata
3 ( resourceMetadata
4 , resourceBody
4 , resourceBody
5 , resourceInvalidateMetadataCache
5 , resourceInvalidateMetadataCache
@@ -7,39 +7,40 @@ module Hakyll.Core.Resource.MetadataCache
7
7
8
8
9--------------------------------------------------------------------------------
9--------------------------------------------------------------------------------
10−import Hakyll.Core.Resource
10+import Hakyll.Core.Identifier
11−import Hakyll.Core.Resource.Metadata
11+import Hakyll.Core.Metadata
12−import Hakyll.Core.Resource.Provider.Internal
12+import Hakyll.Core.ResourceProvider.Internal
13+import Hakyll.Core.ResourceProvider.Metadata
13−import qualified Hakyll.Core.Store as Store
14+import qualified Hakyll.Core.Store as Store
14
15
15
16
16--------------------------------------------------------------------------------
17--------------------------------------------------------------------------------
17−resourceMetadata :: ResourceProvider -> Resource -> IO Metadata
18+resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata
18resourceMetadata rp r = do
19resourceMetadata rp r = do
19 load rp r
20 load rp r
20 Store.Found md <- Store.get (resourceStore rp)
21 Store.Found md <- Store.get (resourceStore rp)
21− [name, unResource r, "metadata"]
22+ [name, toFilePath r, "metadata"]
22 return md
23 return md
23
24
24
25
25--------------------------------------------------------------------------------
26--------------------------------------------------------------------------------
26−resourceBody :: ResourceProvider -> Resource -> IO String
27+resourceBody :: ResourceProvider -> Identifier a -> IO String
27resourceBody rp r = do
28resourceBody rp r = do
28 load rp r
29 load rp r
29 Store.Found bd <- Store.get (resourceStore rp)
30 Store.Found bd <- Store.get (resourceStore rp)
30− [name, unResource r, "body"]
31+ [name, toFilePath r, "body"]
31 maybe (resourceString r) return bd
32 maybe (resourceString r) return bd
32
33
33
34
34--------------------------------------------------------------------------------
35--------------------------------------------------------------------------------
35−resourceInvalidateMetadataCache :: ResourceProvider -> Resource -> IO ()
36+resourceInvalidateMetadataCache :: ResourceProvider -> Identifier a -> IO ()
36resourceInvalidateMetadataCache rp r = do
37resourceInvalidateMetadataCache rp r = do
37− Store.delete (resourceStore rp) [name, unResource r, "metadata"]
38+ Store.delete (resourceStore rp) [name, toFilePath r, "metadata"]
38− Store.delete (resourceStore rp) [name, unResource r, "body"]
39+ Store.delete (resourceStore rp) [name, toFilePath r, "body"]
39
40
40
41
41--------------------------------------------------------------------------------
42--------------------------------------------------------------------------------
42−load :: ResourceProvider -> Resource -> IO ()
43+load :: ResourceProvider -> Identifier a -> IO ()
43load rp r = do
44load rp r = do
44 mmd <- Store.get store mdk :: IO (Store.Result Metadata)
45 mmd <- Store.get store mdk :: IO (Store.Result Metadata)
45 case mmd of
46 case mmd of
@@ -52,8 +53,8 @@ load rp r = do
52 Store.set store bk body
53 Store.set store bk body
53 where
54 where
54 store = resourceStore rp
55 store = resourceStore rp
55− mdk = [name, unResource r, "metadata"]
56+ mdk = [name, toFilePath r, "metadata"]
56− bk = [name, unResource r, "body"]
57+ bk = [name, toFilePath r, "body"]
57
58
58
59
59--------------------------------------------------------------------------------
60--------------------------------------------------------------------------------
src/Hakyll/Core/Resource/Modified.hs → src/Hakyll/Core/ResourceProvider/Modified.hsrenamed+24−23
@@ -1,55 +1,56 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−module Hakyll.Core.Resource.Modified
2+module Hakyll.Core.ResourceProvider.Modified
3 ( resourceModified
3 ( resourceModified
4 , resourceModificationTime
4 , resourceModificationTime
5 ) where
5 ) where
6
6
7
7
8--------------------------------------------------------------------------------
8--------------------------------------------------------------------------------
9−import Control.Applicative ((<$>), (<*>))
9+import Control.Applicative ((<$>), (<*>))
10−import Control.Monad (when)
10+import Control.Monad (when)
11−import qualified Crypto.Hash.MD5 as MD5
11+import qualified Crypto.Hash.MD5 as MD5
12−import qualified Data.ByteString as B
12+import qualified Data.ByteString as B
13−import qualified Data.ByteString.Lazy as BL
13+import qualified Data.ByteString.Lazy as BL
14import Data.IORef
14import Data.IORef
15−import qualified Data.Map as M
15+import qualified Data.Map as M
16−import Data.Time (UTCTime)
16+import Data.Time (UTCTime)
17−import System.Directory (getModificationTime)
17+import System.Directory (getModificationTime)
18
18
19
19
20--------------------------------------------------------------------------------
20--------------------------------------------------------------------------------
21−import Hakyll.Core.Resource
21+import Hakyll.Core.Identifier
22+import Hakyll.Core.ResourceProvider.Internal
22−import Hakyll.Core.Resource.MetadataCache
23+import Hakyll.Core.ResourceProvider.MetadataCache
23−import Hakyll.Core.Resource.Provider.Internal
24+import Hakyll.Core.Store (Store)
24−import Hakyll.Core.Store (Store)
25−import qualified Hakyll.Core.Store as Store
25+import qualified Hakyll.Core.Store as Store
26
26
27
27
28--------------------------------------------------------------------------------
28--------------------------------------------------------------------------------
29-- | A resource is modified if it or its metadata has changed
29-- | A resource is modified if it or its metadata has changed
30−resourceModified :: ResourceProvider -> Resource -> IO Bool
30+resourceModified :: ResourceProvider -> Identifier a -> IO Bool
31resourceModified rp r
31resourceModified rp r
32 | not exists = return False
32 | not exists = return False
33 | otherwise = do
33 | otherwise = do
34 cache <- readIORef cacheRef
34 cache <- readIORef cacheRef
35− case M.lookup r cache of
35+ case M.lookup normalized cache of
36 Just m -> return m
36 Just m -> return m
37 Nothing -> do
37 Nothing -> do
38 -- Check if the actual file was modified, and do a recursive
38 -- Check if the actual file was modified, and do a recursive
39 -- call to check if the metadata file was modified
39 -- call to check if the metadata file was modified
40 m <- (||)
40 m <- (||)
41− <$> fileDigestModified store (unResource r)
41+ <$> fileDigestModified store (toFilePath r)
42 <*> resourceModified rp (resourceMetadataResource r)
42 <*> resourceModified rp (resourceMetadataResource r)
43− modifyIORef cacheRef (M.insert r m)
43+ modifyIORef cacheRef (M.insert normalized m)
44
44
45 -- Important! (But ugly)
45 -- Important! (But ugly)
46 when m $ resourceInvalidateMetadataCache rp r
46 when m $ resourceInvalidateMetadataCache rp r
47
47
48 return m
48 return m
49 where
49 where
50+ normalized = castIdentifier $ setGroup Nothing r
50− exists = resourceExists rp r
51+ exists = resourceExists rp r
51− store = resourceStore rp
52+ store = resourceStore rp
52− cacheRef = resourceModifiedCache rp
53+ cacheRef = resourceModifiedCache rp
53
54
54
55
55--------------------------------------------------------------------------------
56--------------------------------------------------------------------------------
@@ -78,5 +79,5 @@ fileDigest = fmap MD5.hashlazy . BL.readFile
78
79
79
80
80--------------------------------------------------------------------------------
81--------------------------------------------------------------------------------
81−resourceModificationTime :: Resource -> IO UTCTime
82+resourceModificationTime :: Identifier a -> IO UTCTime
82−resourceModificationTime = getModificationTime . unResource
83+resourceModificationTime = getModificationTime . toFilePath
src/Hakyll/Core/Rules.hs+11−16
@@ -51,11 +51,9 @@ import Hakyll.Core.CompiledItem
51import Hakyll.Core.Compiler.Internal
51import Hakyll.Core.Compiler.Internal
52import Hakyll.Core.Identifier
52import Hakyll.Core.Identifier
53import Hakyll.Core.Identifier.Pattern
53import Hakyll.Core.Identifier.Pattern
54−import Hakyll.Core.Resource
54+import Hakyll.Core.ResourceProvider
55−import Hakyll.Core.Resource.Provider
56import Hakyll.Core.Routes
55import Hakyll.Core.Routes
57import Hakyll.Core.Rules.Internal
56import Hakyll.Core.Rules.Internal
58−import Hakyll.Core.Util.Arrow
59import Hakyll.Core.Writable
57import Hakyll.Core.Writable
60
58
61
59
@@ -80,10 +78,10 @@ tellCompilers compilers = RulesM $ do
80
78
81--------------------------------------------------------------------------------
79--------------------------------------------------------------------------------
82-- | Add resources
80-- | Add resources
83−tellResources :: [Resource]
81+tellResources :: [Identifier a]
84 -> Rules
82 -> Rules
85tellResources resources' = RulesM $ tell $
83tellResources resources' = RulesM $ tell $
86− RuleSet mempty mempty $ S.fromList resources'
84+ RuleSet mempty mempty $ S.fromList $ map castIdentifier resources'
87
85
88
86
89--------------------------------------------------------------------------------
87--------------------------------------------------------------------------------
@@ -139,13 +137,12 @@ group g = RulesM . local setGroup' . unRulesM
139-- no resources match the current selection, nothing will happen. In this case,
137-- no resources match the current selection, nothing will happen. In this case,
140-- you might want to have a look at 'create'.
138-- you might want to have a look at 'create'.
141compile :: (Binary a, Typeable a, Writable a)
139compile :: (Binary a, Typeable a, Writable a)
142− => Compiler Resource a -> RulesM (Pattern a)
140+ => Compiler () a -> RulesM (Pattern a)
143compile compiler = do
141compile compiler = do
144 ids <- resources
142 ids <- resources
145− tellCompilers $ flip map ids $ \identifier ->
143+ tellCompilers [(castIdentifier id', compiler) | id' <- ids]
146− (identifier, constA (fromIdentifier identifier) >>> compiler)
147− tellResources $ map fromIdentifier ids
144+ tellResources ids
148− return $ list ids
145+ return $ list $ map castIdentifier ids
149
146
150
147
151--------------------------------------------------------------------------------
148--------------------------------------------------------------------------------
@@ -182,14 +179,12 @@ route route' = RulesM $ do
182--------------------------------------------------------------------------------
179--------------------------------------------------------------------------------
183-- | Get a list of resources matching the current pattern. This will also set
180-- | Get a list of resources matching the current pattern. This will also set
184-- the correct group to the identifiers.
181-- the correct group to the identifiers.
185−resources :: RulesM [Identifier a]
182+resources :: RulesM [Identifier ()]
186resources = RulesM $ do
183resources = RulesM $ do
187− pattern <- rulesPattern <$> ask
184+ pattern <- rulesPattern <$> ask
188 provider <- rulesResourceProvider <$> ask
185 provider <- rulesResourceProvider <$> ask
189− group' <- rulesGroup <$> ask
186+ g <- rulesGroup <$> ask
190− return $ filterMatches pattern $ map (toId group') $ resourceList provider
187+ return $ filterMatches pattern $ map (setGroup g) $ resourceList provider
191− where
192− toId g = setGroup g . toIdentifier
193
188
194
189
195--------------------------------------------------------------------------------
190--------------------------------------------------------------------------------
src/Hakyll/Core/Rules/Internal.hs+3−4
@@ -26,8 +26,7 @@ import Hakyll.Core.CompiledItem
26import Hakyll.Core.Compiler.Internal
26import Hakyll.Core.Compiler.Internal
27import Hakyll.Core.Identifier
27import Hakyll.Core.Identifier
28import Hakyll.Core.Identifier.Pattern
28import Hakyll.Core.Identifier.Pattern
29−import Hakyll.Core.Resource
29+import Hakyll.Core.ResourceProvider
30−import Hakyll.Core.Resource.Provider
31import Hakyll.Core.Routes
30import Hakyll.Core.Routes
32
31
33
32
@@ -49,8 +48,8 @@ data RuleSet = RuleSet
49 rulesRoutes :: Routes
48 rulesRoutes :: Routes
50 , -- | Compilation rules
49 , -- | Compilation rules
51 rulesCompilers :: [(Identifier (), Compiler () CompileRule)]
50 rulesCompilers :: [(Identifier (), Compiler () CompileRule)]
52− , -- | A list of the used resources
51+ , -- | A set of the actually used files
53− rulesResources :: Set Resource
52+ rulesResources :: Set (Identifier ())
54 }
53 }
55
54
56
55
src/Hakyll/Core/Run.hs+3−4
@@ -25,8 +25,7 @@ import Hakyll.Core.DependencyAnalyzer
25import Hakyll.Core.DirectedGraph
25import Hakyll.Core.DirectedGraph
26import Hakyll.Core.Identifier
26import Hakyll.Core.Identifier
27import Hakyll.Core.Logger
27import Hakyll.Core.Logger
28−import Hakyll.Core.Resource
28+import Hakyll.Core.ResourceProvider
29−import Hakyll.Core.Resource.Provider
30import Hakyll.Core.Routes
29import Hakyll.Core.Routes
31import Hakyll.Core.Rules.Internal
30import Hakyll.Core.Rules.Internal
32import Hakyll.Core.Store (Store)
31import Hakyll.Core.Store (Store)
@@ -132,7 +131,7 @@ addNewCompilers newCompilers = Runtime $ do
132
131
133 -- Check which items have been modified
132 -- Check which items have been modified
134 modified <- fmap S.fromList $ flip filterM (map fst newCompilers) $
133 modified <- fmap S.fromList $ flip filterM (map fst newCompilers) $
135− liftIO . resourceModified provider . fromIdentifier
134+ liftIO . resourceModified provider
136 let checkModified = if firstRun then const True else (`S.member` modified)
135 let checkModified = if firstRun then const True else (`S.member` modified)
137
136
138 -- Create a new analyzer and append it to the currect one
137 -- Create a new analyzer and append it to the currect one
@@ -183,7 +182,7 @@ build id' = Runtime $ do
183 let compiler = compilers M.! id'
182 let compiler = compilers M.! id'
184
183
185 -- Check if the resource was modified
184 -- Check if the resource was modified
186− isModified <- liftIO $ resourceModified provider $ fromIdentifier id'
185+ isModified <- liftIO $ resourceModified provider id'
187
186
188 -- Run the compiler
187 -- Run the compiler
189 result <- timed logger "Total compile time" $ liftIO $
188 result <- timed logger "Total compile time" $ liftIO $
src/Hakyll/Core/Writable/CopyFile.hs+13−6
@@ -1,29 +1,36 @@
1+--------------------------------------------------------------------------------
1-- | Exports simple compilers to just copy files
2-- | Exports simple compilers to just copy files
2−--
3{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
4module Hakyll.Core.Writable.CopyFile
4module Hakyll.Core.Writable.CopyFile
5 ( CopyFile (..)
5 ( CopyFile (..)
6 , copyFileCompiler
6 , copyFileCompiler
7 ) where
7 ) where
8
8
9+
10+--------------------------------------------------------------------------------
9import Control.Arrow ((>>^))
11import Control.Arrow ((>>^))
10import System.Directory (copyFile)
12import System.Directory (copyFile)
11−
12import Data.Typeable (Typeable)
13import Data.Typeable (Typeable)
13import Data.Binary (Binary)
14import Data.Binary (Binary)
14
15
15−import Hakyll.Core.Resource
16+
17+--------------------------------------------------------------------------------
16import Hakyll.Core.Writable
18import Hakyll.Core.Writable
17import Hakyll.Core.Compiler
19import Hakyll.Core.Compiler
18import Hakyll.Core.Identifier
20import Hakyll.Core.Identifier
19
21
22+
23+--------------------------------------------------------------------------------
20-- | Newtype construct around 'FilePath' which will copy the file directly
24-- | Newtype construct around 'FilePath' which will copy the file directly
21−--
22newtype CopyFile = CopyFile {unCopyFile :: FilePath}
25newtype CopyFile = CopyFile {unCopyFile :: FilePath}
23− deriving (Show, Eq, Ord, Binary, Typeable)
26+ deriving (Show, Eq, Ord, Binary, Typeable)
27+
24
28
29+--------------------------------------------------------------------------------
25instance Writable CopyFile where
30instance Writable CopyFile where
26 write dst (CopyFile src) = copyFile src dst
31 write dst (CopyFile src) = copyFile src dst
27
32
33+
34+--------------------------------------------------------------------------------
28−copyFileCompiler :: Compiler Resource CopyFile
35+copyFileCompiler :: Compiler a CopyFile
29copyFileCompiler = getIdentifier >>^ CopyFile . toFilePath
36copyFileCompiler = getIdentifier >>^ CopyFile . toFilePath
src/Hakyll/Main.hs+2−2
@@ -12,6 +12,7 @@ import System.Environment (getProgName, getArgs)
12import System.Process (system)
12import System.Process (system)
13
13
14import Hakyll.Core.Configuration
14import Hakyll.Core.Configuration
15+import Hakyll.Core.Identifier
15import Hakyll.Core.Run
16import Hakyll.Core.Run
16import Hakyll.Core.Rules
17import Hakyll.Core.Rules
17
18
@@ -20,7 +21,6 @@ import Control.Applicative ((<$>))
20import Control.Concurrent (forkIO)
21import Control.Concurrent (forkIO)
21import qualified Data.Set as S
22import qualified Data.Set as S
22
23
23−import Hakyll.Core.Resource
24import Hakyll.Core.Rules.Internal
24import Hakyll.Core.Rules.Internal
25import Hakyll.Web.Preview.Poll
25import Hakyll.Web.Preview.Poll
26import Hakyll.Web.Preview.Server
26import Hakyll.Web.Preview.Server
@@ -106,7 +106,7 @@ preview conf rules port = do
106 -- Run the server in the main thread
106 -- Run the server in the main thread
107 server conf port
107 server conf port
108 where
108 where
109− update = map unResource . S.toList . rulesResources <$> run conf rules
109+ update = map toFilePath . S.toList . rulesResources <$> run conf rules
110#else
110#else
111preview _ _ _ = previewServerDisabled
111preview _ _ _ = previewServerDisabled
112#endif
112#endif
src/Hakyll/Web/CompressCss.hs+1−2
@@ -11,12 +11,11 @@ import Data.List (isPrefixOf)
11import Control.Arrow ((>>^))
11import Control.Arrow ((>>^))
12
12
13import Hakyll.Core.Compiler
13import Hakyll.Core.Compiler
14−import Hakyll.Core.Resource
15import Hakyll.Core.Util.String
14import Hakyll.Core.Util.String
16
15
17-- | Compiler form of 'compressCss'
16-- | Compiler form of 'compressCss'
18--
17--
19−compressCssCompiler :: Compiler Resource String
18+compressCssCompiler :: Compiler a String
20compressCssCompiler = getResourceString >>^ compressCss
19compressCssCompiler = getResourceString >>^ compressCss
21
20
22-- | Compress CSS to speed up your site.
21-- | Compress CSS to speed up your site.
src/Hakyll/Web/Page.hs+5−6
@@ -72,7 +72,6 @@ import Text.Pandoc (Pandoc, ParserState, WriterOptions)
72
72
73import Hakyll.Core.Identifier
73import Hakyll.Core.Identifier
74import Hakyll.Core.Compiler
74import Hakyll.Core.Compiler
75−import Hakyll.Core.Resource
76import Hakyll.Web.Page.Internal
75import Hakyll.Web.Page.Internal
77import Hakyll.Web.Page.Read
76import Hakyll.Web.Page.Read
78import Hakyll.Web.Page.Metadata
77import Hakyll.Web.Page.Metadata
@@ -87,12 +86,12 @@ fromBody = Page M.empty
87
86
88-- | Read a page (do not render it)
87-- | Read a page (do not render it)
89--
88--
90−readPageCompiler :: Compiler Resource (Page String)
89+readPageCompiler :: Compiler () (Page String)
91readPageCompiler = getResourceString >>^ readPage
90readPageCompiler = getResourceString >>^ readPage
92
91
93-- | Read a page, add default fields, substitute fields and render using pandoc
92-- | Read a page, add default fields, substitute fields and render using pandoc
94--
93--
95−pageCompiler :: Compiler Resource (Page String)
94+pageCompiler :: Compiler () (Page String)
96pageCompiler =
95pageCompiler =
97 pageCompilerWith defaultHakyllParserState defaultHakyllWriterOptions
96 pageCompilerWith defaultHakyllParserState defaultHakyllWriterOptions
98
97
@@ -100,7 +99,7 @@ pageCompiler =
100-- options
99-- options
101--
100--
102pageCompilerWith :: ParserState -> WriterOptions
101pageCompilerWith :: ParserState -> WriterOptions
103− -> Compiler Resource (Page String)
102+ -> Compiler () (Page String)
104pageCompilerWith state options = pageCompilerWithPandoc state options id
103pageCompilerWith state options = pageCompilerWithPandoc state options id
105
104
106-- | An extension of 'pageCompilerWith' which allows you to specify a custom
105-- | An extension of 'pageCompilerWith' which allows you to specify a custom
@@ -108,7 +107,7 @@ pageCompilerWith state options = pageCompilerWithPandoc state options id
108--
107--
109pageCompilerWithPandoc :: ParserState -> WriterOptions
108pageCompilerWithPandoc :: ParserState -> WriterOptions
110 -> (Pandoc -> Pandoc)
109 -> (Pandoc -> Pandoc)
111− -> Compiler Resource (Page String)
110+ -> Compiler () (Page String)
112pageCompilerWithPandoc state options f = cached cacheName $
111pageCompilerWithPandoc state options f = cached cacheName $
113 readPageCompiler >>> addDefaultFields >>> arr applySelf
112 readPageCompiler >>> addDefaultFields >>> arr applySelf
114 >>> pageReadPandocWith state
113 >>> pageReadPandocWith state
@@ -124,7 +123,7 @@ pageCompilerWithPandoc state options f = cached cacheName $
124pageCompilerWithFields :: ParserState -> WriterOptions
123pageCompilerWithFields :: ParserState -> WriterOptions
125 -> (Pandoc -> Pandoc)
124 -> (Pandoc -> Pandoc)
126 -> Compiler (Page String) (Page String)
125 -> Compiler (Page String) (Page String)
127− -> Compiler Resource (Page String)
126+ -> Compiler () (Page String)
128pageCompilerWithFields state options f g =
127pageCompilerWithFields state options f g =
129 readPageCompiler >>> addDefaultFields >>> g >>> arr applySelf
128 readPageCompiler >>> addDefaultFields >>> g >>> arr applySelf
130 >>> pageReadPandocWith state
129 >>> pageReadPandocWith state
src/Hakyll/Web/Page/Metadata.hs+2−2
@@ -38,7 +38,7 @@ import Hakyll.Web.Page.Internal
38import Hakyll.Core.Util.String
38import Hakyll.Core.Util.String
39import Hakyll.Core.Identifier
39import Hakyll.Core.Identifier
40import Hakyll.Core.Compiler
40import Hakyll.Core.Compiler
41−import Hakyll.Core.Resource.Provider
41+import Hakyll.Core.ResourceProvider
42
42
43-- | Get a metadata field. If the field does not exist, the empty string is
43-- | Get a metadata field. If the field does not exist, the empty string is
44-- returned.
44-- returned.
@@ -208,7 +208,7 @@ renderModificationTimeWith :: TimeLocale
208 -> Compiler (Page String) (Page String)
208 -> Compiler (Page String) (Page String)
209 -- ^ Resulting compiler
209 -- ^ Resulting compiler
210renderModificationTimeWith locale key format =
210renderModificationTimeWith locale key format =
211− id &&& (getResource >>> getResourceWith resourceModificationTime) >>>
211+ id &&& (getResourceWith resourceModificationTime) >>>
212 setFieldA key (arr (formatTime locale format))
212 setFieldA key (arr (formatTime locale format))
213
213
214-- | Copy the body of a page to a metadata field
214-- | Copy the body of a page to a metadata field
src/Hakyll/Web/Pandoc/Biblio.hs+6−7
@@ -17,7 +17,7 @@ module Hakyll.Web.Pandoc.Biblio
17 ) where
17 ) where
18
18
19import Control.Applicative ((<$>))
19import Control.Applicative ((<$>))
20−import Control.Arrow (arr, returnA)
20+import Control.Arrow (arr, returnA, (>>>))
21import Data.Typeable (Typeable)
21import Data.Typeable (Typeable)
22
22
23import Data.Binary (Binary (..))
23import Data.Binary (Binary (..))
@@ -27,7 +27,6 @@ import qualified Text.CSL as CSL
27
27
28import Hakyll.Core.Compiler
28import Hakyll.Core.Compiler
29import Hakyll.Core.Identifier
29import Hakyll.Core.Identifier
30−import Hakyll.Core.Resource
31import Hakyll.Core.Writable
30import Hakyll.Core.Writable
32import Hakyll.Web.Page
31import Hakyll.Web.Page
33import Hakyll.Web.Pandoc
32import Hakyll.Web.Pandoc
@@ -35,8 +34,8 @@ import Hakyll.Web.Pandoc
35newtype CSL = CSL FilePath
34newtype CSL = CSL FilePath
36 deriving (Binary, Show, Typeable, Writable)
35 deriving (Binary, Show, Typeable, Writable)
37
36
38−cslCompiler :: Compiler Resource CSL
37+cslCompiler :: Compiler () CSL
39−cslCompiler = arr (CSL . unResource)
38+cslCompiler = getIdentifier >>> arr (CSL . toFilePath)
40
39
41newtype Biblio = Biblio [CSL.Reference]
40newtype Biblio = Biblio [CSL.Reference]
42 deriving (Show, Typeable)
41 deriving (Show, Typeable)
@@ -49,9 +48,9 @@ instance Binary Biblio where
49instance Writable Biblio where
48instance Writable Biblio where
50 write _ _ = return ()
49 write _ _ = return ()
51
50
52−biblioCompiler :: Compiler Resource Biblio
51+biblioCompiler :: Compiler () Biblio
53−biblioCompiler = unsafeCompiler $
52+biblioCompiler = getIdentifier >>>
54− fmap Biblio . CSL.readBiblioFile . unResource
53+ arr toFilePath >>> unsafeCompiler CSL.readBiblioFile >>> arr Biblio
55
54
56pageReadPandocBiblio :: ParserState
55pageReadPandocBiblio :: ParserState
57 -> Identifier CSL
56 -> Identifier CSL
src/Hakyll/Web/Template.hs+2−3
@@ -79,7 +79,6 @@ import Text.Hamlet (HamletSettings, defaultHamletSettings)
79
79
80import Hakyll.Core.Compiler
80import Hakyll.Core.Compiler
81import Hakyll.Core.Identifier
81import Hakyll.Core.Identifier
82−import Hakyll.Core.Resource
83import Hakyll.Web.Template.Internal
82import Hakyll.Web.Template.Internal
84import Hakyll.Web.Template.Read
83import Hakyll.Web.Template.Read
85import Hakyll.Web.Page.Internal
84import Hakyll.Web.Page.Internal
@@ -119,12 +118,12 @@ applySelf page = applyTemplate (readTemplate $ pageBody page) page
119-- @.hml@ or @.hamlet@, it will be considered as a Hamlet template, and parsed
118-- @.hml@ or @.hamlet@, it will be considered as a Hamlet template, and parsed
120-- as such.
119-- as such.
121--
120--
122−templateCompiler :: Compiler Resource Template
121+templateCompiler :: Compiler () Template
123templateCompiler = templateCompilerWith defaultHamletSettings
122templateCompiler = templateCompilerWith defaultHamletSettings
124
123
125-- | Version of 'templateCompiler' that enables custom settings.
124-- | Version of 'templateCompiler' that enables custom settings.
126--
125--
127−templateCompilerWith :: HamletSettings -> Compiler Resource Template
126+templateCompilerWith :: HamletSettings -> Compiler () Template
128templateCompilerWith settings =
127templateCompilerWith settings =
129 cached "Hakyll.Web.Template.templateCompilerWith" $
128 cached "Hakyll.Web.Template.templateCompilerWith" $
130 getIdentifier &&& getResourceString >>^ uncurry read'
129 getIdentifier &&& getResourceString >>^ uncurry read'