From 3d713e9f2c08dc40e67340b9e6717bb6f6adb20c Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Fri, 22 Jul 2016 16:37:18 +0200 Subject: [PATCH 1/6] Fail if template is not parsed until eof This should fix the second problem in #376. --- src/Hakyll/Web/Template/Internal.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs index 45db2e4..aa8e080 100644 --- a/src/Hakyll/Web/Template/Internal.hs +++ b/src/Hakyll/Web/Template/Internal.hs @@ -120,15 +120,22 @@ instance Binary TemplateExpr where -------------------------------------------------------------------------------- readTemplate :: String -> Template -readTemplate input = case P.parse template "" input of +readTemplate input = case P.parse topLevelTemplate "" input of Left err -> error $ "Cannot parse template: " ++ show err Right t -> t +-------------------------------------------------------------------------------- +topLevelTemplate :: P.Parser Template +topLevelTemplate = Template <$> + P.manyTill templateElement P.eof -------------------------------------------------------------------------------- template :: P.Parser Template -template = Template <$> - (P.many $ chunk <|> escaped <|> conditional <|> for <|> partial <|> expr) +template = Template <$> P.many templateElement + +-------------------------------------------------------------------------------- +templateElement :: P.Parser TemplateElement +templateElement = chunk <|> escaped <|> conditional <|> for <|> partial <|> expr -------------------------------------------------------------------------------- From 56de1d069d296dd05ef05fe10594aa088c0036c0 Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Sat, 23 Jul 2016 12:06:42 +0200 Subject: [PATCH 2/6] s/--local-bin-path/--local-bin/ output of `stack path --local-bin-path`: ``` Run from outside a project, using implicit global project config Using resolver: lts-6.8 from implicit global project's config file: /home/REDACTED/.stack/global-project/stack.yaml '--local-bin-path' will be removed in a future release. Please use '--local-bin' instead. ``` --- web/tutorials/01-installation.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/tutorials/01-installation.markdown b/web/tutorials/01-installation.markdown index a8ffc00..7bbfc54 100644 --- a/web/tutorials/01-installation.markdown +++ b/web/tutorials/01-installation.markdown @@ -32,7 +32,7 @@ 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: From 24e6d6865ac682ad8c0e3737c7be7ac9ae6ea74e Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 23 Jul 2016 12:13:42 +0200 Subject: [PATCH 3/6] Change note for stack init --- web/tutorials/01-installation.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/tutorials/01-installation.markdown b/web/tutorials/01-installation.markdown index a8ffc00..20688e8 100644 --- a/web/tutorials/01-installation.markdown +++ b/web/tutorials/01-installation.markdown @@ -38,7 +38,7 @@ 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 # To create stack.yaml $ stack build $ stack exec site build From 70ee447ff10b2ca46a28f8a5c8a250c48d91e46e Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Sat, 23 Jul 2016 12:14:31 +0200 Subject: [PATCH 4/6] stack init is not really optional stack build complains if there is no stack.yaml so the previous comment is misleading for people who don't know what stack init does. --- web/tutorials/01-installation.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/tutorials/01-installation.markdown b/web/tutorials/01-installation.markdown index 20688e8..a82ea1d 100644 --- a/web/tutorials/01-installation.markdown +++ b/web/tutorials/01-installation.markdown @@ -38,7 +38,7 @@ 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 # To create stack.yaml + $ stack init # creates stack.yaml file based on my-site.cabal $ stack build $ stack exec site build From 871cfd36ddd143f8fad14657e1c1fd80a9e6c66f Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Sat, 23 Jul 2016 12:31:03 +0200 Subject: [PATCH 5/6] Include file name in error messages --- src/Hakyll/Web/Feed.hs | 6 +++++- src/Hakyll/Web/Template.hs | 9 ++++++--- src/Hakyll/Web/Template/Internal.hs | 9 ++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Hakyll/Web/Feed.hs b/src/Hakyll/Web/Feed.hs index 8598f8a..16b6dc0 100644 --- a/src/Hakyll/Web/Feed.hs +++ b/src/Hakyll/Web/Feed.hs @@ -33,6 +33,7 @@ import Hakyll.Core.Compiler.Internal import Hakyll.Core.Item import Hakyll.Web.Template import Hakyll.Web.Template.Context +import Hakyll.Web.Template.Internal import Hakyll.Web.Template.List @@ -72,7 +73,10 @@ renderFeed feedPath itemPath config itemContext items = do applyTemplate feedTpl feedContext body where -- Auxiliary: load a template from a datafile - loadTemplate = fmap readTemplate . readFile <=< getDataFileName + loadTemplate path = do + file <- getDataFileName path + templ <- readFile file + return $ readTemplateFile file templ itemContext' = mconcat [ itemContext diff --git a/src/Hakyll/Web/Template.hs b/src/Hakyll/Web/Template.hs index 65c4ac9..a662906 100644 --- a/src/Hakyll/Web/Template.hs +++ b/src/Hakyll/Web/Template.hs @@ -147,14 +147,16 @@ import Hakyll.Web.Template.Internal templateBodyCompiler :: Compiler (Item Template) templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do item <- getResourceBody - return $ fmap readTemplate item + file <- getResourceFilePath + return $ fmap (readTemplateFile 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 (readTemplateFile file) item -------------------------------------------------------------------------------- @@ -259,5 +261,6 @@ applyAsTemplate :: Context String -- ^ Context -> Item String -- ^ Item and template -> Compiler (Item String) -- ^ Resulting item applyAsTemplate context item = - let tpl = readTemplate $ itemBody item + let tpl = readTemplateFile file (itemBody item) + file = toFilePath $ itemIdentifier item in applyTemplate tpl context item diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs index aa8e080..a63c40d 100644 --- a/src/Hakyll/Web/Template/Internal.hs +++ b/src/Hakyll/Web/Template/Internal.hs @@ -8,6 +8,7 @@ module Hakyll.Web.Template.Internal , TemplateExpr (..) , TemplateElement (..) , readTemplate + , readTemplateFile ) where @@ -120,10 +121,16 @@ instance Binary TemplateExpr where -------------------------------------------------------------------------------- readTemplate :: String -> Template -readTemplate input = case P.parse topLevelTemplate "" input of +readTemplate = readTemplateFile "{literal}" + + +-------------------------------------------------------------------------------- +readTemplateFile :: FilePath -> String -> Template +readTemplateFile file input = case P.parse topLevelTemplate file input of Left err -> error $ "Cannot parse template: " ++ show err Right t -> t + -------------------------------------------------------------------------------- topLevelTemplate :: P.Parser Template topLevelTemplate = Template <$> From 94c94376cfc01df8f80562352f7470817bc75d3f Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 23 Jul 2016 12:53:00 +0200 Subject: [PATCH 6/6] Add tutorial on live reload --- web/tutorials/external-live-reload.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 web/tutorials/external-live-reload.md diff --git a/web/tutorials/external-live-reload.md b/web/tutorials/external-live-reload.md new file mode 100644 index 0000000..38f1c96 --- /dev/null +++ b/web/tutorials/external-live-reload.md @@ -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 +---