on master help sign in
Remove Resource type
commit1319bbfe4ab3ddd321bcbb902bba7392ad868324 authorJasper Van der Jeugt <m@jaspervdj.be> dateFri 9 Nov 2012, 16:34 (14 years ago) parentdac3fac
23 files changed+193−375
hakyll.cabal+6−6 src/Hakyll.hs+4−4 src/Hakyll/Core/Compiler.hs+15−21 src/Hakyll/Core/Compiler/Internal.hs+1−1 src/Hakyll/Core/Identifier.hs+13−4 src/Hakyll/Core/Metadata.hs+24 src/Hakyll/Core/Resource.hs−51 src/Hakyll/Core/Resource/Pattern.hs−160 src/Hakyll/Core/Resource/Provider.hs → src/Hakyll/Core/ResourceProvider.hs+8−7 src/Hakyll/Core/Resource/Provider/Internal.hs → src/Hakyll/Core/ResourceProvider/Internal.hs+16−14 src/Hakyll/Core/Resource/Metadata.hs → src/Hakyll/Core/ResourceProvider/Metadata.hs+18−17 src/Hakyll/Core/Resource/MetadataCache.hs → src/Hakyll/Core/ResourceProvider/MetadataCache.hs+16−15 src/Hakyll/Core/Resource/Modified.hs → src/Hakyll/Core/ResourceProvider/Modified.hs+24−23 src/Hakyll/Core/Rules.hs+11−16 src/Hakyll/Core/Rules/Internal.hs+3−4 src/Hakyll/Core/Run.hs+3−4 src/Hakyll/Core/Writable/CopyFile.hs+13−6 src/Hakyll/Main.hs+2−2 src/Hakyll/Web/CompressCss.hs+1−2 src/Hakyll/Web/Page.hs+5−6 src/Hakyll/Web/Page/Metadata.hs+2−2 src/Hakyll/Web/Pandoc/Biblio.hs+6−7 src/Hakyll/Web/Template.hs+2−3
hakyll.cabal+6−6
@@ -99,8 +99,8 @@ Library
9999 Hakyll.Core.Identifier
100100 Hakyll.Core.Identifier.Pattern
101101 Hakyll.Core.Logger
102− Hakyll.Core.Resource
103− Hakyll.Core.Resource.Provider
102+ Hakyll.Core.Metadata
103+ Hakyll.Core.ResourceProvider
104104 Hakyll.Core.Routes
105105 Hakyll.Core.Rules
106106 Hakyll.Core.Run
@@ -132,10 +132,10 @@ Library
132132 Other-Modules:
133133 Hakyll.Core.Compiler.Internal
134134 Hakyll.Core.DirectedGraph.Internal
135− Hakyll.Core.Resource.Metadata
136− Hakyll.Core.Resource.MetadataCache
137− Hakyll.Core.Resource.Modified
138− Hakyll.Core.Resource.Provider.Internal
135+ Hakyll.Core.ResourceProvider.Internal
136+ Hakyll.Core.ResourceProvider.Metadata
137+ Hakyll.Core.ResourceProvider.MetadataCache
138+ Hakyll.Core.ResourceProvider.Modified
139139 Hakyll.Core.Rules.Internal
140140 Hakyll.Web.Page.Internal
141141 Hakyll.Web.Template.Internal
src/Hakyll.hs+4−4
@@ -6,8 +6,8 @@ module Hakyll
66 , module Hakyll.Core.Configuration
77 , module Hakyll.Core.Identifier
88 , module Hakyll.Core.Identifier.Pattern
9− , module Hakyll.Core.Resource
10− , module Hakyll.Core.Resource.Provider
9+ , module Hakyll.Core.Metadata
10+ , module Hakyll.Core.ResourceProvider
1111 , module Hakyll.Core.Routes
1212 , module Hakyll.Core.Rules
1313#ifdef UNIX_FILTER
@@ -42,8 +42,8 @@ import Hakyll.Core.Compiler
4242import Hakyll.Core.Configuration
4343import Hakyll.Core.Identifier
4444import Hakyll.Core.Identifier.Pattern
45−import Hakyll.Core.Resource
46−import Hakyll.Core.Resource.Provider
45+import Hakyll.Core.Metadata
46+import Hakyll.Core.ResourceProvider
4747import Hakyll.Core.Routes
4848import Hakyll.Core.Rules
4949#ifdef UNIX_FILTER
src/Hakyll/Core/Compiler.hs+15−21
@@ -93,7 +93,6 @@ module Hakyll.Core.Compiler
9393 ( Compiler
9494 , runCompiler
9595 , getIdentifier
96− , getResource
9796 , getRoute
9897 , getRouteFor
9998 , getResourceString
@@ -135,8 +134,7 @@ import Hakyll.Core.Identifier
135134import Hakyll.Core.Identifier.Pattern
136135import Hakyll.Core.CompiledItem
137136import Hakyll.Core.Writable
138−import Hakyll.Core.Resource
139−import Hakyll.Core.Resource.Provider
137+import Hakyll.Core.ResourceProvider
140138import Hakyll.Core.Compiler.Internal
141139import Hakyll.Core.Store (Store)
142140import Hakyll.Core.Rules.Internal
@@ -181,11 +179,6 @@ getIdentifier :: Compiler a (Identifier b)
181179getIdentifier = fromJob $ const $ CompilerM $
182180 castIdentifier . compilerIdentifier <$> ask
183181
184−-- | Get the resource that is currently being compiled
185−--
186−getResource :: Compiler a Resource
187−getResource = getIdentifier >>> arr fromIdentifier
188−
189182-- | Get the route we are using for this item
190183--
191184getRoute :: Compiler a (Maybe FilePath)
@@ -200,22 +193,23 @@ getRouteFor = fromJob $ \identifier -> CompilerM $ do
200193
201194-- | Get the resource we are compiling as a string
202195--
203−getResourceString :: Compiler Resource String
196+getResourceString :: Compiler a String
204197getResourceString = getResourceWith resourceString
205198
206199-- | Get the resource we are compiling as a lazy bytestring
207200--
208−getResourceLBS :: Compiler Resource ByteString
201+getResourceLBS :: Compiler a ByteString
209202getResourceLBS = getResourceWith resourceLBS
210203
211204-- | Overloadable function for 'getResourceString' and 'getResourceLBS'
212205--
213−getResourceWith :: (Resource -> IO a) -> Compiler Resource a
214−getResourceWith reader = fromJob $ \r -> CompilerM $ do
215− let filePath = unResource r
206+getResourceWith :: (Identifier a -> IO b) -> Compiler c b
207+getResourceWith reader = fromJob $ \_ -> CompilerM $ do
216208 provider <- compilerResourceProvider <$> ask
209+ r <- compilerIdentifier <$> ask
210+ let filePath = toFilePath r
217211 if resourceExists provider r
218− then liftIO $ reader r
212+ then liftIO $ reader $ castIdentifier r
219213 else throwError $ error' filePath
220214 where
221215 error' id' = "Hakyll.Core.Compiler.getResourceWith: resource "
@@ -299,17 +293,17 @@ requireAllA pattern = (id &&& requireAll_ pattern >>>)
299293
300294cached :: (Binary a, Typeable a, Writable a)
301295 => String
302− -> Compiler Resource a
303− -> Compiler Resource a
296+ -> Compiler () a
297+ -> Compiler () a
304298cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
305− logger <- compilerLogger <$> ask
299+ logger <- compilerLogger <$> ask
306300 identifier <- castIdentifier . compilerIdentifier <$> ask
307− store <- compilerStore <$> ask
308− modified <- compilerResourceModified <$> ask
309− progName <- liftIO getProgName
301+ store <- compilerStore <$> ask
302+ modified <- compilerResourceModified <$> ask
303+ progName <- liftIO getProgName
310304 report logger $ "Checking cache: " ++ if modified then "modified" else "OK"
311305 if modified
312− then do v <- unCompilerM $ j $ fromIdentifier identifier
306+ then do v <- unCompilerM $ j ()
313307 liftIO $ Store.set store [name, show identifier] v
314308 return v
315309 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)
2626import Control.Arrow (Arrow, ArrowChoice, arr, first, left)
2727
2828import Hakyll.Core.Identifier
29−import Hakyll.Core.Resource.Provider
29+import Hakyll.Core.ResourceProvider
3030import Hakyll.Core.Store
3131import Hakyll.Core.Routes
3232import Hakyll.Core.Logger
src/Hakyll/Core/Identifier.hs+13−4
@@ -34,6 +34,7 @@ module Hakyll.Core.Identifier
3434 ( Identifier (..)
3535 , castIdentifier
3636 , parseIdentifier
37+ , fromFilePath
3738 , toFilePath
3839 , setGroup
3940 ) where
@@ -77,16 +78,24 @@ castIdentifier :: Identifier a -> Identifier b
7778castIdentifier (Identifier g p) = Identifier g p
7879{-# INLINE castIdentifier #-}
7980
81+
82+--------------------------------------------------------------------------------
8083-- | Parse an identifier from a string
81−--
8284parseIdentifier :: String -> Identifier a
83−parseIdentifier = Identifier Nothing
84− . intercalate "/" . filter (not . null) . split'
85+parseIdentifier = Identifier Nothing .
86+ intercalate "/" . filter (not . null) . split'
8587 where
8688 split' = map dropTrailingPathSeparator . splitPath
8789
90+
91+--------------------------------------------------------------------------------
92+-- | Create an identifier from a filepath
93+fromFilePath :: FilePath -> Identifier a
94+fromFilePath = parseIdentifier
95+
96+
97+--------------------------------------------------------------------------------
8898-- | Convert an identifier to a relative 'FilePath'
89−--
9099toFilePath :: Identifier a -> FilePath
91100toFilePath = identifierPath
92101
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 @@
11--------------------------------------------------------------------------------
22-- | This module provides an wrapper API around the file system which does some
33-- caching.
4−module Hakyll.Core.Resource.Provider
4+module Hakyll.Core.ResourceProvider
55 ( -- * Constructing resource providers
66 ResourceProvider
77 , newResourceProvider
@@ -23,15 +23,16 @@ module Hakyll.Core.Resource.Provider
2323
2424
2525--------------------------------------------------------------------------------
26−import Hakyll.Core.Resource
27−import qualified Hakyll.Core.Resource.MetadataCache as Internal
28−import Hakyll.Core.Resource.Modified
29−import Hakyll.Core.Resource.Provider.Internal
26+import Hakyll.Core.Identifier
27+import Hakyll.Core.Metadata
28+import Hakyll.Core.ResourceProvider.Internal
29+import qualified Hakyll.Core.ResourceProvider.MetadataCache as Internal
30+import Hakyll.Core.ResourceProvider.Modified
3031
3132
3233--------------------------------------------------------------------------------
3334-- | Wrapper to ensure metadata cache is invalidated if necessary
34−resourceMetadata :: ResourceProvider -> Resource -> IO Metadata
35+resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata
3536resourceMetadata rp r = do
3637 _ <- resourceModified rp r
3738 Internal.resourceMetadata rp r
@@ -39,7 +40,7 @@ resourceMetadata rp r = do
3940
4041--------------------------------------------------------------------------------
4142-- | Wrapper to ensure metadata cache is invalidated if necessary
42−resourceBody :: ResourceProvider -> Resource -> IO String
43+resourceBody :: ResourceProvider -> Identifier a -> IO String
4344resourceBody rp r = do
4445 _ <- resourceModified rp r
4546 Internal.resourceBody rp r
src/Hakyll/Core/Resource/Provider/Internal.hs → src/Hakyll/Core/ResourceProvider/Internal.hsrenamed+16−14
@@ -1,5 +1,5 @@
11--------------------------------------------------------------------------------
2−module Hakyll.Core.Resource.Provider.Internal
2+module Hakyll.Core.ResourceProvider.Internal
33 ( ResourceProvider (..)
44 , newResourceProvider
55
@@ -24,18 +24,18 @@ import System.FilePath (addExtension)
2424
2525
2626--------------------------------------------------------------------------------
27−import Hakyll.Core.Resource
2827import Hakyll.Core.Store
2928import Hakyll.Core.Util.File
29+import Hakyll.Core.Identifier
3030
3131
3232--------------------------------------------------------------------------------
3333-- | Responsible for retrieving and listing resources
3434data ResourceProvider = ResourceProvider
3535 { -- | A list of all files found
36− resourceSet :: Set Resource
36+ resourceSet :: Set (Identifier ())
3737 , -- | Cache keeping track of modified files
38− resourceModifiedCache :: IORef (Map Resource Bool)
38+ resourceModifiedCache :: IORef (Map (Identifier ()) Bool)
3939 , -- | Underlying persistent store for caching
4040 resourceStore :: Store
4141 }
@@ -48,37 +48,39 @@ newResourceProvider :: Store -- ^ Store to use
4848 -> FilePath -- ^ Search directory
4949 -> IO ResourceProvider -- ^ Resulting provider
5050newResourceProvider store ignore directory = do
51− list <- map resource . filter (not . ignore) <$>
51+ list <- map parseIdentifier . filter (not . ignore) <$>
5252 getRecursiveContents False directory
5353 cache <- newIORef M.empty
5454 return $ ResourceProvider (S.fromList list) cache store
5555
5656
5757--------------------------------------------------------------------------------
58−resourceList :: ResourceProvider -> [Resource]
58+resourceList :: ResourceProvider -> [Identifier ()]
5959resourceList = S.toList . resourceSet
6060
6161
6262--------------------------------------------------------------------------------
6363-- | Check if a given resiyrce exists
64−resourceExists :: ResourceProvider -> Resource -> Bool
65−resourceExists provider = (`S.member` resourceSet provider)
64+resourceExists :: ResourceProvider -> Identifier a -> Bool
65+resourceExists provider =
66+ (`S.member` resourceSet provider) . setGroup Nothing . castIdentifier
6667
6768
6869--------------------------------------------------------------------------------
6970-- | Each resource may have an associated metadata resource (with a @.metadata@
7071-- filename)
71−resourceMetadataResource :: Resource -> Resource
72−resourceMetadataResource = resource . flip addExtension "metadata" . unResource
72+resourceMetadataResource :: Identifier a -> Identifier ()
73+resourceMetadataResource =
74+ parseIdentifier . flip addExtension "metadata" . toFilePath
7375
7476
7577--------------------------------------------------------------------------------
7678-- | Get the raw body of a resource as string
77−resourceString :: Resource -> IO String
78−resourceString = readFile . unResource
79+resourceString :: Identifier a -> IO String
80+resourceString = readFile . toFilePath
7981
8082
8183--------------------------------------------------------------------------------
8284-- | Get the raw body of a resource of a lazy bytestring
83−resourceLBS :: Resource -> IO BL.ByteString
84−resourceLBS = BL.readFile . unResource
85+resourceLBS :: Identifier a -> IO BL.ByteString
86+resourceLBS = BL.readFile . toFilePath
src/Hakyll/Core/Resource/Metadata.hs → src/Hakyll/Core/ResourceProvider/Metadata.hsrenamed+18−17
@@ -1,42 +1,43 @@
11--------------------------------------------------------------------------------
22-- | Internal module to parse metadata
3−module Hakyll.Core.Resource.Metadata
3+module Hakyll.Core.ResourceProvider.Metadata
44 ( loadMetadata
55 ) where
66
77
88--------------------------------------------------------------------------------
9−import Control.Applicative ((<$>), (<*), (<*>))
10−import Control.Arrow (second)
11−import qualified Data.ByteString.Char8 as BC
12−import qualified Data.Map as M
13−import System.IO as IO
14−import Text.Parsec ((<?>))
15−import qualified Text.Parsec as P
16−import Text.Parsec.String (Parser)
9+import Control.Applicative ((<$>), (<*), (<*>))
10+import Control.Arrow (second)
11+import qualified Data.ByteString.Char8 as BC
12+import qualified Data.Map as M
13+import System.IO as IO
14+import Text.Parsec ((<?>))
15+import qualified Text.Parsec as P
16+import Text.Parsec.String (Parser)
1717
1818
1919--------------------------------------------------------------------------------
20−import Hakyll.Core.Resource
21−import Hakyll.Core.Resource.Provider.Internal
20+import Hakyll.Core.Identifier
21+import Hakyll.Core.Metadata
22+import Hakyll.Core.ResourceProvider.Internal
2223import Hakyll.Core.Util.String
2324
2425
2526--------------------------------------------------------------------------------
26−loadMetadata :: ResourceProvider -> Resource -> IO (Metadata, Maybe String)
27−loadMetadata rp r = do
27+loadMetadata :: ResourceProvider -> Identifier a -> IO (Metadata, Maybe String)
28+loadMetadata rp identifier = do
2829 hasHeader <- probablyHasMetadataHeader fp
2930 (md, body) <- if hasHeader
3031 then second Just <$> loadMetadataHeader fp
3132 else return (M.empty, Nothing)
3233
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
3435
3536 return (M.union md emd, body)
3637 where
37− fp = unResource r
38− mr = resourceMetadataResource r
39− mfp = unResource mr
38+ fp = toFilePath identifier
39+ mi = resourceMetadataResource identifier
40+ mfp = toFilePath mi
4041
4142
4243--------------------------------------------------------------------------------
src/Hakyll/Core/Resource/MetadataCache.hs → src/Hakyll/Core/ResourceProvider/MetadataCache.hsrenamed+16−15
@@ -1,5 +1,5 @@
11--------------------------------------------------------------------------------
2−module Hakyll.Core.Resource.MetadataCache
2+module Hakyll.Core.ResourceProvider.MetadataCache
33 ( resourceMetadata
44 , resourceBody
55 , resourceInvalidateMetadataCache
@@ -7,39 +7,40 @@ module Hakyll.Core.Resource.MetadataCache
77
88
99--------------------------------------------------------------------------------
10−import Hakyll.Core.Resource
11−import Hakyll.Core.Resource.Metadata
12−import Hakyll.Core.Resource.Provider.Internal
13−import qualified Hakyll.Core.Store as Store
10+import Hakyll.Core.Identifier
11+import Hakyll.Core.Metadata
12+import Hakyll.Core.ResourceProvider.Internal
13+import Hakyll.Core.ResourceProvider.Metadata
14+import qualified Hakyll.Core.Store as Store
1415
1516
1617--------------------------------------------------------------------------------
17−resourceMetadata :: ResourceProvider -> Resource -> IO Metadata
18+resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata
1819resourceMetadata rp r = do
1920 load rp r
2021 Store.Found md <- Store.get (resourceStore rp)
21− [name, unResource r, "metadata"]
22+ [name, toFilePath r, "metadata"]
2223 return md
2324
2425
2526--------------------------------------------------------------------------------
26−resourceBody :: ResourceProvider -> Resource -> IO String
27+resourceBody :: ResourceProvider -> Identifier a -> IO String
2728resourceBody rp r = do
2829 load rp r
2930 Store.Found bd <- Store.get (resourceStore rp)
30− [name, unResource r, "body"]
31+ [name, toFilePath r, "body"]
3132 maybe (resourceString r) return bd
3233
3334
3435--------------------------------------------------------------------------------
35−resourceInvalidateMetadataCache :: ResourceProvider -> Resource -> IO ()
36+resourceInvalidateMetadataCache :: ResourceProvider -> Identifier a -> IO ()
3637resourceInvalidateMetadataCache rp r = do
37− Store.delete (resourceStore rp) [name, unResource r, "metadata"]
38− Store.delete (resourceStore rp) [name, unResource r, "body"]
38+ Store.delete (resourceStore rp) [name, toFilePath r, "metadata"]
39+ Store.delete (resourceStore rp) [name, toFilePath r, "body"]
3940
4041
4142--------------------------------------------------------------------------------
42−load :: ResourceProvider -> Resource -> IO ()
43+load :: ResourceProvider -> Identifier a -> IO ()
4344load rp r = do
4445 mmd <- Store.get store mdk :: IO (Store.Result Metadata)
4546 case mmd of
@@ -52,8 +53,8 @@ load rp r = do
5253 Store.set store bk body
5354 where
5455 store = resourceStore rp
55− mdk = [name, unResource r, "metadata"]
56− bk = [name, unResource r, "body"]
56+ mdk = [name, toFilePath r, "metadata"]
57+ bk = [name, toFilePath r, "body"]
5758
5859
5960--------------------------------------------------------------------------------
src/Hakyll/Core/Resource/Modified.hs → src/Hakyll/Core/ResourceProvider/Modified.hsrenamed+24−23
@@ -1,55 +1,56 @@
11--------------------------------------------------------------------------------
2−module Hakyll.Core.Resource.Modified
2+module Hakyll.Core.ResourceProvider.Modified
33 ( resourceModified
44 , resourceModificationTime
55 ) where
66
77
88--------------------------------------------------------------------------------
9−import Control.Applicative ((<$>), (<*>))
10−import Control.Monad (when)
11−import qualified Crypto.Hash.MD5 as MD5
12−import qualified Data.ByteString as B
13−import qualified Data.ByteString.Lazy as BL
9+import Control.Applicative ((<$>), (<*>))
10+import Control.Monad (when)
11+import qualified Crypto.Hash.MD5 as MD5
12+import qualified Data.ByteString as B
13+import qualified Data.ByteString.Lazy as BL
1414import Data.IORef
15−import qualified Data.Map as M
16−import Data.Time (UTCTime)
17−import System.Directory (getModificationTime)
15+import qualified Data.Map as M
16+import Data.Time (UTCTime)
17+import System.Directory (getModificationTime)
1818
1919
2020--------------------------------------------------------------------------------
21−import Hakyll.Core.Resource
22−import Hakyll.Core.Resource.MetadataCache
23−import Hakyll.Core.Resource.Provider.Internal
24−import Hakyll.Core.Store (Store)
25−import qualified Hakyll.Core.Store as Store
21+import Hakyll.Core.Identifier
22+import Hakyll.Core.ResourceProvider.Internal
23+import Hakyll.Core.ResourceProvider.MetadataCache
24+import Hakyll.Core.Store (Store)
25+import qualified Hakyll.Core.Store as Store
2626
2727
2828--------------------------------------------------------------------------------
2929-- | A resource is modified if it or its metadata has changed
30−resourceModified :: ResourceProvider -> Resource -> IO Bool
30+resourceModified :: ResourceProvider -> Identifier a -> IO Bool
3131resourceModified rp r
3232 | not exists = return False
3333 | otherwise = do
3434 cache <- readIORef cacheRef
35− case M.lookup r cache of
35+ case M.lookup normalized cache of
3636 Just m -> return m
3737 Nothing -> do
3838 -- Check if the actual file was modified, and do a recursive
3939 -- call to check if the metadata file was modified
4040 m <- (||)
41− <$> fileDigestModified store (unResource r)
41+ <$> fileDigestModified store (toFilePath r)
4242 <*> resourceModified rp (resourceMetadataResource r)
43− modifyIORef cacheRef (M.insert r m)
43+ modifyIORef cacheRef (M.insert normalized m)
4444
4545 -- Important! (But ugly)
4646 when m $ resourceInvalidateMetadataCache rp r
4747
4848 return m
4949 where
50− exists = resourceExists rp r
51− store = resourceStore rp
52− cacheRef = resourceModifiedCache rp
50+ normalized = castIdentifier $ setGroup Nothing r
51+ exists = resourceExists rp r
52+ store = resourceStore rp
53+ cacheRef = resourceModifiedCache rp
5354
5455
5556--------------------------------------------------------------------------------
@@ -78,5 +79,5 @@ fileDigest = fmap MD5.hashlazy . BL.readFile
7879
7980
8081--------------------------------------------------------------------------------
81−resourceModificationTime :: Resource -> IO UTCTime
82−resourceModificationTime = getModificationTime . unResource
82+resourceModificationTime :: Identifier a -> IO UTCTime
83+resourceModificationTime = getModificationTime . toFilePath
src/Hakyll/Core/Rules.hs+11−16
@@ -51,11 +51,9 @@ import Hakyll.Core.CompiledItem
5151import Hakyll.Core.Compiler.Internal
5252import Hakyll.Core.Identifier
5353import Hakyll.Core.Identifier.Pattern
54−import Hakyll.Core.Resource
55−import Hakyll.Core.Resource.Provider
54+import Hakyll.Core.ResourceProvider
5655import Hakyll.Core.Routes
5756import Hakyll.Core.Rules.Internal
58−import Hakyll.Core.Util.Arrow
5957import Hakyll.Core.Writable
6058
6159
@@ -80,10 +78,10 @@ tellCompilers compilers = RulesM $ do
8078
8179--------------------------------------------------------------------------------
8280-- | Add resources
83−tellResources :: [Resource]
81+tellResources :: [Identifier a]
8482 -> Rules
8583tellResources resources' = RulesM $ tell $
86− RuleSet mempty mempty $ S.fromList resources'
84+ RuleSet mempty mempty $ S.fromList $ map castIdentifier resources'
8785
8886
8987--------------------------------------------------------------------------------
@@ -139,13 +137,12 @@ group g = RulesM . local setGroup' . unRulesM
139137-- no resources match the current selection, nothing will happen. In this case,
140138-- you might want to have a look at 'create'.
141139compile :: (Binary a, Typeable a, Writable a)
142− => Compiler Resource a -> RulesM (Pattern a)
140+ => Compiler () a -> RulesM (Pattern a)
143141compile compiler = do
144142 ids <- resources
145− tellCompilers $ flip map ids $ \identifier ->
146− (identifier, constA (fromIdentifier identifier) >>> compiler)
147− tellResources $ map fromIdentifier ids
148− return $ list ids
143+ tellCompilers [(castIdentifier id', compiler) | id' <- ids]
144+ tellResources ids
145+ return $ list $ map castIdentifier ids
149146
150147
151148--------------------------------------------------------------------------------
@@ -182,14 +179,12 @@ route route' = RulesM $ do
182179--------------------------------------------------------------------------------
183180-- | Get a list of resources matching the current pattern. This will also set
184181-- the correct group to the identifiers.
185−resources :: RulesM [Identifier a]
182+resources :: RulesM [Identifier ()]
186183resources = RulesM $ do
187− pattern <- rulesPattern <$> ask
184+ pattern <- rulesPattern <$> ask
188185 provider <- rulesResourceProvider <$> ask
189− group' <- rulesGroup <$> ask
190− return $ filterMatches pattern $ map (toId group') $ resourceList provider
191− where
192− toId g = setGroup g . toIdentifier
186+ g <- rulesGroup <$> ask
187+ return $ filterMatches pattern $ map (setGroup g) $ resourceList provider
193188
194189
195190--------------------------------------------------------------------------------
src/Hakyll/Core/Rules/Internal.hs+3−4
@@ -26,8 +26,7 @@ import Hakyll.Core.CompiledItem
2626import Hakyll.Core.Compiler.Internal
2727import Hakyll.Core.Identifier
2828import Hakyll.Core.Identifier.Pattern
29−import Hakyll.Core.Resource
30−import Hakyll.Core.Resource.Provider
29+import Hakyll.Core.ResourceProvider
3130import Hakyll.Core.Routes
3231
3332
@@ -49,8 +48,8 @@ data RuleSet = RuleSet
4948 rulesRoutes :: Routes
5049 , -- | Compilation rules
5150 rulesCompilers :: [(Identifier (), Compiler () CompileRule)]
52− , -- | A list of the used resources
53− rulesResources :: Set Resource
51+ , -- | A set of the actually used files
52+ rulesResources :: Set (Identifier ())
5453 }
5554
5655
src/Hakyll/Core/Run.hs+3−4
@@ -25,8 +25,7 @@ import Hakyll.Core.DependencyAnalyzer
2525import Hakyll.Core.DirectedGraph
2626import Hakyll.Core.Identifier
2727import Hakyll.Core.Logger
28−import Hakyll.Core.Resource
29−import Hakyll.Core.Resource.Provider
28+import Hakyll.Core.ResourceProvider
3029import Hakyll.Core.Routes
3130import Hakyll.Core.Rules.Internal
3231import Hakyll.Core.Store (Store)
@@ -132,7 +131,7 @@ addNewCompilers newCompilers = Runtime $ do
132131
133132 -- Check which items have been modified
134133 modified <- fmap S.fromList $ flip filterM (map fst newCompilers) $
135− liftIO . resourceModified provider . fromIdentifier
134+ liftIO . resourceModified provider
136135 let checkModified = if firstRun then const True else (`S.member` modified)
137136
138137 -- Create a new analyzer and append it to the currect one
@@ -183,7 +182,7 @@ build id' = Runtime $ do
183182 let compiler = compilers M.! id'
184183
185184 -- Check if the resource was modified
186− isModified <- liftIO $ resourceModified provider $ fromIdentifier id'
185+ isModified <- liftIO $ resourceModified provider id'
187186
188187 -- Run the compiler
189188 result <- timed logger "Total compile time" $ liftIO $
src/Hakyll/Core/Writable/CopyFile.hs+13−6
@@ -1,29 +1,36 @@
1+--------------------------------------------------------------------------------
12-- | Exports simple compilers to just copy files
2−--
33{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
44module Hakyll.Core.Writable.CopyFile
55 ( CopyFile (..)
66 , copyFileCompiler
77 ) where
88
9+
10+--------------------------------------------------------------------------------
911import Control.Arrow ((>>^))
1012import System.Directory (copyFile)
11−
1213import Data.Typeable (Typeable)
1314import Data.Binary (Binary)
1415
15−import Hakyll.Core.Resource
16+
17+--------------------------------------------------------------------------------
1618import Hakyll.Core.Writable
1719import Hakyll.Core.Compiler
1820import Hakyll.Core.Identifier
1921
22+
23+--------------------------------------------------------------------------------
2024-- | Newtype construct around 'FilePath' which will copy the file directly
21−--
2225newtype CopyFile = CopyFile {unCopyFile :: FilePath}
23− deriving (Show, Eq, Ord, Binary, Typeable)
26+ deriving (Show, Eq, Ord, Binary, Typeable)
27+
2428
29+--------------------------------------------------------------------------------
2530instance Writable CopyFile where
2631 write dst (CopyFile src) = copyFile src dst
2732
28−copyFileCompiler :: Compiler Resource CopyFile
33+
34+--------------------------------------------------------------------------------
35+copyFileCompiler :: Compiler a CopyFile
2936copyFileCompiler = getIdentifier >>^ CopyFile . toFilePath
src/Hakyll/Main.hs+2−2
@@ -12,6 +12,7 @@ import System.Environment (getProgName, getArgs)
1212import System.Process (system)
1313
1414import Hakyll.Core.Configuration
15+import Hakyll.Core.Identifier
1516import Hakyll.Core.Run
1617import Hakyll.Core.Rules
1718
@@ -20,7 +21,6 @@ import Control.Applicative ((<$>))
2021import Control.Concurrent (forkIO)
2122import qualified Data.Set as S
2223
23−import Hakyll.Core.Resource
2424import Hakyll.Core.Rules.Internal
2525import Hakyll.Web.Preview.Poll
2626import Hakyll.Web.Preview.Server
@@ -106,7 +106,7 @@ preview conf rules port = do
106106 -- Run the server in the main thread
107107 server conf port
108108 where
109− update = map unResource . S.toList . rulesResources <$> run conf rules
109+ update = map toFilePath . S.toList . rulesResources <$> run conf rules
110110#else
111111preview _ _ _ = previewServerDisabled
112112#endif
src/Hakyll/Web/CompressCss.hs+1−2
@@ -11,12 +11,11 @@ import Data.List (isPrefixOf)
1111import Control.Arrow ((>>^))
1212
1313import Hakyll.Core.Compiler
14−import Hakyll.Core.Resource
1514import Hakyll.Core.Util.String
1615
1716-- | Compiler form of 'compressCss'
1817--
19−compressCssCompiler :: Compiler Resource String
18+compressCssCompiler :: Compiler a String
2019compressCssCompiler = getResourceString >>^ compressCss
2120
2221-- | Compress CSS to speed up your site.
src/Hakyll/Web/Page.hs+5−6
@@ -72,7 +72,6 @@ import Text.Pandoc (Pandoc, ParserState, WriterOptions)
7272
7373import Hakyll.Core.Identifier
7474import Hakyll.Core.Compiler
75−import Hakyll.Core.Resource
7675import Hakyll.Web.Page.Internal
7776import Hakyll.Web.Page.Read
7877import Hakyll.Web.Page.Metadata
@@ -87,12 +86,12 @@ fromBody = Page M.empty
8786
8887-- | Read a page (do not render it)
8988--
90−readPageCompiler :: Compiler Resource (Page String)
89+readPageCompiler :: Compiler () (Page String)
9190readPageCompiler = getResourceString >>^ readPage
9291
9392-- | Read a page, add default fields, substitute fields and render using pandoc
9493--
95−pageCompiler :: Compiler Resource (Page String)
94+pageCompiler :: Compiler () (Page String)
9695pageCompiler =
9796 pageCompilerWith defaultHakyllParserState defaultHakyllWriterOptions
9897
@@ -100,7 +99,7 @@ pageCompiler =
10099-- options
101100--
102101pageCompilerWith :: ParserState -> WriterOptions
103− -> Compiler Resource (Page String)
102+ -> Compiler () (Page String)
104103pageCompilerWith state options = pageCompilerWithPandoc state options id
105104
106105-- | An extension of 'pageCompilerWith' which allows you to specify a custom
@@ -108,7 +107,7 @@ pageCompilerWith state options = pageCompilerWithPandoc state options id
108107--
109108pageCompilerWithPandoc :: ParserState -> WriterOptions
110109 -> (Pandoc -> Pandoc)
111− -> Compiler Resource (Page String)
110+ -> Compiler () (Page String)
112111pageCompilerWithPandoc state options f = cached cacheName $
113112 readPageCompiler >>> addDefaultFields >>> arr applySelf
114113 >>> pageReadPandocWith state
@@ -124,7 +123,7 @@ pageCompilerWithPandoc state options f = cached cacheName $
124123pageCompilerWithFields :: ParserState -> WriterOptions
125124 -> (Pandoc -> Pandoc)
126125 -> Compiler (Page String) (Page String)
127− -> Compiler Resource (Page String)
126+ -> Compiler () (Page String)
128127pageCompilerWithFields state options f g =
129128 readPageCompiler >>> addDefaultFields >>> g >>> arr applySelf
130129 >>> pageReadPandocWith state
src/Hakyll/Web/Page/Metadata.hs+2−2
@@ -38,7 +38,7 @@ import Hakyll.Web.Page.Internal
3838import Hakyll.Core.Util.String
3939import Hakyll.Core.Identifier
4040import Hakyll.Core.Compiler
41−import Hakyll.Core.Resource.Provider
41+import Hakyll.Core.ResourceProvider
4242
4343-- | Get a metadata field. If the field does not exist, the empty string is
4444-- returned.
@@ -208,7 +208,7 @@ renderModificationTimeWith :: TimeLocale
208208 -> Compiler (Page String) (Page String)
209209 -- ^ Resulting compiler
210210renderModificationTimeWith locale key format =
211− id &&& (getResource >>> getResourceWith resourceModificationTime) >>>
211+ id &&& (getResourceWith resourceModificationTime) >>>
212212 setFieldA key (arr (formatTime locale format))
213213
214214-- | 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
1717 ) where
1818
1919import Control.Applicative ((<$>))
20−import Control.Arrow (arr, returnA)
20+import Control.Arrow (arr, returnA, (>>>))
2121import Data.Typeable (Typeable)
2222
2323import Data.Binary (Binary (..))
@@ -27,7 +27,6 @@ import qualified Text.CSL as CSL
2727
2828import Hakyll.Core.Compiler
2929import Hakyll.Core.Identifier
30−import Hakyll.Core.Resource
3130import Hakyll.Core.Writable
3231import Hakyll.Web.Page
3332import Hakyll.Web.Pandoc
@@ -35,8 +34,8 @@ import Hakyll.Web.Pandoc
3534newtype CSL = CSL FilePath
3635 deriving (Binary, Show, Typeable, Writable)
3736
38−cslCompiler :: Compiler Resource CSL
39−cslCompiler = arr (CSL . unResource)
37+cslCompiler :: Compiler () CSL
38+cslCompiler = getIdentifier >>> arr (CSL . toFilePath)
4039
4140newtype Biblio = Biblio [CSL.Reference]
4241 deriving (Show, Typeable)
@@ -49,9 +48,9 @@ instance Binary Biblio where
4948instance Writable Biblio where
5049 write _ _ = return ()
5150
52−biblioCompiler :: Compiler Resource Biblio
53−biblioCompiler = unsafeCompiler $
54− fmap Biblio . CSL.readBiblioFile . unResource
51+biblioCompiler :: Compiler () Biblio
52+biblioCompiler = getIdentifier >>>
53+ arr toFilePath >>> unsafeCompiler CSL.readBiblioFile >>> arr Biblio
5554
5655pageReadPandocBiblio :: ParserState
5756 -> Identifier CSL
src/Hakyll/Web/Template.hs+2−3
@@ -79,7 +79,6 @@ import Text.Hamlet (HamletSettings, defaultHamletSettings)
7979
8080import Hakyll.Core.Compiler
8181import Hakyll.Core.Identifier
82−import Hakyll.Core.Resource
8382import Hakyll.Web.Template.Internal
8483import Hakyll.Web.Template.Read
8584import Hakyll.Web.Page.Internal
@@ -119,12 +118,12 @@ applySelf page = applyTemplate (readTemplate $ pageBody page) page
119118-- @.hml@ or @.hamlet@, it will be considered as a Hamlet template, and parsed
120119-- as such.
121120--
122−templateCompiler :: Compiler Resource Template
121+templateCompiler :: Compiler () Template
123122templateCompiler = templateCompilerWith defaultHamletSettings
124123
125124-- | Version of 'templateCompiler' that enables custom settings.
126125--
127−templateCompilerWith :: HamletSettings -> Compiler Resource Template
126+templateCompilerWith :: HamletSettings -> Compiler () Template
128127templateCompilerWith settings =
129128 cached "Hakyll.Web.Template.templateCompilerWith" $
130129 getIdentifier &&& getResourceString >>^ uncurry read'