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

View file

@ -128,7 +128,7 @@
-- > <p>
-- > $for(counts)-$
-- > $count$
-- > $-sep-$...
-- > $-sep$...
-- > $-endfor$
-- > </p>
--
@ -148,6 +148,7 @@ module Hakyll.Web.Template
, loadAndApplyTemplate
, applyAsTemplate
, readTemplate
, unsafeReadTemplateFile
) where
@ -188,24 +189,31 @@ instance IsString Template where
fromString = readTemplate
--------------------------------------------------------------------------------
-- | Wrap the constructor to ensure trim is called.
template :: [TemplateElement] -> Template
template = Template . trim
--------------------------------------------------------------------------------
readTemplate :: String -> Template
readTemplate = Template . trim . readTemplateElems
--------------------------------------------------------------------------------
-- | Read a template, without metadata header
templateBodyCompiler :: Compiler (Item Template)
templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
item <- getResourceBody
return $ fmap readTemplate item
file <- getResourceFilePath
return $ fmap (template . readTemplateElemsFile file) item
--------------------------------------------------------------------------------
-- | Read complete file contents as a template
templateCompiler :: Compiler (Item Template)
templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
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
-> Compiler (Item String) -- ^ Resulting 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
--------------------------------------------------------------------------------
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 (..)
, templateElems
, readTemplateElems
, readTemplateElemsFile
) where
@ -108,7 +109,12 @@ instance Binary TemplateExpr where
--------------------------------------------------------------------------------
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
Right t -> t

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
(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
haskell program. We can compile and run it like this:
$ 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 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
---