From 5a4ae4147313f52d50ff3bd9d74340a86175a5d9 Mon Sep 17 00:00:00 2001 From: Bergi Date: Wed, 21 Oct 2015 22:14:39 +0200 Subject: templateBodyCompiler compiles resource body only and becomes the new default, instead of templateCompiler fixes #378 --- data/example/site.hs | 2 +- src/Hakyll/Web/Template.hs | 10 +++++++++- tests/Hakyll/Web/Template/Tests.hs | 2 +- web/tutorials/04-compilers.markdown | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/data/example/site.hs b/data/example/site.hs index be041f8..2751f77 100644 --- a/data/example/site.hs +++ b/data/example/site.hs @@ -57,7 +57,7 @@ main = hakyll $ do >>= loadAndApplyTemplate "templates/default.html" indexCtx >>= relativizeUrls - match "templates/*" $ compile templateCompiler + match "templates/*" $ compile templateBodyCompiler -------------------------------------------------------------------------------- diff --git a/src/Hakyll/Web/Template.hs b/src/Hakyll/Web/Template.hs index d28ce08..194949d 100644 --- a/src/Hakyll/Web/Template.hs +++ b/src/Hakyll/Web/Template.hs @@ -118,6 +118,7 @@ {-# LANGUAGE ScopedTypeVariables #-} module Hakyll.Web.Template ( Template + , templateBodyCompiler , templateCompiler , applyTemplate , loadAndApplyTemplate @@ -143,7 +144,14 @@ import Hakyll.Web.Template.Internal -------------------------------------------------------------------------------- --- | Read a template. +-- | Read a template, without metadata header +templateBodyCompiler :: Compiler (Item Template) +templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do + item <- getResourceBody + return $ fmap readTemplate item + +-------------------------------------------------------------------------------- +-- | Read complete file contents as a template templateCompiler :: Compiler (Item Template) templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do item <- getResourceString diff --git a/tests/Hakyll/Web/Template/Tests.hs b/tests/Hakyll/Web/Template/Tests.hs index ea3a9b2..a975901 100644 --- a/tests/Hakyll/Web/Template/Tests.hs +++ b/tests/Hakyll/Web/Template/Tests.hs @@ -51,7 +51,7 @@ case01 = do out <- resourceString provider "template.html.out" tpl <- testCompilerDone store provider "template.html" $ - templateCompiler + templateBodyCompiler item <- testCompilerDone store provider "example.md" $ pandocCompiler >>= applyTemplate (itemBody tpl) testContext diff --git a/web/tutorials/04-compilers.markdown b/web/tutorials/04-compilers.markdown index 49935e1..d283e9a 100644 --- a/web/tutorials/04-compilers.markdown +++ b/web/tutorials/04-compilers.markdown @@ -53,10 +53,10 @@ when the template is applied. If you want an actual dollar sign in the output, use `$$`. You usually compile the templates from disk using the aptly named -`templateCompiler`: +`templateBodyCompiler`: ```haskell -match "templates/*" $ compile templateCompiler +match "templates/*" $ compile templateBodyCompiler ``` Notice the lack of `route` here: this is because we don't need to write the -- cgit v1.2.3