hakyll 3.0.1.0 → 3.0.1.1
raw patch · 8 files changed
+101/−29 lines, 8 files
Files
- hakyll.cabal +2/−1
- src/Hakyll.hs +2/−0
- src/Hakyll/Core/Compiler.hs +27/−20
- src/Hakyll/Core/Compiler/Internal.hs +10/−4
- src/Hakyll/Core/Logger.hs +9/−0
- src/Hakyll/Core/Run.hs +7/−2
- src/Hakyll/Core/Writable.hs +10/−2
- src/Hakyll/Web/Blaze.hs +34/−0
hakyll.cabal view
@@ -1,5 +1,5 @@ Name: hakyll-Version: 3.0.1.0+Version: 3.0.1.1 Synopsis: A simple static site generator library. Description: A simple static site generator library, mainly aimed at@@ -65,6 +65,7 @@ strict-concurrency >= 0.2 exposed-modules: Hakyll Hakyll.Main+ Hakyll.Web.Blaze Hakyll.Web.Util.Url Hakyll.Web.Preview.Server Hakyll.Web.Preview.Poll
src/Hakyll.hs view
@@ -16,6 +16,7 @@ , module Hakyll.Core.Writable.CopyFile , module Hakyll.Core.Writable.WritableTuple , module Hakyll.Main+ , module Hakyll.Web.Blaze , module Hakyll.Web.CompressCss , module Hakyll.Web.Feed , module Hakyll.Web.FileType@@ -44,6 +45,7 @@ import Hakyll.Core.Writable.CopyFile import Hakyll.Core.Writable.WritableTuple import Hakyll.Main+import Hakyll.Web.Blaze import Hakyll.Web.CompressCss import Hakyll.Web.Feed import Hakyll.Web.FileType
src/Hakyll/Core/Compiler.hs view
@@ -112,6 +112,7 @@ import Control.Applicative ((<$>)) import Control.Monad.Reader (ask) import Control.Monad.Trans (liftIO)+import Control.Monad.Error (throwError) import Control.Category (Category, (.), id) import Data.Maybe (fromMaybe) import System.FilePath (takeExtension)@@ -133,14 +134,14 @@ -- | Run a compiler, yielding the resulting target and it's dependencies. This -- version of 'runCompilerJob' also stores the result ---runCompiler :: Compiler () CompileRule -- ^ Compiler to run- -> Identifier -- ^ Target identifier- -> ResourceProvider -- ^ Resource provider- -> Routes -- ^ Route- -> Store -- ^ Store- -> Bool -- ^ Was the resource modified?- -> Logger -- ^ Logger- -> IO CompileRule -- ^ Resulting item+runCompiler :: Compiler () CompileRule -- ^ Compiler to run+ -> Identifier -- ^ Target identifier+ -> ResourceProvider -- ^ Resource provider+ -> Routes -- ^ Route+ -> Store -- ^ Store+ -> Bool -- ^ Was the resource modified?+ -> Logger -- ^ Logger+ -> IO (Throwing CompileRule) -- ^ Resulting item runCompiler compiler identifier provider routes store modified logger = do -- Run the compiler job result <-@@ -151,7 +152,7 @@ -- In case we compiled an item, we will store a copy in the cache first, -- before we return control. This makes sure the compiled item can later -- be accessed by e.g. require.- CompileRule (CompiledItem x) ->+ Right (CompileRule (CompiledItem x)) -> storeSet store "Hakyll.Core.Compiler.runCompiler" identifier x -- Otherwise, we do nothing here@@ -180,23 +181,29 @@ -- getResourceString :: Compiler Resource String getResourceString = fromJob $ \resource -> CompilerM $ do+ let identifier = unResource resource provider <- compilerResourceProvider <$> ask- liftIO $ resourceString provider resource+ if resourceExists provider identifier+ then liftIO $ resourceString provider resource+ else throwError $ error' identifier+ where+ error' id' = "Hakyll.Core.Compiler.getResourceString: resource "+ ++ show id' ++ " not found" -- | Auxiliary: get a dependency -- getDependency :: (Binary a, Writable a, Typeable a) => Identifier -> CompilerM a-getDependency identifier = CompilerM $ do+getDependency id' = CompilerM $ do store <- compilerStore <$> ask- fmap (fromMaybe error') $ liftIO $- storeGet store "Hakyll.Core.Compiler.runCompiler" identifier+ result <- liftIO $ storeGet store "Hakyll.Core.Compiler.runCompiler" id'+ case result of+ Nothing -> throwError error'+ Just x -> return x where- error' = error $ "Hakyll.Core.Compiler.getDependency: "- ++ show identifier- ++ " not found in the cache, the cache might be corrupted or"- ++ " the item you are referring to might not exist"-+ error' = "Hakyll.Core.Compiler.getDependency: " ++ show id'+ ++ " not found in the cache, the cache might be corrupted or"+ ++ " the item you are referring to might not exist" -- | Variant of 'require' which drops the current value --@@ -268,9 +275,9 @@ return v else do v <- liftIO $ storeGet store name identifier case v of Just v' -> return v'- Nothing -> error'+ Nothing -> throwError error' where- error' = error "Hakyll.Core.Compiler.cached: Cache corrupt!"+ error' = "Hakyll.Core.Compiler.cached: Cache corrupt!" -- | Create an unsafe compiler from a function in IO --
src/Hakyll/Core/Compiler/Internal.hs view
@@ -5,6 +5,7 @@ ( Dependencies , DependencyEnvironment (..) , CompilerEnvironment (..)+ , Throwing , CompilerM (..) , Compiler (..) , runCompilerJob@@ -17,6 +18,7 @@ import Prelude hiding ((.), id) import Control.Applicative (Applicative, pure, (<*>), (<$>)) import Control.Monad.Reader (ReaderT, Reader, ask, runReaderT, runReader)+import Control.Monad.Error (ErrorT, runErrorT) import Control.Monad ((<=<), liftM2) import Data.Set (Set) import qualified Data.Set as S@@ -59,10 +61,14 @@ compilerLogger :: Logger } +-- | A calculation possibly throwing an error+--+type Throwing a = Either String a+ -- | The compiler monad -- newtype CompilerM a = CompilerM- { unCompilerM :: ReaderT CompilerEnvironment IO a+ { unCompilerM :: ErrorT String (ReaderT CompilerEnvironment IO) a } deriving (Monad, Functor, Applicative) -- | The compiler arrow@@ -96,7 +102,7 @@ Left l -> Left <$> j l Right r -> Right <$> return r --- | Run a compiler, yielding the resulting target and it's dependencies+-- | Run a compiler, yielding the resulting target -- runCompilerJob :: Compiler () a -- ^ Compiler to run -> Identifier -- ^ Target identifier@@ -105,9 +111,9 @@ -> Store -- ^ Store -> Bool -- ^ Was the resource modified? -> Logger -- ^ Logger- -> IO a+ -> IO (Throwing a) -- ^ Result runCompilerJob compiler identifier provider route store modified logger =- runReaderT (unCompilerM $ compilerJob compiler ()) env+ runReaderT (runErrorT $ unCompilerM $ compilerJob compiler ()) env where env = CompilerEnvironment { compilerIdentifier = identifier
src/Hakyll/Core/Logger.hs view
@@ -8,6 +8,7 @@ , section , timed , report+ , thrown ) where import Control.Monad (forever)@@ -88,3 +89,11 @@ -> String -- ^ Message -> m () -- ^ No result report logger msg = liftIO $ message logger $ " [ ] " ++ msg++-- | Log an error that was thrown in the compilation phase+--+thrown :: MonadIO m+ => Logger -- ^ Logger+ -> String -- ^ Message+ -> m () -- ^ No result+thrown logger msg = liftIO $ message logger $ " [ ERROR] " ++ msg
src/Hakyll/Core/Run.hs view
@@ -188,7 +188,7 @@ case result of -- Compile rule for one item, easy stuff- CompileRule compiled -> do+ Right (CompileRule compiled) -> do case runRoutes routes id' of Nothing -> return () Just url -> timed logger ("Routing to " ++ url) $ do@@ -202,6 +202,11 @@ unRuntime $ runCompilers compilers -- Metacompiler, slightly more complicated- MetaCompileRule newCompilers ->+ Right (MetaCompileRule newCompilers) -> -- Actually I was just kidding, it's not hard at all unRuntime $ addNewCompilers compilers newCompilers++ -- Some error happened, log and continue+ Left err -> do+ thrown logger err + unRuntime $ runCompilers compilers
src/Hakyll/Core/Writable.hs view
@@ -1,6 +1,6 @@ -- | Describes writable items; items that can be saved to the disk ---{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} module Hakyll.Core.Writable ( Writable (..) ) where@@ -8,6 +8,8 @@ import Data.Word (Word8) import qualified Data.ByteString as SB+import Text.Blaze (Html)+import Text.Blaze.Renderer.String (renderHtml) -- | Describes an item that can be saved to the disk --@@ -18,5 +20,11 @@ instance Writable [Char] where write = writeFile +instance Writable SB.ByteString where+ write p = SB.writeFile p+ instance Writable [Word8] where- write p = SB.writeFile p . SB.pack+ write p = write p . SB.pack++instance Writable Html where+ write p html = write p $ renderHtml html
+ src/Hakyll/Web/Blaze.hs view
@@ -0,0 +1,34 @@+-- | Module providing BlazeHtml support for hakyll+--+module Hakyll.Web.Blaze+ ( getFieldHtml+ , getFieldHtml'+ , getBodyHtml+ , getBodyHtml'+ ) where++import Text.Blaze (Html, toHtml, preEscapedString)++import Hakyll.Web.Page+import Hakyll.Web.Page.Metadata++-- | Get a field from a page and convert it to HTML. This version does escape+-- the given HTML+--+getFieldHtml :: String -> Page a -> Html+getFieldHtml key = preEscapedString . getField key++-- | Version of 'getFieldHtml' that escapes the HTML content+--+getFieldHtml' :: String -> Page a -> Html+getFieldHtml' key = toHtml . getField key++-- | Get the body as HTML+--+getBodyHtml :: Page String -> Html+getBodyHtml = preEscapedString . pageBody++-- | Version of 'getBodyHtml' that escapes the HTML content+--+getBodyHtml' :: Page String -> Html+getBodyHtml' = toHtml . pageBody