on master help sign in
A bit of cleanup
25b8c8bJasper Van der Jeugt
hakyll.cabal+5−5
@@ -103,13 +103,9 @@ Library
103 Hakyll.Core.Identifier
103 Hakyll.Core.Identifier
104 Hakyll.Core.Identifier.Pattern
104 Hakyll.Core.Identifier.Pattern
105 Hakyll.Core.Item
105 Hakyll.Core.Item
106− Hakyll.Core.Logger
107 Hakyll.Core.Metadata
106 Hakyll.Core.Metadata
108 Hakyll.Core.Routes
107 Hakyll.Core.Routes
109 Hakyll.Core.Rules
108 Hakyll.Core.Rules
110− Hakyll.Core.Runtime
111− Hakyll.Core.Store
112− Hakyll.Core.Util.File
113 Hakyll.Core.Util.String
109 Hakyll.Core.Util.String
114 Hakyll.Core.Writable
110 Hakyll.Core.Writable
115 Hakyll.Core.Writable.CopyFile
111 Hakyll.Core.Writable.CopyFile
@@ -133,12 +129,16 @@ Library
133 Hakyll.Core.Compiler.Internal
129 Hakyll.Core.Compiler.Internal
134 Hakyll.Core.Compiler.Require
130 Hakyll.Core.Compiler.Require
135 Hakyll.Core.Item.SomeItem
131 Hakyll.Core.Item.SomeItem
132+ Hakyll.Core.Logger
136 Hakyll.Core.Provider
133 Hakyll.Core.Provider
137 Hakyll.Core.Provider.Internal
134 Hakyll.Core.Provider.Internal
138 Hakyll.Core.Provider.Metadata
135 Hakyll.Core.Provider.Metadata
139 Hakyll.Core.Provider.MetadataCache
136 Hakyll.Core.Provider.MetadataCache
140 Hakyll.Core.Provider.Modified
137 Hakyll.Core.Provider.Modified
141 Hakyll.Core.Rules.Internal
138 Hakyll.Core.Rules.Internal
139+ Hakyll.Core.Runtime
140+ Hakyll.Core.Store
141+ Hakyll.Core.Util.File
142 Hakyll.Web.Template.Internal
142 Hakyll.Web.Template.Internal
143 Paths_hakyll
143 Paths_hakyll
144
144
@@ -157,7 +157,7 @@ Library
157 unix >= 2.4 && < 2.7
157 unix >= 2.4 && < 2.7
158 Cpp-options:
158 Cpp-options:
159 -DUNIX_FILTER
159 -DUNIX_FILTER
160− Other-modules:
160+ Exposed-modules:
161 Hakyll.Core.UnixFilter
161 Hakyll.Core.UnixFilter
162
162
163Test-suite hakyll-tests
163Test-suite hakyll-tests
src/Hakyll/Core/Compiler/Internal.hs+2
@@ -82,6 +82,8 @@ data CompilerResult a where
82
82
83
83
84--------------------------------------------------------------------------------
84--------------------------------------------------------------------------------
85+-- | A monad which lets you compile items and takes care of dependency tracking
86+-- for you.
85newtype Compiler a = Compiler
87newtype Compiler a = Compiler
86 { unCompiler :: CompilerRead -> IO (CompilerResult a)
88 { unCompiler :: CompilerRead -> IO (CompilerResult a)
87 }
89 }
src/Hakyll/Core/Compiler/Require.hs+12−1
@@ -30,6 +30,8 @@ import qualified Hakyll.Core.Store as Store
30
30
31
31
32--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
33+-- | Whilst compiling an item, it possible to save multiple snapshots of it, and
34+-- not just the final result.
33type Snapshot = String
35type Snapshot = String
34
36
35
37
@@ -39,6 +41,8 @@ save store item = saveSnapshot store final item
39
41
40
42
41--------------------------------------------------------------------------------
43--------------------------------------------------------------------------------
44+-- | Save a specific snapshot of an item, so you can load it later using
45+-- 'requireSnapshot'.
42saveSnapshot :: (Binary a, Typeable a)
46saveSnapshot :: (Binary a, Typeable a)
43 => Store -> Snapshot -> Item a -> IO ()
47 => Store -> Snapshot -> Item a -> IO ()
44saveSnapshot store snapshot item =
48saveSnapshot store snapshot item =
@@ -46,11 +50,14 @@ saveSnapshot store snapshot item =
46
50
47
51
48--------------------------------------------------------------------------------
52--------------------------------------------------------------------------------
53+-- | Load an item compiled elsewhere. If the required item is not yet compiled,
54+-- the build system will take care of that automatically.
49require :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
55require :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)
50require id' = requireSnapshot id' final
56require id' = requireSnapshot id' final
51
57
52
58
53--------------------------------------------------------------------------------
59--------------------------------------------------------------------------------
60+-- | Require a specific snapshot of an item.
54requireSnapshot :: (Binary a, Typeable a)
61requireSnapshot :: (Binary a, Typeable a)
55 => Identifier -> Snapshot -> Compiler (Item a)
62 => Identifier -> Snapshot -> Compiler (Item a)
56requireSnapshot id' snapshot = do
63requireSnapshot id' snapshot = do
@@ -77,6 +84,9 @@ requireSnapshot id' snapshot = do
77
84
78
85
79--------------------------------------------------------------------------------
86--------------------------------------------------------------------------------
87+-- | A shortcut for only requiring the body of an item.
88+--
89+-- > requireBody = fmap itemBody . require
80requireBody :: (Binary a, Typeable a) => Identifier -> Compiler a
90requireBody :: (Binary a, Typeable a) => Identifier -> Compiler a
81requireBody id' = requireSnapshotBody id' final
91requireBody id' = requireSnapshotBody id' final
82
92
@@ -88,6 +98,7 @@ requireSnapshotBody id' snapshot = fmap itemBody $ requireSnapshot id' snapshot
88
98
89
99
90--------------------------------------------------------------------------------
100--------------------------------------------------------------------------------
101+-- | This function allows you to 'require' a dynamic list of items
91requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
102requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [Item a]
92requireAll pattern = requireAllSnapshots pattern final
103requireAll pattern = requireAllSnapshots pattern final
93
104
@@ -108,4 +119,4 @@ key identifier snapshot =
108
119
109--------------------------------------------------------------------------------
120--------------------------------------------------------------------------------
110final :: Snapshot
121final :: Snapshot
111−final = "final"
122+final = "_final"
src/Hakyll/Core/Configuration.hs+7−5
@@ -9,7 +9,7 @@ module Hakyll.Core.Configuration
9
9
10--------------------------------------------------------------------------------
10--------------------------------------------------------------------------------
11import Data.List (isPrefixOf, isSuffixOf)
11import Data.List (isPrefixOf, isSuffixOf)
12−import System.FilePath (takeFileName)
12+import System.FilePath (normalise, takeFileName)
13
13
14
14
15--------------------------------------------------------------------------------
15--------------------------------------------------------------------------------
@@ -79,7 +79,7 @@ defaultConfiguration = Configuration
79 | "#" `isPrefixOf` fileName = True
79 | "#" `isPrefixOf` fileName = True
80 | "~" `isSuffixOf` fileName = True
80 | "~" `isSuffixOf` fileName = True
81 | ".swp" `isSuffixOf` fileName = True
81 | ".swp" `isSuffixOf` fileName = True
82− | otherwise = False
82+ | otherwise = False
83 where
83 where
84 fileName = takeFileName path
84 fileName = takeFileName path
85
85
@@ -88,6 +88,8 @@ defaultConfiguration = Configuration
88-- | Check if a file should be ignored
88-- | Check if a file should be ignored
89shouldIgnoreFile :: Configuration -> FilePath -> Bool
89shouldIgnoreFile :: Configuration -> FilePath -> Bool
90shouldIgnoreFile conf path =
90shouldIgnoreFile conf path =
91− destinationDirectory conf `isPrefixOf` path ||
91+ destinationDirectory conf `isPrefixOf` path' ||
92− storeDirectory conf `isPrefixOf` path ||
92+ storeDirectory conf `isPrefixOf` path' ||
93− ignoreFile conf path
93+ ignoreFile conf path'
94+ where
95+ path' = normalise path
src/Hakyll/Core/Identifier.hs+2−25
@@ -1,34 +1,12 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−-- | An identifier is a type used to uniquely identify a resource, target...
2+-- | An identifier is a type used to uniquely identify an item. An identifier is
3−--
4−-- One can think of an identifier as something similar to a file path. An
5−-- identifier is a path as well, with the different elements in the path
6−-- separated by @/@ characters. Examples of identifiers are:
3+-- conceptually similar to a file path. Examples of identifiers are:
7--
4--
8-- * @posts/foo.markdown@
5-- * @posts/foo.markdown@
9--
6--
10-- * @index@
7-- * @index@
11--
8--
12-- * @error/404@
9-- * @error/404@
13−--
14−-- The most important difference between an 'Identifier' and a file path is that
15−-- the identifier for an item is not necesserily the file path.
16−--
17−-- For example, we could have an @index@ identifier, generated by Hakyll. The
18−-- actual file path would be @index.html@, but we identify it using @index@.
19−--
20−-- @posts/foo.markdown@ could be an identifier of an item that is rendered to
21−-- @posts/foo.html@. In this case, the identifier is the name of the source
22−-- file of the page.
23−--
24−-- An `Identifier` carries the type of the value it identifies. This basically
25−-- means that an @Identifier (Page String)@ refers to a page.
26−--
27−-- It is a phantom type parameter, meaning you can safely change this if you
28−-- know what you are doing. You can change the type using the 'castIdentifier'
29−-- function.
30−--
31−-- If the @a@ type is not known, Hakyll traditionally uses @Identifier ()@.
32{-# LANGUAGE DeriveDataTypeable #-}
10{-# LANGUAGE DeriveDataTypeable #-}
33{-# LANGUAGE GeneralizedNewtypeDeriving #-}
11{-# LANGUAGE GeneralizedNewtypeDeriving #-}
34module Hakyll.Core.Identifier
12module Hakyll.Core.Identifier
@@ -54,7 +32,6 @@ import GHC.Exts (IsString, fromString)
54
32
55
33
56--------------------------------------------------------------------------------
34--------------------------------------------------------------------------------
57−-- | An identifier used to uniquely identify a value
58data Identifier = Identifier
35data Identifier = Identifier
59 { identifierVersion :: Maybe String
36 { identifierVersion :: Maybe String
60 , identifierPath :: String
37 , identifierPath :: String
src/Hakyll/Core/Identifier/Pattern.hs+2−1
@@ -149,7 +149,7 @@ instance Monoid Pattern where
149
149
150
150
151--------------------------------------------------------------------------------
151--------------------------------------------------------------------------------
152−-- | THis is necessary for good 'isLiteral' results
152+-- | This is necessary for good 'isLiteral' results
153optimize :: Pattern -> Pattern
153optimize :: Pattern -> Pattern
154optimize (Complement x) = Complement (optimize x)
154optimize (Complement x) = Complement (optimize x)
155optimize (And x Everything) = x
155optimize (And x Everything) = x
@@ -189,6 +189,7 @@ fromRegex = Regex
189
189
190
190
191--------------------------------------------------------------------------------
191--------------------------------------------------------------------------------
192+-- | Create a pattern which matches all items with the given version.
192fromVersion :: Maybe String -> Pattern
193fromVersion :: Maybe String -> Pattern
193fromVersion = Version
194fromVersion = Version
194
195
src/Hakyll/Core/Rules/Internal.hs+6−9
@@ -1,10 +1,9 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2−-- | Internal rules module for types which are not exposed to the user
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE Rank2Types #-}
3{-# LANGUAGE Rank2Types #-}
5module Hakyll.Core.Rules.Internal
4module Hakyll.Core.Rules.Internal
6 ( RuleSet (..)
5 ( RuleSet (..)
7− , RuleEnvironment (..)
6+ , RulesRead (..)
8 , Rules (..)
7 , Rules (..)
9 , runRules
8 , runRules
10 ) where
9 ) where
@@ -31,11 +30,10 @@ import Hakyll.Core.Routes
31
30
32
31
33--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
34−-- | A collection of rules for the compilation process
35data RuleSet = RuleSet
33data RuleSet = RuleSet
36− { -- | Routes used in the compilation structure
34+ { -- | Accumulated routes
37 rulesRoutes :: Routes
35 rulesRoutes :: Routes
38− , -- | Compilation rules
36+ , -- | Accumulated compilers
39 rulesCompilers :: [(Identifier, Compiler SomeItem)]
37 rulesCompilers :: [(Identifier, Compiler SomeItem)]
40 , -- | A set of the actually used files
38 , -- | A set of the actually used files
41 rulesResources :: Set Identifier
39 rulesResources :: Set Identifier
@@ -50,8 +48,7 @@ instance Monoid RuleSet where
50
48
51
49
52--------------------------------------------------------------------------------
50--------------------------------------------------------------------------------
53−-- | Rule environment
51+data RulesRead = RulesRead
54−data RuleEnvironment = RuleEnvironment
55 { rulesProvider :: Provider
52 { rulesProvider :: Provider
56 , rulesPattern :: Pattern
53 , rulesPattern :: Pattern
57 , rulesVersion :: Maybe String
54 , rulesVersion :: Maybe String
@@ -61,7 +58,7 @@ data RuleEnvironment = RuleEnvironment
61--------------------------------------------------------------------------------
58--------------------------------------------------------------------------------
62-- | The monad used to compose rules
59-- | The monad used to compose rules
63newtype Rules a = Rules
60newtype Rules a = Rules
64− { unRules :: RWST RuleEnvironment RuleSet () IO a
61+ { unRules :: RWST RulesRead RuleSet () IO a
65 } deriving (Monad, Functor, Applicative)
62 } deriving (Monad, Functor, Applicative)
66
63
67
64
@@ -83,7 +80,7 @@ runRules rules provider = do
83 (_, _, ruleSet) <- runRWST (unRules rules) env ()
80 (_, _, ruleSet) <- runRWST (unRules rules) env ()
84 return $ nubCompilers ruleSet
81 return $ nubCompilers ruleSet
85 where
82 where
86− env = RuleEnvironment
83+ env = RulesRead
87 { rulesProvider = provider
84 { rulesProvider = provider
88 , rulesPattern = mempty
85 , rulesPattern = mempty
89 , rulesVersion = Nothing
86 , rulesVersion = Nothing
src/Hakyll/Core/Runtime.hs+2−1
@@ -48,7 +48,8 @@ run config rules = do
48 Logger.message logger "Creating store..."
48 Logger.message logger "Creating store..."
49 store <- Store.new (inMemoryCache config) $ storeDirectory config
49 store <- Store.new (inMemoryCache config) $ storeDirectory config
50 Logger.message logger "Creating provider..."
50 Logger.message logger "Creating provider..."
51− provider <- newProvider store (ignoreFile config) $ providerDirectory config
51+ provider <- newProvider store (shouldIgnoreFile config) $
52+ providerDirectory config
52 Logger.message logger "Running rules..."
53 Logger.message logger "Running rules..."
53 ruleSet <- runRules rules provider
54 ruleSet <- runRules rules provider
54
55
src/Hakyll/Core/Util/File.hs+5−28
@@ -3,23 +3,15 @@
3module Hakyll.Core.Util.File
3module Hakyll.Core.Util.File
4 ( makeDirectories
4 ( makeDirectories
5 , getRecursiveContents
5 , getRecursiveContents
6− , isFileInternal
7 ) where
6 ) where
8
7
9
8
10--------------------------------------------------------------------------------
9--------------------------------------------------------------------------------
11−import Control.Applicative ((<$>))
10+import Control.Applicative ((<$>))
12−import Control.Monad (forM)
11+import Control.Monad (forM)
13−import Data.List (isPrefixOf)
14−import System.Directory (createDirectoryIfMissing,
12+import System.Directory (createDirectoryIfMissing,
15− doesDirectoryExist,
16− getDirectoryContents)
13+ doesDirectoryExist, getDirectoryContents)
17−import System.FilePath (dropTrailingPathSeparator,
14+import System.FilePath (takeDirectory, (</>))
18− splitPath, takeDirectory, (</>))
19−
20−
21−--------------------------------------------------------------------------------
22−import Hakyll.Core.Configuration
23
15
24
16
25--------------------------------------------------------------------------------
17--------------------------------------------------------------------------------
@@ -50,18 +42,3 @@ getRecursiveContents top = go ""
50 else return [rel]
42 else return [rel]
51
43
52 return $ concat paths
44 return $ concat paths
53−
54−
55−--------------------------------------------------------------------------------
56−-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in
57−-- the destination or store directory
58−isFileInternal :: Configuration -- ^ Configuration
59− -> FilePath -- ^ File to check
60− -> Bool -- ^ If the given file is internal
61−isFileInternal configuration file =
62− any (`isPrefixOf` split file) dirs
63− where
64− split = map dropTrailingPathSeparator . splitPath
65− dirs = map (split . ($ configuration)) [ destinationDirectory
66− , storeDirectory
67− ]