on master help sign in
Fix merge conflicts
commit11ef948720fab551173852e0f67da04990171433 authorsamgd <sam@samgd.com> dateMon 25 Jul 2016, 18:24 (10 years ago) parent82d640268e9c77
5 files changed+48−21
src/Hakyll/Web/Feed.hs+5−7 src/Hakyll/Web/Template.hs+22−5 src/Hakyll/Web/Template/Internal.hs+13−7 web/tutorials/01-installation.markdown+2−2 web/tutorials/external-live-reload.md+6
src/Hakyll/Web/Feed.hs+5−7
@@ -23,10 +23,6 @@ module Hakyll.Web.Feed
2323 ) where
2424
2525
26−--------------------------------------------------------------------------------
27−import Control.Monad ((<=<))
28−
29−
3026--------------------------------------------------------------------------------
3127import Hakyll.Core.Compiler
3228import Hakyll.Core.Compiler.Internal
@@ -65,14 +61,16 @@ renderFeed :: FilePath -- ^ Feed template
6561 -> [Item String] -- ^ Input items
6662 -> Compiler (Item String) -- ^ Resulting item
6763renderFeed feedPath itemPath config itemContext items = do
68− feedTpl <- compilerUnsafeIO $ loadTemplate feedPath
69− itemTpl <- compilerUnsafeIO $ loadTemplate itemPath
64+ feedTpl <- loadTemplate feedPath
65+ itemTpl <- loadTemplate itemPath
7066
7167 body <- makeItem =<< applyTemplateList itemTpl itemContext' items
7268 applyTemplate feedTpl feedContext body
7369 where
7470 -- Auxiliary: load a template from a datafile
75− loadTemplate = fmap readTemplate . readFile <=< getDataFileName
71+ loadTemplate path = do
72+ file <- compilerUnsafeIO $ getDataFileName path
73+ unsafeReadTemplateFile file
7674
7775 itemContext' = mconcat
7876 [ itemContext
src/Hakyll/Web/Template.hs+22−5
@@ -128,7 +128,7 @@
128128-- > <p>
129129-- > $for(counts)-$
130130-- > $count$
131−-- > $-sep-$...
131+-- > $-sep$...
132132-- > $-endfor$
133133-- > </p>
134134--
@@ -148,6 +148,7 @@ module Hakyll.Web.Template
148148 , loadAndApplyTemplate
149149 , applyAsTemplate
150150 , readTemplate
151+ , unsafeReadTemplateFile
151152 ) where
152153
153154
@@ -188,24 +189,31 @@ instance IsString Template where
188189 fromString = readTemplate
189190
190191
192+--------------------------------------------------------------------------------
193+-- | Wrap the constructor to ensure trim is called.
194+template :: [TemplateElement] -> Template
195+template = Template . trim
196+
197+
191198--------------------------------------------------------------------------------
192199readTemplate :: String -> Template
193200readTemplate = Template . trim . readTemplateElems
194201
195−
196202--------------------------------------------------------------------------------
197203-- | Read a template, without metadata header
198204templateBodyCompiler :: Compiler (Item Template)
199205templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
200206 item <- getResourceBody
201− return $ fmap readTemplate item
207+ file <- getResourceFilePath
208+ return $ fmap (template . readTemplateElemsFile file) item
202209
203210--------------------------------------------------------------------------------
204211-- | Read complete file contents as a template
205212templateCompiler :: Compiler (Item Template)
206213templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
207214 item <- getResourceString
208− return $ fmap readTemplate item
215+ file <- getResourceFilePath
216+ return $ fmap (template . readTemplateElemsFile file) item
209217
210218
211219--------------------------------------------------------------------------------
@@ -317,5 +325,14 @@ applyAsTemplate :: Context String -- ^ Context
317325 -> Item String -- ^ Item and template
318326 -> Compiler (Item String) -- ^ Resulting item
319327applyAsTemplate context item =
320− let tpl = readTemplate $ itemBody item
328+ let tpl = template $ readTemplateElemsFile file (itemBody item)
329+ file = toFilePath $ itemIdentifier item
321330 in applyTemplate tpl context item
331+
332+
333+--------------------------------------------------------------------------------
334+unsafeReadTemplateFile :: FilePath -> Compiler Template
335+unsafeReadTemplateFile file = do
336+ tpl <- unsafeCompiler $ readFile file
337+ pure $ template $ readTemplateElemsFile file tpl
338+
src/Hakyll/Web/Template/Internal.hs+13−7
@@ -7,6 +7,7 @@ module Hakyll.Web.Template.Internal
77 , TemplateElement (..)
88 , templateElems
99 , readTemplateElems
10+ , readTemplateElemsFile
1011 ) where
1112
1213
@@ -108,7 +109,12 @@ instance Binary TemplateExpr where
108109
109110--------------------------------------------------------------------------------
110111readTemplateElems :: String -> [TemplateElement]
111−readTemplateElems input = case P.parse templateElems "" input of
112+readTemplateElems = readTemplateElemsFile "{literal}"
113+
114+
115+--------------------------------------------------------------------------------
116+readTemplateElemsFile :: FilePath -> String -> [TemplateElement]
117+readTemplateElemsFile file input = case P.parse templateElems file input of
112118 Left err -> error $ "Cannot parse template: " ++ show err
113119 Right t -> t
114120
@@ -116,12 +122,12 @@ readTemplateElems input = case P.parse templateElems "" input of
116122--------------------------------------------------------------------------------
117123templateElems :: P.Parser [TemplateElement]
118124templateElems = mconcat <$> P.many (P.choice [ lift chunk
119− , lift escaped
120− , conditional
121− , for
122− , partial
123− , expr
124− ])
125+ , lift escaped
126+ , conditional
127+ , for
128+ , partial
129+ , expr
130+ ])
125131 where lift = fmap (:[])
126132
127133
web/tutorials/01-installation.markdown+2−2
@@ -32,13 +32,13 @@ content and a generic configuration.
3232
3333If `hakyll-init` is not found, you should make sure your stack bin path
3434(usually `$HOME/.local/bin`) is in your `$PATH`. You can check your stack local
35−bin path by running `stack path --local-bin-path`.
35+bin path by running `stack path --local-bin`.
3636
3737The file `site.hs` holds the configuration of your site, as an executable
3838haskell program. We can compile and run it like this:
3939
4040 $ cd my-site
41− $ stack init # Optional, if you haven't used stack before
41+ $ stack init # creates stack.yaml file based on my-site.cabal
4242 $ stack build
4343 $ stack exec site build
4444
web/tutorials/external-live-reload.mdnew file+6
@@ -0,0 +1,6 @@
1+---
2+title: Live Reloading with Hakyll
3+author: Ben Kolera
4+url: 'http://benkolera.com/posts/2015-09-14-hakyll_livereload.html'
5+external: true
6+---