on master help sign in
Fix merge conflicts
11ef948samgd
src/Hakyll/Web/Feed.hs+5−7
@@ -23,10 +23,6 @@ module Hakyll.Web.Feed
23 ) where
23 ) where
24
24
25
25
26−--------------------------------------------------------------------------------
27−import Control.Monad ((<=<))
28−
29−
30--------------------------------------------------------------------------------
26--------------------------------------------------------------------------------
31import Hakyll.Core.Compiler
27import Hakyll.Core.Compiler
32import Hakyll.Core.Compiler.Internal
28import Hakyll.Core.Compiler.Internal
@@ -65,14 +61,16 @@ renderFeed :: FilePath -- ^ Feed template
65 -> [Item String] -- ^ Input items
61 -> [Item String] -- ^ Input items
66 -> Compiler (Item String) -- ^ Resulting item
62 -> Compiler (Item String) -- ^ Resulting item
67renderFeed feedPath itemPath config itemContext items = do
63renderFeed feedPath itemPath config itemContext items = do
68− feedTpl <- compilerUnsafeIO $ loadTemplate feedPath
64+ feedTpl <- loadTemplate feedPath
69− itemTpl <- compilerUnsafeIO $ loadTemplate itemPath
65+ itemTpl <- loadTemplate itemPath
70
66
71 body <- makeItem =<< applyTemplateList itemTpl itemContext' items
67 body <- makeItem =<< applyTemplateList itemTpl itemContext' items
72 applyTemplate feedTpl feedContext body
68 applyTemplate feedTpl feedContext body
73 where
69 where
74 -- Auxiliary: load a template from a datafile
70 -- 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
76
74
77 itemContext' = mconcat
75 itemContext' = mconcat
78 [ itemContext
76 [ itemContext
src/Hakyll/Web/Template.hs+22−5
@@ -128,7 +128,7 @@
128-- > <p>
128-- > <p>
129-- > $for(counts)-$
129-- > $for(counts)-$
130-- > $count$
130-- > $count$
131−-- > $-sep-$...
131+-- > $-sep$...
132-- > $-endfor$
132-- > $-endfor$
133-- > </p>
133-- > </p>
134--
134--
@@ -148,6 +148,7 @@ module Hakyll.Web.Template
148 , loadAndApplyTemplate
148 , loadAndApplyTemplate
149 , applyAsTemplate
149 , applyAsTemplate
150 , readTemplate
150 , readTemplate
151+ , unsafeReadTemplateFile
151 ) where
152 ) where
152
153
153
154
@@ -188,24 +189,31 @@ instance IsString Template where
188 fromString = readTemplate
189 fromString = readTemplate
189
190
190
191
192+--------------------------------------------------------------------------------
193+-- | Wrap the constructor to ensure trim is called.
194+template :: [TemplateElement] -> Template
195+template = Template . trim
196+
197+
191--------------------------------------------------------------------------------
198--------------------------------------------------------------------------------
192readTemplate :: String -> Template
199readTemplate :: String -> Template
193readTemplate = Template . trim . readTemplateElems
200readTemplate = Template . trim . readTemplateElems
194
201
195−
196--------------------------------------------------------------------------------
202--------------------------------------------------------------------------------
197-- | Read a template, without metadata header
203-- | Read a template, without metadata header
198templateBodyCompiler :: Compiler (Item Template)
204templateBodyCompiler :: Compiler (Item Template)
199templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
205templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
200 item <- getResourceBody
206 item <- getResourceBody
201− return $ fmap readTemplate item
207+ file <- getResourceFilePath
208+ return $ fmap (template . readTemplateElemsFile file) item
202
209
203--------------------------------------------------------------------------------
210--------------------------------------------------------------------------------
204-- | Read complete file contents as a template
211-- | Read complete file contents as a template
205templateCompiler :: Compiler (Item Template)
212templateCompiler :: Compiler (Item Template)
206templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
213templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
207 item <- getResourceString
214 item <- getResourceString
208− return $ fmap readTemplate item
215+ file <- getResourceFilePath
216+ return $ fmap (template . readTemplateElemsFile file) item
209
217
210
218
211--------------------------------------------------------------------------------
219--------------------------------------------------------------------------------
@@ -317,5 +325,14 @@ applyAsTemplate :: Context String -- ^ Context
317 -> Item String -- ^ Item and template
325 -> Item String -- ^ Item and template
318 -> Compiler (Item String) -- ^ Resulting item
326 -> Compiler (Item String) -- ^ Resulting item
319applyAsTemplate context item =
327applyAsTemplate context item =
320− let tpl = readTemplate $ itemBody item
328+ let tpl = template $ readTemplateElemsFile file (itemBody item)
329+ file = toFilePath $ itemIdentifier item
321 in applyTemplate tpl context item
330 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
7 , TemplateElement (..)
7 , TemplateElement (..)
8 , templateElems
8 , templateElems
9 , readTemplateElems
9 , readTemplateElems
10+ , readTemplateElemsFile
10 ) where
11 ) where
11
12
12
13
@@ -108,7 +109,12 @@ instance Binary TemplateExpr where
108
109
109--------------------------------------------------------------------------------
110--------------------------------------------------------------------------------
110readTemplateElems :: String -> [TemplateElement]
111readTemplateElems :: String -> [TemplateElement]
112+readTemplateElems = readTemplateElemsFile "{literal}"
113+
114+
115+--------------------------------------------------------------------------------
116+readTemplateElemsFile :: FilePath -> String -> [TemplateElement]
111−readTemplateElems input = case P.parse templateElems "" input of
117+readTemplateElemsFile file input = case P.parse templateElems file input of
112 Left err -> error $ "Cannot parse template: " ++ show err
118 Left err -> error $ "Cannot parse template: " ++ show err
113 Right t -> t
119 Right t -> t
114
120
@@ -116,12 +122,12 @@ readTemplateElems input = case P.parse templateElems "" input of
116--------------------------------------------------------------------------------
122--------------------------------------------------------------------------------
117templateElems :: P.Parser [TemplateElement]
123templateElems :: P.Parser [TemplateElement]
118templateElems = mconcat <$> P.many (P.choice [ lift chunk
124templateElems = mconcat <$> P.many (P.choice [ lift chunk
119− , lift escaped
125+ , lift escaped
120− , conditional
126+ , conditional
121− , for
127+ , for
122− , partial
128+ , partial
123− , expr
129+ , expr
124− ])
130+ ])
125 where lift = fmap (:[])
131 where lift = fmap (:[])
126
132
127
133
web/tutorials/01-installation.markdown+2−2
@@ -32,13 +32,13 @@ content and a generic configuration.
32
32
33If `hakyll-init` is not found, you should make sure your stack bin path
33If `hakyll-init` is not found, you should make sure your stack bin path
34(usually `$HOME/.local/bin`) is in your `$PATH`. You can check your stack local
34(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`.
36
36
37The file `site.hs` holds the configuration of your site, as an executable
37The file `site.hs` holds the configuration of your site, as an executable
38haskell program. We can compile and run it like this:
38haskell program. We can compile and run it like this:
39
39
40 $ cd my-site
40 $ 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
42 $ stack build
42 $ stack build
43 $ stack exec site build
43 $ stack exec site build
44
44
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+---