on master help sign in
Fix $body$ bug, add `traceShowCompiler`
commit5c454fc2ced8364e000f8c9cc36387e39e001714 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 26 Feb 2011, 15:49 (16 years ago) parented12fd2
4 files changed+24−15
src/Hakyll/Core/Compiler.hs+9 src/Hakyll/Web/Page.hs−12 src/Hakyll/Web/Page/Internal.hs+12 src/Hakyll/Web/Template.hs+3−3
src/Hakyll/Core/Compiler.hs+9
@@ -101,6 +101,7 @@ module Hakyll.Core.Compiler
101101 , requireAllA
102102 , cached
103103 , unsafeCompiler
104+ , traceShowCompiler
104105 , mapCompiler
105106 , timedCompiler
106107 , byExtension
@@ -277,6 +278,14 @@ unsafeCompiler :: (a -> IO b) -- ^ Function to lift
277278 -> Compiler a b -- ^ Resulting compiler
278279unsafeCompiler f = fromJob $ CompilerM . liftIO . f
279280
281+-- | Compiler for debugging purposes
282+--
283+traceShowCompiler :: Show a => Compiler a a
284+traceShowCompiler = fromJob $ \x -> CompilerM $ do
285+ logger <- compilerLogger <$> ask
286+ report logger $ show x
287+ return x
288+
280289-- | Map over a compiler
281290--
282291mapCompiler :: Compiler a b
src/Hakyll/Web/Page.hs−12
@@ -61,8 +61,6 @@ import Prelude hiding (id)
6161import Control.Category (id)
6262import Control.Arrow (arr, (>>^), (&&&), (>>>))
6363import System.FilePath (takeBaseName, takeDirectory)
64−import Data.Monoid (Monoid, mempty)
65−import Data.Map (Map)
6664import qualified Data.Map as M
6765import Data.List (sortBy)
6866import Data.Ord (comparing)
@@ -82,16 +80,6 @@ import Hakyll.Web.Util.String
8280fromBody :: a -> Page a
8381fromBody = Page M.empty
8482
85−-- | Create a metadata page, without a body
86−--
87−fromMap :: Monoid a => Map String String -> Page a
88−fromMap m = Page m mempty
89−
90−-- | Convert a page to a map. The body will be placed in the @body@ key.
91−--
92−toMap :: Page String -> Map String String
93−toMap (Page m b) = M.insert "body" b m
94−
9583-- | Read a page (do not render it)
9684--
9785readPageCompiler :: Compiler Resource (Page String)
src/Hakyll/Web/Page/Internal.hs+12
@@ -3,6 +3,8 @@
33{-# LANGUAGE DeriveDataTypeable #-}
44module Hakyll.Web.Page.Internal
55 ( Page (..)
6+ , fromMap
7+ , toMap
68 ) where
79
810import Control.Applicative ((<$>), (<*>))
@@ -36,3 +38,13 @@ instance Binary a => Binary (Page a) where
3638
3739instance Writable a => Writable (Page a) where
3840 write p (Page _ b) = write p b
41+
42+-- | Create a metadata page, without a body
43+--
44+fromMap :: Monoid a => Map String String -> Page a
45+fromMap m = Page m mempty
46+
47+-- | Convert a page to a map. The body will be placed in the @body@ key.
48+--
49+toMap :: Page String -> Map String String
50+toMap (Page m b) = M.insert "body" b m
src/Hakyll/Web/Template.hs+3−3
@@ -53,6 +53,7 @@ module Hakyll.Web.Template
5353import Control.Arrow
5454import Data.Maybe (fromMaybe)
5555import System.FilePath (takeExtension)
56+import qualified Data.Map as M
5657
5758import Text.Hamlet (HamletSettings, defaultHamletSettings)
5859
@@ -62,7 +63,6 @@ import Hakyll.Core.ResourceProvider
6263import Hakyll.Web.Template.Internal
6364import Hakyll.Web.Template.Read
6465import Hakyll.Web.Page.Internal
65−import Hakyll.Web.Page.Metadata
6666
6767-- | Substitutes @$identifiers@ in the given @Template@ by values from the given
6868-- "Page". When a key is not found, it is left as it is. You can specify
@@ -72,9 +72,9 @@ applyTemplate :: Template -> Page String -> Page String
7272applyTemplate template page =
7373 fmap (const $ substitute =<< unTemplate template) page
7474 where
75+ map' = toMap page
7576 substitute (Chunk chunk) = chunk
76− substitute (Key key) =
77− fromMaybe ("$" ++ key ++ "$") $ getFieldMaybe key page
77+ substitute (Key key) = fromMaybe ("$" ++ key ++ "$") $ M.lookup key map'
7878 substitute (Escaped) = "$"
7979
8080-- | Apply a page as it's own template. This is often very useful to fill in