mirror of
https://github.com/ilyakooo0/hakyll.git
synced 2024-10-06 09:17:15 +03:00
Fix merge conflicts
This commit is contained in:
commit
11ef948720
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
@ -116,12 +122,12 @@ readTemplateElems input = case P.parse templateElems "" input of
|
||||
--------------------------------------------------------------------------------
|
||||
templateElems :: P.Parser [TemplateElement]
|
||||
templateElems = mconcat <$> P.many (P.choice [ lift chunk
|
||||
, lift escaped
|
||||
, conditional
|
||||
, for
|
||||
, partial
|
||||
, expr
|
||||
])
|
||||
, lift escaped
|
||||
, conditional
|
||||
, for
|
||||
, partial
|
||||
, expr
|
||||
])
|
||||
where lift = fmap (:[])
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
6
web/tutorials/external-live-reload.md
Normal file
6
web/tutorials/external-live-reload.md
Normal 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
|
||||
---
|
Loading…
Reference in New Issue
Block a user