Fix merge conflicts

This commit is contained in:
samgd 2016-07-25 18:24:12 +02:00
commit 11ef948720
No known key found for this signature in database
GPG key ID: E69F2FF86041ADB3
5 changed files with 48 additions and 21 deletions

View file

@ -23,10 +23,6 @@ module Hakyll.Web.Feed
) where ) where
--------------------------------------------------------------------------------
import Control.Monad ((<=<))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Hakyll.Core.Compiler import Hakyll.Core.Compiler
import Hakyll.Core.Compiler.Internal import Hakyll.Core.Compiler.Internal
@ -65,14 +61,16 @@ renderFeed :: FilePath -- ^ Feed template
-> [Item String] -- ^ Input items -> [Item String] -- ^ Input items
-> Compiler (Item String) -- ^ Resulting item -> Compiler (Item String) -- ^ Resulting item
renderFeed feedPath itemPath config itemContext items = do renderFeed feedPath itemPath config itemContext items = do
feedTpl <- compilerUnsafeIO $ loadTemplate feedPath feedTpl <- loadTemplate feedPath
itemTpl <- compilerUnsafeIO $ loadTemplate itemPath itemTpl <- loadTemplate itemPath
body <- makeItem =<< applyTemplateList itemTpl itemContext' items body <- makeItem =<< applyTemplateList itemTpl itemContext' items
applyTemplate feedTpl feedContext body applyTemplate feedTpl feedContext body
where where
-- Auxiliary: load a template from a datafile -- Auxiliary: load a template from a datafile
loadTemplate = fmap readTemplate . readFile <=< getDataFileName loadTemplate path = do
file <- compilerUnsafeIO $ getDataFileName path
unsafeReadTemplateFile file
itemContext' = mconcat itemContext' = mconcat
[ itemContext [ itemContext

View file

@ -128,7 +128,7 @@
-- > <p> -- > <p>
-- > $for(counts)-$ -- > $for(counts)-$
-- > $count$ -- > $count$
-- > $-sep-$... -- > $-sep$...
-- > $-endfor$ -- > $-endfor$
-- > </p> -- > </p>
-- --
@ -148,6 +148,7 @@ module Hakyll.Web.Template
, loadAndApplyTemplate , loadAndApplyTemplate
, applyAsTemplate , applyAsTemplate
, readTemplate , readTemplate
, unsafeReadTemplateFile
) where ) where
@ -188,24 +189,31 @@ instance IsString Template where
fromString = readTemplate fromString = readTemplate
--------------------------------------------------------------------------------
-- | Wrap the constructor to ensure trim is called.
template :: [TemplateElement] -> Template
template = Template . trim
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
readTemplate :: String -> Template readTemplate :: String -> Template
readTemplate = Template . trim . readTemplateElems readTemplate = Template . trim . readTemplateElems
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Read a template, without metadata header -- | Read a template, without metadata header
templateBodyCompiler :: Compiler (Item Template) templateBodyCompiler :: Compiler (Item Template)
templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
item <- getResourceBody item <- getResourceBody
return $ fmap readTemplate item file <- getResourceFilePath
return $ fmap (template . readTemplateElemsFile file) item
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Read complete file contents as a template -- | Read complete file contents as a template
templateCompiler :: Compiler (Item Template) templateCompiler :: Compiler (Item Template)
templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
item <- getResourceString item <- getResourceString
return $ fmap readTemplate item file <- getResourceFilePath
return $ fmap (template . readTemplateElemsFile file) item
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -317,5 +325,14 @@ applyAsTemplate :: Context String -- ^ Context
-> Item String -- ^ Item and template -> Item String -- ^ Item and template
-> Compiler (Item String) -- ^ Resulting item -> Compiler (Item String) -- ^ Resulting item
applyAsTemplate context item = applyAsTemplate context item =
let tpl = readTemplate $ itemBody item let tpl = template $ readTemplateElemsFile file (itemBody item)
file = toFilePath $ itemIdentifier item
in applyTemplate tpl context item in applyTemplate tpl context item
--------------------------------------------------------------------------------
unsafeReadTemplateFile :: FilePath -> Compiler Template
unsafeReadTemplateFile file = do
tpl <- unsafeCompiler $ readFile file
pure $ template $ readTemplateElemsFile file tpl

View file

@ -7,6 +7,7 @@ module Hakyll.Web.Template.Internal
, TemplateElement (..) , TemplateElement (..)
, templateElems , templateElems
, readTemplateElems , readTemplateElems
, readTemplateElemsFile
) where ) where
@ -108,7 +109,12 @@ instance Binary TemplateExpr where
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
readTemplateElems :: String -> [TemplateElement] readTemplateElems :: String -> [TemplateElement]
readTemplateElems input = case P.parse templateElems "" input of readTemplateElems = readTemplateElemsFile "{literal}"
--------------------------------------------------------------------------------
readTemplateElemsFile :: FilePath -> String -> [TemplateElement]
readTemplateElemsFile file input = case P.parse templateElems file input of
Left err -> error $ "Cannot parse template: " ++ show err Left err -> error $ "Cannot parse template: " ++ show err
Right t -> t Right t -> t
@ -116,12 +122,12 @@ readTemplateElems input = case P.parse templateElems "" input of
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
templateElems :: P.Parser [TemplateElement] templateElems :: P.Parser [TemplateElement]
templateElems = mconcat <$> P.many (P.choice [ lift chunk templateElems = mconcat <$> P.many (P.choice [ lift chunk
, lift escaped , lift escaped
, conditional , conditional
, for , for
, partial , partial
, expr , expr
]) ])
where lift = fmap (:[]) where lift = fmap (:[])

View file

@ -32,13 +32,13 @@ content and a generic configuration.
If `hakyll-init` is not found, you should make sure your stack bin path If `hakyll-init` is not found, you should make sure your stack bin path
(usually `$HOME/.local/bin`) is in your `$PATH`. You can check your stack local (usually `$HOME/.local/bin`) is in your `$PATH`. You can check your stack local
bin path by running `stack path --local-bin-path`. bin path by running `stack path --local-bin`.
The file `site.hs` holds the configuration of your site, as an executable The file `site.hs` holds the configuration of your site, as an executable
haskell program. We can compile and run it like this: haskell program. We can compile and run it like this:
$ cd my-site $ cd my-site
$ stack init # Optional, if you haven't used stack before $ stack init # creates stack.yaml file based on my-site.cabal
$ stack build $ stack build
$ stack exec site build $ stack exec site build

View file

@ -0,0 +1,6 @@
---
title: Live Reloading with Hakyll
author: Ben Kolera
url: 'http://benkolera.com/posts/2015-09-14-hakyll_livereload.html'
external: true
---