on master help sign in
57 files changed+880−351
since splitsnapshots
unifiedsplit
.circleci/config.yml+5−11 CHANGELOG.md+52 hakyll.cabal+15−12 lib/Hakyll/Core/Compiler.hs+35−2 lib/Hakyll/Core/Compiler/Internal.hs+126−41 lib/Hakyll/Core/Compiler/Require.hs+2 lib/Hakyll/Core/Identifier.hs+1−1 lib/Hakyll/Core/Logger.hs+9−3 lib/Hakyll/Core/Provider/Metadata.hs+3−2 lib/Hakyll/Core/Runtime.hs+3−3 lib/Hakyll/Core/Store.hs+26−23 lib/Hakyll/Web/Feed.hs+51−32 lib/Hakyll/Web/Html.hs+1−1 lib/Hakyll/Web/Tags.hs+2−1 lib/Hakyll/Web/Template.hs+24−2 lib/Hakyll/Web/Template/Context.hs+122−32 lib/Hakyll/Web/Template/Internal.hs+103−44 lib/Hakyll/Web/Template/Internal/Element.hs+7−14 stack.yaml+9−7 tests/Hakyll/Core/UnixFilter/Tests.hs+6−14 tests/Hakyll/Web/Template/Context/Tests.hs+40−3 tests/Hakyll/Web/Template/Tests.hs+49−17 tests/TestSuite.hs+2 tests/TestSuite/Util.hs+11−2 tests/data/embed.html+1 tests/data/posts/2018-09-26.md+1 tests/data/posts/2019/05/10/tomorrow.md+1 web/css/syntax.css+61−18 web/examples.markdown+20−6 web/site.hs+14−32 web/templates/tutorials.html+24−18 web/tutorials/01-installation.markdown+4−2 web/tutorials/02-basics.markdown+1 web/tutorials/03-rules-routes-compilers.markdown+1 web/tutorials/04-compilers.markdown+1 web/tutorials/05-snapshots-feeds.markdown+1 web/tutorials/06-versions.markdown+1 web/tutorials/a-guide-to-the-hakyll-module-zoo.markdown+1 web/tutorials/external-add-tags-to-your-hakyll-blog.md+1−1 web/tutorials/external-blogger-port.md+1−1 web/tutorials/external-cassius-template.md+1−1 web/tutorials/external-clean-urls-with-hakyll.md+1−1 web/tutorials/external-deploying-with-widely.md+1−1 web/tutorials/external-external-code-inclusion.md+6 web/tutorials/external-functionfield.md+1−1 web/tutorials/external-github-pages-circle-ci.md+1−1 web/tutorials/external-inlining-and-compressing-css.md+1−1 web/tutorials/faq.markdown+1 web/tutorials/github-pages-tutorial.md+1 web/tutorials/hakyll-3-to-hakyll4-migration-guide.markdown+1 web/tutorials/robertwpearce-01-setup-and-initial-customization.html+5 web/tutorials/robertwpearce-02-generating-a-sitemap-xml-file.html+5 web/tutorials/robertwpearce-03-generating-rss-and-atom-xml-feeds.html+5 web/tutorials/robertwpearce-04-copying-static-files-for-your-build.html+5 web/tutorials/robertwpearce-05-generating-custom-post-filenames-from-a-title-slug.html+5 web/tutorials/using-clay-with-hakyll.markdown+1 web/tutorials/using-teasers-in-hakyll.markdown+1
.circleci/config.yml+5−11
@@ -6,20 +6,14 @@ jobs:
66 steps:
77 - checkout
88 - restore_cache:
9− key: 'v2-hakyll-{{ arch }}-{{ .Branch }}'
10− - run:
11− name: 'Update cabal indices'
12− command: 'cabal update'
9+ key: 'v3-hakyll-{{ arch }}-{{ .Branch }}'
1310 - run:
1411 # We set jobs to 1 here because that prevents Out-Of-Memory exceptions
1512 # while compiling dependencies.
1613 name: 'Install dependencies'
17− command: '.circleci/tickle.sh cabal install --only-dependencies --enable-tests --jobs=1 --flags="+buildWebsite"'
18− - run:
19− name: 'Build and run tests'
20− command: 'cabal test'
14+ command: '.circleci/tickle.sh stack build --test --copy-bins --jobs=1'
2115 - save_cache:
22− key: 'v2-hakyll-{{ arch }}-{{ .Branch }}-{{ .Revision }}'
16+ key: 'v3-hakyll-{{ arch }}-{{ .Branch }}-{{ .Revision }}'
2317 paths:
24− - '~/.cabal'
25− - '~/.ghc'
18+ - '~/.stack-work'
19+ - '~/.stack'
CHANGELOG.md+52
@@ -4,6 +4,58 @@ title: Releases
44
55# Releases
66
7+## Hakyll 4.13.0.0 (2019-08-30)
8+
9+- Improved documentation in many places (contribution by Bergi)
10+- Significantly improve error messages when reading and applying templates
11+ (contribution by Bergi)
12+ * `empty` and `fail` for `Compiler` now fail without or with a message,
13+ allowing for much better debug output
14+ * `renderFeed`, `renderRssWithTemplates` and `renderAtomWithTemplates` now
15+ take `Template` rather than `String` arguments
16+- Add option to specify date in directory structure,e.g.
17+ `posts/2019/05/10/tomorrow.md` (contribution by Taeer Bar-Ya)
18+- Bump QuickCheck to 2.13
19+
20+## Hakyll 4.12.5.2 (2019-05-09)
21+
22+- Bump pandoc to 2.7
23+- Add `srcset` to the list of URL attributes (contribution by c50a326)
24+- Expose `getCategory` in `Hakyll.Web.Tags` (contribution by Ng Wei En)
25+- Fix issue where `published` overwrites the user's context (contribution by
26+ ncaq)
27+
28+## Hakyll 4.12.5.1 (2019-02-03)
29+
30+- Bump pandoc to 2.6
31+- Bump pandoc-citeproc to 0.16
32+
33+## Hakyll 4.12.5.0 (2019-01-12)
34+
35+- Update dependencies (contribution by Hexirp):
36+ * Bump containers to 0.6
37+ * Bump yaml to 0.11
38+ * Bump pandoc to 2.5
39+ * Bump pandoc-citeproc to 0.15
40+ * Bump tasty to 1.2
41+- Correct assertion in unixFilterError test
42+ (contribution by Jim McStanton)
43+- Add renderRssWithTemplates, renderAtomWithTemplates
44+ (contribution by Abhinav Sarkar)
45+- Speed up hashing in cache (contribution by 0xd34df00d)
46+- Update type of fromFilePath to use FilePath instead of String
47+ (contribution by Jim McStanton)
48+- Drop extension when parsing dates in filepaths (contribution by
49+ Gabriel Aumala)
50+
51+## Hakyll 4.12.4.0 (2018-08-13)
52+
53+- Bump yaml to 0.10
54+- Bump file-embed to 0.0.11
55+- Bump QuickCheck to 2.12
56+- Use makeRelativeToProject with embedFile for stack ghci (contribution by
57+ Michael Sloan)
58+
759## Hakyll 4.12.3.0 (2018-05-29)
860
961- Bump tasty to 1.1
hakyll.cabal+15−12
@@ -1,5 +1,5 @@
11Name: hakyll
2−Version: 4.12.3.0
2+Version: 4.13.0.0
33
44Synopsis: A static website compiler library
55Description:
@@ -68,6 +68,7 @@ Extra-source-files:
6868 tests/data/partial.html
6969 tests/data/partial.html.out
7070 tests/data/posts/2010-08-26-birthday.md
71+ tests/data/posts/2018-09-26.md
7172 tests/data/russian.md
7273 tests/data/strip.html
7374 tests/data/strip.html.out
@@ -166,15 +167,17 @@ Library
166167 blaze-html >= 0.5 && < 0.10,
167168 blaze-markup >= 0.5.1 && < 0.9,
168169 bytestring >= 0.9 && < 0.11,
169− containers >= 0.3 && < 0.6,
170+ containers >= 0.3 && < 0.7,
170171 cryptohash >= 0.7 && < 0.12,
171172 data-default >= 0.4 && < 0.8,
172173 deepseq >= 1.3 && < 1.5,
173174 directory >= 1.0 && < 1.4,
175+ file-embed >= 0.0.10.1 && < 0.0.12,
174176 filepath >= 1.0 && < 1.5,
175177 lrucache >= 1.1.1 && < 1.3,
176178 mtl >= 1 && < 2.3,
177179 network-uri >= 2.6 && < 2.7,
180+ optparse-applicative >= 0.12 && < 0.15,
178181 parsec >= 3.0 && < 3.2,
179182 process >= 1.6 && < 1.7,
180183 random >= 1.0 && < 1.2,
@@ -182,14 +185,13 @@ Library
182185 resourcet >= 1.1 && < 1.3,
183186 scientific >= 0.3.4 && < 0.4,
184187 tagsoup >= 0.13.1 && < 0.15,
188+ template-haskell >= 2.14 && < 2.15,
185189 text >= 0.11 && < 1.3,
186190 time >= 1.8 && < 1.10,
187191 time-locale-compat >= 0.1 && < 0.2,
188192 unordered-containers >= 0.2 && < 0.3,
189193 vector >= 0.11 && < 0.13,
190− yaml >= 0.8.11 && < 0.10,
191− optparse-applicative >= 0.12 && < 0.15,
192− file-embed >= 0.0.10.1 && < 0.0.11
194+ yaml >= 0.8.11 && < 0.12
193195
194196 If flag(previewServer)
195197 Build-depends:
@@ -227,8 +229,8 @@ Library
227229 Other-Modules:
228230 Hakyll.Web.Pandoc.Binary
229231 Build-Depends:
230− pandoc >= 2.0.5 && < 2.3,
231− pandoc-citeproc >= 0.14 && < 0.15
232+ pandoc >= 2.0.5 && < 2.8,
233+ pandoc-citeproc >= 0.14 && < 0.17
232234 Cpp-options:
233235 -DUSE_PANDOC
234236
@@ -253,24 +255,25 @@ Test-suite hakyll-tests
253255 Hakyll.Web.CompressCss.Tests
254256 Hakyll.Web.Html.RelativizeUrls.Tests
255257 Hakyll.Web.Html.Tests
258+ Hakyll.Web.Tags.Tests
256259 Hakyll.Web.Template.Context.Tests
257260 Hakyll.Web.Template.Tests
258261 TestSuite.Util
259262
260263 Build-Depends:
261264 hakyll,
262− QuickCheck >= 2.8 && < 2.12,
263− tasty >= 0.11 && < 1.2,
265+ QuickCheck >= 2.8 && < 2.14,
266+ tasty >= 0.11 && < 1.3,
264267 tasty-hunit >= 0.9 && < 0.11,
265268 tasty-quickcheck >= 0.8 && < 0.11,
266269 -- Copy pasted from hakyll dependencies:
267270 base >= 4.8 && < 5,
268271 bytestring >= 0.9 && < 0.11,
269− containers >= 0.3 && < 0.6,
272+ containers >= 0.3 && < 0.7,
270273 filepath >= 1.0 && < 1.5,
271274 text >= 0.11 && < 1.3,
272275 unordered-containers >= 0.2 && < 0.3,
273− yaml >= 0.8.11 && < 0.10
276+ yaml >= 0.8.11 && < 0.12
274277
275278 If flag(previewServer)
276279 Cpp-options:
@@ -321,4 +324,4 @@ Executable hakyll-website
321324 base >= 4 && < 5,
322325 directory >= 1.0 && < 1.4,
323326 filepath >= 1.0 && < 1.5,
324− pandoc >= 2.0.5 && < 2.3
327+ pandoc >= 2.0.5 && < 2.8
lib/Hakyll/Core/Compiler.hs+35−2
@@ -24,13 +24,16 @@ module Hakyll.Core.Compiler
2424 , cached
2525 , unsafeCompiler
2626 , debugCompiler
27+ , noResult
28+ , withErrorMessage
2729 ) where
2830
2931
3032--------------------------------------------------------------------------------
31−import Control.Monad (when, unless)
33+import Control.Monad (unless, when, (>=>))
3234import Data.Binary (Binary)
3335import Data.ByteString.Lazy (ByteString)
36+import qualified Data.List.NonEmpty as NonEmpty
3437import Data.Typeable (Typeable)
3538import System.Environment (getProgName)
3639import System.FilePath (takeExtension)
@@ -62,6 +65,7 @@ getUnderlyingExtension = takeExtension . toFilePath <$> getUnderlying
6265
6366
6467--------------------------------------------------------------------------------
68+-- | Create an item from the underlying identifier and a given value.
6569makeItem :: a -> Compiler (Item a)
6670makeItem x = do
6771 identifier <- getUnderlying
@@ -141,6 +145,10 @@ saveSnapshot snapshot item = do
141145
142146
143147--------------------------------------------------------------------------------
148+-- | Turn on caching for a compilation value to avoid recomputing it
149+-- on subsequent Hakyll runs.
150+-- The storage key consists of the underlying identifier of the compiled
151+-- ressource and the given name.
144152cached :: (Binary a, Typeable a)
145153 => String
146154 -> Compiler a
@@ -177,12 +185,37 @@ cached name compiler = do
177185
178186
179187--------------------------------------------------------------------------------
188+-- | Run an IO computation without dependencies in a Compiler
180189unsafeCompiler :: IO a -> Compiler a
181190unsafeCompiler = compilerUnsafeIO
182191
183192
184193--------------------------------------------------------------------------------
185−-- | Compiler for debugging purposes
194+-- | Fail so that it is treated as non-defined in an @\$if()\$@ branching
195+-- "Hakyll.Web.Template" macro, and alternative
196+-- 'Hakyll.Web.Template.Context.Context's are tried
197+--
198+-- @since 4.13.0
199+noResult :: String -> Compiler a
200+noResult = compilerNoResult . return
201+
202+
203+--------------------------------------------------------------------------------
204+-- | Prepend an error line to the error, if there is one. This allows you to
205+-- add helpful context to error messages.
206+--
207+-- @since 4.13.0
208+withErrorMessage :: String -> Compiler a -> Compiler a
209+withErrorMessage x = do
210+ compilerTry >=> either (compilerResult . CompilerError . prepend) return
211+ where
212+ prepend (CompilationFailure es) = CompilationFailure (x `NonEmpty.cons` es)
213+ prepend (CompilationNoResult es) = CompilationNoResult (x : es)
214+
215+
216+--------------------------------------------------------------------------------
217+-- | Compiler for debugging purposes.
218+-- Passes a message to the debug logger that is printed in verbose mode.
186219debugCompiler :: String -> Compiler ()
187220debugCompiler msg = do
188221 logger <- compilerLogger <$> compilerAsk
lib/Hakyll/Core/Compiler/Internal.hs+126−41
@@ -1,6 +1,7 @@
11--------------------------------------------------------------------------------
22-- | Internally used compiler module
33{-# LANGUAGE CPP #-}
4+{-# LANGUAGE DeriveFunctor #-}
45{-# LANGUAGE FlexibleInstances #-}
56{-# LANGUAGE GADTs #-}
67{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -10,19 +11,26 @@ module Hakyll.Core.Compiler.Internal
1011 Snapshot
1112 , CompilerRead (..)
1213 , CompilerWrite (..)
14+ , CompilerErrors (..)
1315 , CompilerResult (..)
1416 , Compiler (..)
1517 , runCompiler
1618
1719 -- * Core operations
20+ , compilerResult
1821 , compilerTell
1922 , compilerAsk
23+ , compilerUnsafeIO
24+
25+ -- * Error operations
2026 , compilerThrow
27+ , compilerNoResult
2128 , compilerCatch
22− , compilerResult
23− , compilerUnsafeIO
29+ , compilerTry
30+ , compilerErrorMessages
2431
2532 -- * Utilities
33+ , compilerDebugEntries
2634 , compilerTellDependencies
2735 , compilerTellCacheHits
2836 ) where
@@ -32,7 +40,9 @@ module Hakyll.Core.Compiler.Internal
3240import Control.Applicative (Alternative (..))
3341import Control.Exception (SomeException, handle)
3442import Control.Monad (forM_)
35−import Control.Monad.Except (MonadError (..))
43+import Control.Monad.Except (MonadError (..))
44+import Data.List.NonEmpty (NonEmpty (..))
45+import qualified Data.List.NonEmpty as NonEmpty
3646#if MIN_VERSION_base(4,9,0)
3747import Data.Semigroup (Semigroup (..))
3848#endif
@@ -45,7 +55,6 @@ import Hakyll.Core.Configuration
4555import Hakyll.Core.Dependencies
4656import Hakyll.Core.Identifier
4757import Hakyll.Core.Identifier.Pattern
48−import Hakyll.Core.Logger (Logger)
4958import qualified Hakyll.Core.Logger as Logger
5059import Hakyll.Core.Metadata
5160import Hakyll.Core.Provider
@@ -75,7 +84,7 @@ data CompilerRead = CompilerRead
7584 , -- | Compiler store
7685 compilerStore :: Store
7786 , -- | Logger
78− compilerLogger :: Logger
87+ compilerLogger :: Logger.Logger
7988 }
8089
8190
@@ -104,11 +113,29 @@ instance Monoid CompilerWrite where
104113
105114
106115--------------------------------------------------------------------------------
107−data CompilerResult a where
108− CompilerDone :: a -> CompilerWrite -> CompilerResult a
109− CompilerSnapshot :: Snapshot -> Compiler a -> CompilerResult a
110− CompilerError :: [String] -> CompilerResult a
111− CompilerRequire :: (Identifier, Snapshot) -> Compiler a -> CompilerResult a
116+-- | Distinguishes reasons in a 'CompilerError'
117+data CompilerErrors a
118+ -- | One or more exceptions occured during compilation
119+ = CompilationFailure (NonEmpty a)
120+ -- | Absence of any result, most notably in template contexts. May still
121+ -- have error messages.
122+ | CompilationNoResult [a]
123+ deriving Functor
124+
125+
126+-- | Unwrap a `CompilerErrors`
127+compilerErrorMessages :: CompilerErrors a -> [a]
128+compilerErrorMessages (CompilationFailure x) = NonEmpty.toList x
129+compilerErrorMessages (CompilationNoResult x) = x
130+
131+
132+--------------------------------------------------------------------------------
133+-- | An intermediate result of a compilation step
134+data CompilerResult a
135+ = CompilerDone a CompilerWrite
136+ | CompilerSnapshot Snapshot (Compiler a)
137+ | CompilerRequire (Identifier, Snapshot) (Compiler a)
138+ | CompilerError (CompilerErrors String)
112139
113140
114141--------------------------------------------------------------------------------
@@ -126,14 +153,14 @@ instance Functor Compiler where
126153 return $ case res of
127154 CompilerDone x w -> CompilerDone (f x) w
128155 CompilerSnapshot s c' -> CompilerSnapshot s (fmap f c')
129− CompilerError e -> CompilerError e
130156 CompilerRequire i c' -> CompilerRequire i (fmap f c')
157+ CompilerError e -> CompilerError e
131158 {-# INLINE fmap #-}
132159
133160
134161--------------------------------------------------------------------------------
135162instance Monad Compiler where
136− return x = Compiler $ \_ -> return $ CompilerDone x mempty
163+ return x = compilerResult $ CompilerDone x mempty
137164 {-# INLINE return #-}
138165
139166 Compiler c >>= f = Compiler $ \r -> do
@@ -146,14 +173,14 @@ instance Monad Compiler where
146173 CompilerSnapshot s c' -> CompilerSnapshot s $ do
147174 compilerTell w -- Save dependencies!
148175 c'
149− CompilerError e -> CompilerError e
150176 CompilerRequire i c' -> CompilerRequire i $ do
151177 compilerTell w -- Save dependencies!
152178 c'
179+ CompilerError e -> CompilerError e
153180
154181 CompilerSnapshot s c' -> return $ CompilerSnapshot s (c' >>= f)
155− CompilerError e -> return $ CompilerError e
156182 CompilerRequire i c' -> return $ CompilerRequire i (c' >>= f)
183+ CompilerError e -> return $ CompilerError e
157184 {-# INLINE (>>=) #-}
158185
159186 fail = compilerThrow . return
@@ -170,87 +197,145 @@ instance Applicative Compiler where
170197
171198
172199--------------------------------------------------------------------------------
200+-- | Access provided metadata from anywhere
173201instance MonadMetadata Compiler where
174202 getMetadata = compilerGetMetadata
175203 getMatches = compilerGetMatches
176204
177205
178206--------------------------------------------------------------------------------
207+-- | Compilation may fail with multiple error messages.
208+-- 'catchError' handles errors from 'throwError', 'fail' and 'Hakyll.Core.Compiler.noResult'
179209instance MonadError [String] Compiler where
180− throwError = compilerThrow
181− catchError = compilerCatch
210+ throwError = compilerThrow
211+ catchError c = compilerCatch c . (. compilerErrorMessages)
182212
183213
184214--------------------------------------------------------------------------------
215+-- | Like 'unCompiler' but treating IO exceptions as 'CompilerError's
185216runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
186217runCompiler compiler read' = handle handler $ unCompiler compiler read'
187218 where
188219 handler :: SomeException -> IO (CompilerResult a)
189− handler e = return $ CompilerError [show e]
220+ handler e = return $ CompilerError $ CompilationFailure $ show e :| []
190221
191222
192223--------------------------------------------------------------------------------
224+-- | Trying alternative compilers if the first fails, regardless whether through
225+-- 'fail', 'throwError' or 'Hakyll.Core.Compiler.noResult'.
226+-- Aggregates error messages if all fail.
193227instance Alternative Compiler where
194− empty = compilerThrow []
195− x <|> y = compilerCatch x $ \es -> do
196− logger <- compilerLogger <$> compilerAsk
197− forM_ es $ \e -> compilerUnsafeIO $ Logger.debug logger $
198− "Hakyll.Core.Compiler.Internal: Alternative failed: " ++ e
199− y
228+ empty = compilerNoResult []
229+ x <|> y = x `compilerCatch` (\rx -> y `compilerCatch` (\ry ->
230+ case (rx, ry) of
231+ (CompilationFailure xs, CompilationFailure ys) ->
232+ compilerThrow $ NonEmpty.toList xs ++ NonEmpty.toList ys
233+ (CompilationFailure xs, CompilationNoResult ys) ->
234+ debug ys >> compilerThrow (NonEmpty.toList xs)
235+ (CompilationNoResult xs, CompilationFailure ys) ->
236+ debug xs >> compilerThrow (NonEmpty.toList ys)
237+ (CompilationNoResult xs, CompilationNoResult ys) -> compilerNoResult $ xs ++ ys
238+ ))
239+ where
240+ debug = compilerDebugEntries "Hakyll.Core.Compiler.Internal: Alternative fail suppressed"
200241 {-# INLINE (<|>) #-}
201242
202243
203244--------------------------------------------------------------------------------
245+-- | Put the result back in a compiler
246+compilerResult :: CompilerResult a -> Compiler a
247+compilerResult x = Compiler $ \_ -> return x
248+{-# INLINE compilerResult #-}
249+
250+
251+--------------------------------------------------------------------------------
252+-- | Get the current environment
204253compilerAsk :: Compiler CompilerRead
205254compilerAsk = Compiler $ \r -> return $ CompilerDone r mempty
206255{-# INLINE compilerAsk #-}
207256
208257
209258--------------------------------------------------------------------------------
259+-- | Put a 'CompilerWrite'
210260compilerTell :: CompilerWrite -> Compiler ()
211−compilerTell deps = Compiler $ \_ -> return $ CompilerDone () deps
261+compilerTell = compilerResult . CompilerDone ()
212262{-# INLINE compilerTell #-}
213263
214264
215265--------------------------------------------------------------------------------
266+-- | Run an IO computation without dependencies in a Compiler
267+compilerUnsafeIO :: IO a -> Compiler a
268+compilerUnsafeIO io = Compiler $ \_ -> do
269+ x <- io
270+ return $ CompilerDone x mempty
271+{-# INLINE compilerUnsafeIO #-}
272+
273+
274+--------------------------------------------------------------------------------
275+-- | Throw errors in the 'Compiler'.
276+--
277+-- If no messages are given, this is considered a 'CompilationNoResult' error.
278+-- Otherwise, it is treated as a proper compilation failure.
216279compilerThrow :: [String] -> Compiler a
217−compilerThrow es = Compiler $ \_ -> return $ CompilerError es
218−{-# INLINE compilerThrow #-}
280+compilerThrow = compilerResult . CompilerError .
281+ maybe (CompilationNoResult []) CompilationFailure .
282+ NonEmpty.nonEmpty
283+
284+-- | Put a 'CompilerError' with multiple messages as 'CompilationNoResult'
285+compilerNoResult :: [String] -> Compiler a
286+compilerNoResult = compilerResult . CompilerError . CompilationNoResult
219287
220288
221289--------------------------------------------------------------------------------
222−compilerCatch :: Compiler a -> ([String] -> Compiler a) -> Compiler a
290+-- | Allows to distinguish 'CompilerError's and branch on them with 'Either'
291+--
292+-- prop> compilerTry = (`compilerCatch` return . Left) . fmap Right
293+compilerTry :: Compiler a -> Compiler (Either (CompilerErrors String) a)
294+compilerTry (Compiler x) = Compiler $ \r -> do
295+ res <- x r
296+ case res of
297+ CompilerDone res' w -> return (CompilerDone (Right res') w)
298+ CompilerSnapshot s c -> return (CompilerSnapshot s (compilerTry c))
299+ CompilerRequire i c -> return (CompilerRequire i (compilerTry c))
300+ CompilerError e -> return (CompilerDone (Left e) mempty)
301+{-# INLINE compilerTry #-}
302+
303+
304+--------------------------------------------------------------------------------
305+-- | Allows you to recover from 'CompilerError's.
306+-- Uses the same parameter order as 'catchError' so that it can be used infix.
307+--
308+-- prop> c `compilerCatch` f = compilerTry c >>= either f return
309+compilerCatch :: Compiler a -> (CompilerErrors String -> Compiler a) -> Compiler a
223310compilerCatch (Compiler x) f = Compiler $ \r -> do
224311 res <- x r
225312 case res of
226313 CompilerDone res' w -> return (CompilerDone res' w)
227314 CompilerSnapshot s c -> return (CompilerSnapshot s (compilerCatch c f))
228− CompilerError e -> unCompiler (f e) r
229315 CompilerRequire i c -> return (CompilerRequire i (compilerCatch c f))
316+ CompilerError e -> unCompiler (f e) r
230317{-# INLINE compilerCatch #-}
231318
232319
233320--------------------------------------------------------------------------------
234−-- | Put the result back in a compiler
235−compilerResult :: CompilerResult a -> Compiler a
236−compilerResult x = Compiler $ \_ -> return x
237−{-# INLINE compilerResult #-}
238−
321+compilerDebugLog :: [String] -> Compiler ()
322+compilerDebugLog ms = do
323+ logger <- compilerLogger <$> compilerAsk
324+ compilerUnsafeIO $ forM_ ms $ Logger.debug logger
239325
240326--------------------------------------------------------------------------------
241−compilerUnsafeIO :: IO a -> Compiler a
242−compilerUnsafeIO io = Compiler $ \_ -> do
243− x <- io
244− return $ CompilerDone x mempty
245−{-# INLINE compilerUnsafeIO #-}
327+-- | Pass a list of messages with a heading to the debug logger
328+compilerDebugEntries :: String -> [String] -> Compiler ()
329+compilerDebugEntries msg = compilerDebugLog . (msg:) . map indent
330+ where
331+ indent = unlines . map (" "++) . lines
246332
247333
248334--------------------------------------------------------------------------------
249335compilerTellDependencies :: [Dependency] -> Compiler ()
250336compilerTellDependencies ds = do
251− logger <- compilerLogger <$> compilerAsk
252− forM_ ds $ \d -> compilerUnsafeIO $ Logger.debug logger $
253− "Hakyll.Core.Compiler.Internal: Adding dependency: " ++ show d
337+ compilerDebugLog $ map (\d ->
338+ "Hakyll.Core.Compiler.Internal: Adding dependency: " ++ show d) ds
254339 compilerTell mempty {compilerDependencies = ds}
255340{-# INLINE compilerTellDependencies #-}
256341
lib/Hakyll/Core/Compiler/Require.hs+2
@@ -91,6 +91,7 @@ loadBody id' = loadSnapshotBody id' final
9191
9292
9393--------------------------------------------------------------------------------
94+-- | A shortcut for only requiring the body for a specific snapshot of an item
9495loadSnapshotBody :: (Binary a, Typeable a)
9596 => Identifier -> Snapshot -> Compiler a
9697loadSnapshotBody id' snapshot = fmap itemBody $ loadSnapshot id' snapshot
@@ -103,6 +104,7 @@ loadAll pattern = loadAllSnapshots pattern final
103104
104105
105106--------------------------------------------------------------------------------
107+-- | Load a specific snapshot for each of dynamic list of items
106108loadAllSnapshots :: (Binary a, Typeable a)
107109 => Pattern -> Snapshot -> Compiler [Item a]
108110loadAllSnapshots pattern snapshot = do
lib/Hakyll/Core/Identifier.hs+1−1
@@ -62,7 +62,7 @@ instance Show Identifier where
6262
6363--------------------------------------------------------------------------------
6464-- | Parse an identifier from a string
65−fromFilePath :: String -> Identifier
65+fromFilePath :: FilePath -> Identifier
6666fromFilePath = Identifier Nothing .
6767 intercalate "/" . filter (not . null) . split'
6868 where
lib/Hakyll/Core/Logger.hs+9−3
@@ -18,6 +18,7 @@ import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
1818import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)
1919import Control.Monad (forever)
2020import Control.Monad.Trans (MonadIO, liftIO)
21+import Data.List (intercalate)
2122import Prelude hiding (error)
2223
2324
@@ -79,7 +80,7 @@ string l v m
7980
8081--------------------------------------------------------------------------------
8182error :: MonadIO m => Logger -> String -> m ()
82−error l m = string l Error $ " [ERROR] " ++ m
83+error l m = string l Error $ " [ERROR] " ++ indent m
8384
8485
8586--------------------------------------------------------------------------------
@@ -89,9 +90,14 @@ header l = string l Message
8990
9091--------------------------------------------------------------------------------
9192message :: MonadIO m => Logger -> String -> m ()
92−message l m = string l Message $ " " ++ m
93+message l m = string l Message $ " " ++ indent m
9394
9495
9596--------------------------------------------------------------------------------
9697debug :: MonadIO m => Logger -> String -> m ()
97−debug l m = string l Debug $ " [DEBUG] " ++ m
98+debug l m = string l Debug $ " [DEBUG] " ++ indent m
99+
100+
101+--------------------------------------------------------------------------------
102+indent :: String -> String
103+indent = intercalate "\n " . lines
lib/Hakyll/Core/Provider/Metadata.hs+3−2
@@ -27,6 +27,7 @@ import Hakyll.Core.Identifier
2727import Hakyll.Core.Metadata
2828import Hakyll.Core.Provider.Internal
2929import System.IO as IO
30+import System.IO.Error (modifyIOError, ioeSetLocation)
3031
3132
3233--------------------------------------------------------------------------------
@@ -51,7 +52,7 @@ loadMetadata p identifier = do
5152--------------------------------------------------------------------------------
5253loadMetadataHeader :: FilePath -> IO (Metadata, String)
5354loadMetadataHeader fp = do
54− fileContent <- readFile fp
55+ fileContent <- modifyIOError (`ioeSetLocation` "loadMetadataHeader") $ readFile fp
5556 case parsePage fileContent of
5657 Right x -> return x
5758 Left err -> throwIO $ MetadataException fp err
@@ -60,7 +61,7 @@ loadMetadataHeader fp = do
6061--------------------------------------------------------------------------------
6162loadMetadataFile :: FilePath -> IO Metadata
6263loadMetadataFile fp = do
63− fileContent <- B.readFile fp
64+ fileContent <- modifyIOError (`ioeSetLocation` "loadMetadataFile") $ B.readFile fp
6465 let errOrMeta = Yaml.decodeEither' fileContent
6566 either (fail . show) return errOrMeta
6667
lib/Hakyll/Core/Runtime.hs+3−3
@@ -199,9 +199,9 @@ chase trail id'
199199 result <- liftIO $ runCompiler compiler read'
200200 case result of
201201 -- Rethrow error
202− CompilerError [] -> throwError
203− "Compiler failed but no info given, try running with -v?"
204− CompilerError es -> throwError $ intercalate "; " es
202+ CompilerError e -> throwError $ case compilerErrorMessages e of
203+ [] -> "Compiler failed but no info given, try running with -v?"
204+ es -> intercalate "; " es
205205
206206 -- Signal that a snapshot was saved ->
207207 CompilerSnapshot snapshot c -> do
lib/Hakyll/Core/Store.hs+26−23
@@ -16,7 +16,6 @@ module Hakyll.Core.Store
1616
1717
1818--------------------------------------------------------------------------------
19−import Control.Exception (IOException, handle)
2019import qualified Crypto.Hash.MD5 as MD5
2120import Data.Binary (Binary, decode, encodeFile)
2221import qualified Data.ByteString as B
@@ -27,11 +26,13 @@ import Data.Maybe (isJust)
2726import qualified Data.Text as T
2827import qualified Data.Text.Encoding as T
2928import Data.Typeable (TypeRep, Typeable, cast, typeOf)
29+import Numeric (showHex)
3030import System.Directory (createDirectoryIfMissing)
3131import System.Directory (doesFileExist, removeFile)
3232import System.FilePath ((</>))
3333import System.IO (IOMode (..), hClose, openFile)
34−import Text.Printf (printf)
34+import System.IO.Error (catchIOError, ioeSetFileName,
35+ ioeSetLocation, modifyIOError)
3536
3637
3738--------------------------------------------------------------------------------
@@ -84,6 +85,14 @@ new inMemory directory = do
8485 where
8586 csize = Just 500
8687
88+--------------------------------------------------------------------------------
89+withStore :: Store -> String -> (String -> FilePath -> IO a) -> [String] -> IO a
90+withStore store loc run identifier = modifyIOError handle $ run key path
91+ where
92+ key = hash identifier
93+ path = storeDirectory store </> key
94+ handle e = e `ioeSetFileName` (path ++ " for " ++ intercalate "/" identifier)
95+ `ioeSetLocation` ("Store." ++ loc)
8796
8897--------------------------------------------------------------------------------
8998-- | Auxiliary: add an item to the in-memory cache
@@ -124,17 +133,16 @@ cacheDelete (Store _ (Just lru)) key = do
124133--------------------------------------------------------------------------------
125134-- | Store an item
126135set :: (Binary a, Typeable a) => Store -> [String] -> a -> IO ()
127−set store identifier value = do
128− encodeFile (storeDirectory store </> key) value
136+set store identifier value = withStore store "set" (\key path -> do
137+ encodeFile path value
129138 cacheInsert store key value
130− where
131− key = hash identifier
139+ ) identifier
132140
133141
134142--------------------------------------------------------------------------------
135143-- | Load an item
136144get :: (Binary a, Typeable a) => Store -> [String] -> IO (Result a)
137−get store identifier = do
145+get store = withStore store "get" $ \key path -> do
138146 -- First check the in-memory map
139147 ref <- cacheLookup store key
140148 case ref of
@@ -146,17 +154,14 @@ get store identifier = do
146154 then return NotFound
147155 -- Found in the filesystem
148156 else do
149− v <- decodeClose
157+ v <- decodeClose path
150158 cacheInsert store key v
151159 return $ Found v
152160 -- Found in the in-memory map (or wrong type), just return
153161 s -> return s
154162 where
155− key = hash identifier
156− path = storeDirectory store </> key
157−
158163 -- 'decodeFile' from Data.Binary which closes the file ASAP
159− decodeClose = do
164+ decodeClose path = do
160165 h <- openFile path ReadMode
161166 lbs <- BL.hGetContents h
162167 BL.length lbs `seq` hClose h
@@ -166,32 +171,30 @@ get store identifier = do
166171--------------------------------------------------------------------------------
167172-- | Strict function
168173isMember :: Store -> [String] -> IO Bool
169−isMember store identifier = do
174+isMember store = withStore store "isMember" $ \key path -> do
170175 inCache <- cacheIsMember store key
171176 if inCache then return True else doesFileExist path
172− where
173− key = hash identifier
174− path = storeDirectory store </> key
175177
176178
177179--------------------------------------------------------------------------------
178180-- | Delete an item
179181delete :: Store -> [String] -> IO ()
180−delete store identifier = do
182+delete store = withStore store "delete" $ \key path -> do
181183 cacheDelete store key
182− deleteFile $ storeDirectory store </> key
183− where
184− key = hash identifier
184+ deleteFile path
185185
186186
187187--------------------------------------------------------------------------------
188188-- | Delete a file unless it doesn't exist...
189189deleteFile :: FilePath -> IO ()
190−deleteFile = handle (\(_ :: IOException) -> return ()) . removeFile
190+deleteFile = (`catchIOError` \_ -> return ()) . removeFile
191191
192192
193193--------------------------------------------------------------------------------
194194-- | Mostly meant for internal usage
195195hash :: [String] -> String
196−hash = concatMap (printf "%02x") . B.unpack .
197− MD5.hash . T.encodeUtf8 . T.pack . intercalate "/"
196+hash = toHex . B.unpack . MD5.hash . T.encodeUtf8 . T.pack . intercalate "/"
197+ where
198+ toHex [] = ""
199+ toHex (x : xs) | x < 16 = '0' : showHex x (toHex xs)
200+ | otherwise = showHex x (toHex xs)
lib/Hakyll/Web/Feed.hs+51−32
@@ -1,4 +1,5 @@
1−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE TemplateHaskell #-}
23
34--------------------------------------------------------------------------------
45-- | A Module that allows easy rendering of RSS feeds.
@@ -22,6 +23,8 @@ module Hakyll.Web.Feed
2223 ( FeedConfiguration (..)
2324 , renderRss
2425 , renderAtom
26+ , renderRssWithTemplates
27+ , renderAtomWithTemplates
2528 ) where
2629
2730
@@ -35,27 +38,26 @@ import Hakyll.Web.Template.List
3538
3639
3740--------------------------------------------------------------------------------
38−import Data.FileEmbed (makeRelativeToProject, embedFile)
39−import qualified Data.Text as T
40−import qualified Data.Text.Encoding as T
41+import Data.FileEmbed (makeRelativeToProject)
4142
4243
4344--------------------------------------------------------------------------------
44−rssTemplate :: String
45−rssTemplate = T.unpack $
46− T.decodeUtf8 $(makeRelativeToProject "data/templates/rss.xml" >>= embedFile)
45+rssTemplate :: Template
46+rssTemplate =
47+ $(makeRelativeToProject "data/templates/rss.xml" >>= embedTemplate)
4748
48−rssItemTemplate :: String
49−rssItemTemplate = T.unpack $
50− T.decodeUtf8 $(makeRelativeToProject "data/templates/rss-item.xml" >>= embedFile)
49+rssItemTemplate :: Template
50+rssItemTemplate =
51+ $(makeRelativeToProject "data/templates/rss-item.xml" >>= embedTemplate)
5152
52−atomTemplate :: String
53−atomTemplate = T.unpack $
54− T.decodeUtf8 $(makeRelativeToProject "data/templates/atom.xml" >>= embedFile)
53+atomTemplate :: Template
54+atomTemplate =
55+ $(makeRelativeToProject "data/templates/atom.xml" >>= embedTemplate)
56+
57+atomItemTemplate :: Template
58+atomItemTemplate =
59+ $(makeRelativeToProject "data/templates/atom-item.xml" >>= embedTemplate)
5560
56−atomItemTemplate :: String
57−atomItemTemplate = T.unpack $
58− T.decodeUtf8 $(makeRelativeToProject "data/templates/atom-item.xml" >>= embedFile)
5961
6062--------------------------------------------------------------------------------
6163-- | This is a data structure to keep the configuration of a feed.
@@ -75,16 +77,13 @@ data FeedConfiguration = FeedConfiguration
7577
7678--------------------------------------------------------------------------------
7779-- | Abstract function to render any feed.
78−renderFeed :: String -- ^ Default feed template
79− -> String -- ^ Default item template
80+renderFeed :: Template -- ^ Default feed template
81+ -> Template -- ^ Default item template
8082 -> FeedConfiguration -- ^ Feed configuration
8183 -> Context String -- ^ Context for the items
8284 -> [Item String] -- ^ Input items
8385 -> Compiler (Item String) -- ^ Resulting item
84−renderFeed defFeed defItem config itemContext items = do
85− feedTpl <- readTemplateFile defFeed
86− itemTpl <- readTemplateFile defItem
87−
86+renderFeed feedTpl itemTpl config itemContext items = do
8887 protectedItems <- mapM (applyFilter protectCDATA) items
8988 body <- makeItem =<< applyTemplateList itemTpl itemContext' protectedItems
9089 applyTemplate feedTpl feedContext body
@@ -118,11 +117,35 @@ renderFeed defFeed defItem config itemContext items = do
118117 updatedField = field "updated" $ \_ -> case items of
119118 [] -> return "Unknown"
120119 (x : _) -> unContext itemContext' "updated" [] x >>= \cf -> case cf of
121− ListField _ _ -> fail "Hakyll.Web.Feed.renderFeed: Internal error"
122120 StringField s -> return s
121+ _ -> fail "Hakyll.Web.Feed.renderFeed: Internal error"
122+
123+--------------------------------------------------------------------------------
124+-- | Render an RSS feed using given templates with a number of items.
125+renderRssWithTemplates ::
126+ Template -- ^ Feed template
127+ -> Template -- ^ Item template
128+ -> FeedConfiguration -- ^ Feed configuration
129+ -> Context String -- ^ Item context
130+ -> [Item String] -- ^ Feed items
131+ -> Compiler (Item String) -- ^ Resulting feed
132+renderRssWithTemplates feedTemplate itemTemplate config context = renderFeed
133+ feedTemplate itemTemplate config
134+ (makeItemContext "%a, %d %b %Y %H:%M:%S UT" context)
123135
124− readTemplateFile :: String -> Compiler Template
125− readTemplateFile value = pure $ template $ readTemplateElems value
136+
137+--------------------------------------------------------------------------------
138+-- | Render an Atom feed using given templates with a number of items.
139+renderAtomWithTemplates ::
140+ Template -- ^ Feed template
141+ -> Template -- ^ Item template
142+ -> FeedConfiguration -- ^ Feed configuration
143+ -> Context String -- ^ Item context
144+ -> [Item String] -- ^ Feed items
145+ -> Compiler (Item String) -- ^ Resulting feed
146+renderAtomWithTemplates feedTemplate itemTemplate config context = renderFeed
147+ feedTemplate itemTemplate config
148+ (makeItemContext "%Y-%m-%dT%H:%M:%SZ" context)
126149
127150
128151--------------------------------------------------------------------------------
@@ -131,9 +154,7 @@ renderRss :: FeedConfiguration -- ^ Feed configuration
131154 -> Context String -- ^ Item context
132155 -> [Item String] -- ^ Feed items
133156 -> Compiler (Item String) -- ^ Resulting feed
134−renderRss config context = renderFeed
135− rssTemplate rssItemTemplate config
136− (makeItemContext "%a, %d %b %Y %H:%M:%S UT" context)
157+renderRss = renderRssWithTemplates rssTemplate rssItemTemplate
137158
138159
139160--------------------------------------------------------------------------------
@@ -142,13 +163,11 @@ renderAtom :: FeedConfiguration -- ^ Feed configuration
142163 -> Context String -- ^ Item context
143164 -> [Item String] -- ^ Feed items
144165 -> Compiler (Item String) -- ^ Resulting feed
145−renderAtom config context = renderFeed
146− atomTemplate atomItemTemplate config
147− (makeItemContext "%Y-%m-%dT%H:%M:%SZ" context)
166+renderAtom = renderAtomWithTemplates atomTemplate atomItemTemplate
148167
149168
150169--------------------------------------------------------------------------------
151170-- | Copies @$updated$@ from @$published$@ if it is not already set.
152171makeItemContext :: String -> Context a -> Context a
153172makeItemContext fmt context = mconcat
154− [dateField "published" fmt, context, dateField "updated" fmt]
173+ [context, dateField "published" fmt, dateField "updated" fmt]
lib/Hakyll/Web/Html.hs+1−1
@@ -59,7 +59,7 @@ demoteHeaders = withTags $ \tag -> case tag of
5959
6060--------------------------------------------------------------------------------
6161isUrlAttribute :: String -> Bool
62−isUrlAttribute = (`elem` ["src", "href", "data", "poster"])
62+isUrlAttribute = (`elem` ["src", "href", "data", "poster", "srcset"])
6363
6464
6565--------------------------------------------------------------------------------
lib/Hakyll/Web/Tags.hs+2−1
@@ -43,6 +43,7 @@
4343module Hakyll.Web.Tags
4444 ( Tags (..)
4545 , getTags
46+ , getCategory
4647 , buildTagsWith
4748 , buildTags
4849 , buildCategories
@@ -112,7 +113,7 @@ getTags identifier = do
112113
113114
114115--------------------------------------------------------------------------------
115−-- | Obtain categories from a page.
116+-- | Obtain category from a page.
116117getCategory :: MonadMetadata m => Identifier -> m [String]
117118getCategory = return . return . takeBaseName . takeDirectory . toFilePath
118119
lib/Hakyll/Web/Template.hs+24−2
@@ -138,19 +138,41 @@
138138-- > 3...2...1
139139-- > </p>
140140--
141+{-# LANGUAGE TemplateHaskell #-}
141142module Hakyll.Web.Template
142143 ( Template
143− , template
144− , readTemplateElems
145144 , templateBodyCompiler
146145 , templateCompiler
147146 , applyTemplate
148147 , loadAndApplyTemplate
149148 , applyAsTemplate
150149 , readTemplate
150+ , compileTemplateItem
151151 , unsafeReadTemplateFile
152+ , embedTemplate
152153 ) where
153154
154155
155156--------------------------------------------------------------------------------
156157import Hakyll.Web.Template.Internal
158+
159+
160+--------------------------------------------------------------------------------
161+import Data.FileEmbed (embedFile)
162+import qualified Data.Text as T
163+import qualified Data.Text.Encoding as T
164+import Language.Haskell.TH (Exp, Q)
165+
166+
167+--------------------------------------------------------------------------------
168+-- | Embed template allows you embed a template within the Haskell binary.
169+-- Example:
170+--
171+-- > myTemplate :: Template
172+-- > myTemplate = $(embedTemplate "test.html")
173+embedTemplate :: FilePath -> Q Exp
174+embedTemplate filePath = [|
175+ let source = T.unpack $ T.decodeUtf8 $(embedFile filePath) in
176+ case parseTemplateElemsFile filePath source of
177+ Left err -> error err
178+ Right tpl -> template filePath tpl |]
lib/Hakyll/Web/Template/Context.hs+122−32
@@ -1,6 +1,27 @@
1+-- | This module provides 'Context's which are used to expand expressions in
2+-- templates and allow for arbitrary customisation.
3+--
4+-- 'Template's define a small expression DSL which consists of strings,
5+-- identifiers and function application. There is no type system, every value is
6+-- a string and on the top level they get substituted verbatim into the page.
7+--
8+-- For example, you can build a context that contains
9+--
10+-- > … <> functionField "concat" (const . concat) <> …
11+--
12+-- which will allow you to use the @concat@ identifier as a function that takes
13+-- arbitrarily many stings and concatenates them to a new string:
14+--
15+-- > $partial(concat("templates/categories/", category))$
16+--
17+-- This will evaluate the @category@ field in the context, then prepend he path,
18+-- and include the referenced file as a template.
19+
20+
121--------------------------------------------------------------------------------
222{-# LANGUAGE CPP #-}
323{-# LANGUAGE ExistentialQuantification #-}
24+{-# LANGUAGE RankNTypes #-}
425module Hakyll.Web.Template.Context
526 ( ContextField (..)
627 , Context (..)
@@ -28,13 +49,14 @@ module Hakyll.Web.Template.Context
2849 , teaserField
2950 , teaserFieldWithSeparator
3051 , missingField
52+ , bindItem
3153 ) where
3254
3355
3456--------------------------------------------------------------------------------
3557import Control.Applicative (Alternative (..))
3658import Control.Monad (msum)
37−import Data.List (intercalate)
59+import Data.List (intercalate, tails)
3860#if MIN_VERSION_base(4,9,0)
3961import Data.Semigroup (Semigroup (..))
4062#endif
@@ -50,13 +72,16 @@ import Hakyll.Core.Metadata
5072import Hakyll.Core.Provider
5173import Hakyll.Core.Util.String (needlePrefix, splitAll)
5274import Hakyll.Web.Html
53−import System.FilePath (splitDirectories, takeBaseName)
75+import Prelude hiding (id)
76+import System.FilePath (dropExtension, splitDirectories,
77+ takeBaseName)
5478
5579
5680--------------------------------------------------------------------------------
5781-- | Mostly for internal usage
5882data ContextField
59− = StringField String
83+ = EmptyField
84+ | StringField String
6085 | forall a. ListField (Context a) [Item a]
6186
6287
@@ -81,6 +106,8 @@ newtype Context a = Context
81106
82107
83108--------------------------------------------------------------------------------
109+-- | Tries to find a key in the left context,
110+-- or when that fails in the right context.
84111#if MIN_VERSION_base(4,9,0)
85112instance Semigroup (Context a) where
86113 (<>) (Context f) (Context g) = Context $ \k a i -> f k a i <|> g k a i
@@ -97,64 +124,105 @@ instance Monoid (Context a) where
97124
98125--------------------------------------------------------------------------------
99126field' :: String -> (Item a -> Compiler ContextField) -> Context a
100−field' key value = Context $ \k _ i -> if k == key then value i else empty
127+field' key value = Context $ \k _ i ->
128+ if k == key
129+ then value i
130+ else noResult $ "Tried field " ++ key
101131
102132
103133--------------------------------------------------------------------------------
104−-- | Constructs a new field in the 'Context.'
134+-- | Constructs a new field for a 'Context'.
135+-- If the key matches, the compiler is run and its result is substituted in the
136+-- template.
137+--
138+-- If the compiler fails, the field will be considered non-existent
139+-- in an @$if()$@ macro or ultimately break the template application
140+-- (unless the key is found in another context when using '<>').
141+-- Use 'empty' or 'noResult' for intentional failures of fields used in
142+-- @$if()$@, to distinguish them from exceptions thrown with 'fail'.
105143field
106144 :: String -- ^ Key
107145 -> (Item a -> Compiler String) -- ^ Function that constructs a value based
108− -- on the item
146+ -- on the item (e.g. accessing metadata)
109147 -> Context a
110148field key value = field' key (fmap StringField . value)
111149
112150
113151--------------------------------------------------------------------------------
114152-- | Creates a 'field' to use with the @$if()$@ template macro.
153+-- Attempting to substitute the field into the template will cause an error.
115154boolField
116155 :: String
117156 -> (Item a -> Bool)
118157 -> Context a
119−boolField name f = field name (\i -> if f i
120− then pure (error $ unwords ["no string value for bool field:",name])
121− else empty)
158+boolField name f = field' name (\i -> if f i
159+ then return EmptyField
160+ else noResult $ "Field " ++ name ++ " is false")
122161
123162
124163--------------------------------------------------------------------------------
125−-- | Creates a 'field' that does not depend on the 'Item'
126−constField :: String -> String -> Context a
164+-- | Creates a 'field' that does not depend on the 'Item' but always yields
165+-- the same string
166+constField :: String -- ^ Key
167+ -> String -- ^ Value
168+ -> Context a
127169constField key = field key . const . return
128170
129171
130172--------------------------------------------------------------------------------
173+-- | Creates a list field to be consumed by a @$for(…)$@ expression.
174+-- The compiler returns multiple items which are rendered in the loop body
175+-- with the supplied context.
131176listField :: String -> Context a -> Compiler [Item a] -> Context b
132177listField key c xs = listFieldWith key c (const xs)
133178
134179
135180--------------------------------------------------------------------------------
181+-- | Produces a new 'Context' which has list field 'key'. All fields from
182+-- 'c' are also accessible from the produced context.
183+-- Be careful when doing @listFieldWith k ca f <> cb@ as any fields in @ca@
184+-- will override fields in @cb@ with the same name.
185+-- Creates a list field like 'listField', but supplies the current page
186+-- to the compiler.
136187listFieldWith
137188 :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
138189listFieldWith key c f = field' key $ fmap (ListField c) . f
139190
140191
141192--------------------------------------------------------------------------------
142−functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
193+-- | Creates a variadic function field.
194+--
195+-- The function will be called with the dynamically evaluated string arguments
196+-- from the template as well as the page that is currently rendered.
197+functionField :: String -- ^ Key
198+ -> ([String] -> Item a -> Compiler String) -- ^ Function
199+ -> Context a
143200functionField name value = Context $ \k args i ->
144201 if k == name
145202 then StringField <$> value args i
146− else empty
203+ else noResult $ "Tried function field " ++ name
147204
148205
149206--------------------------------------------------------------------------------
207+-- | Transform the respective string results of all fields in a context.
208+-- For example,
209+--
210+-- > mapContext (++"c") (constField "x" "a" <> constField "y" "b")
211+--
212+-- is equivalent to
213+--
214+-- > constField "x" "ac" <> constField "y" "bc"
215+--
150216mapContext :: (String -> String) -> Context a -> Context a
151217mapContext f (Context c) = Context $ \k a i -> do
152218 fld <- c k a i
153219 case fld of
220+ EmptyField -> wrongType "boolField"
154221 StringField str -> return $ StringField (f str)
155− ListField _ _ -> fail $
156− "Hakyll.Web.Template.Context.mapContext: " ++
157− "can't map over a ListField!"
222+ _ -> wrongType "ListField"
223+ where
224+ wrongType typ = fail $ "Hakyll.Web.Template.Context.mapContext: " ++
225+ "can't map over a " ++ typ ++ "!"
158226
159227--------------------------------------------------------------------------------
160228-- | A context that allows snippet inclusion. In processed file, use as:
@@ -163,15 +231,15 @@ mapContext f (Context c) = Context $ \k a i -> do
163231-- > $snippet("path/to/snippet/")$
164232-- > ...
165233--
166−-- The contents of the included file will not be interpolated.
234+-- The contents of the included file will not be interpolated like @partial@
235+-- does it.
167236--
168237snippetField :: Context String
169238snippetField = functionField "snippet" f
170239 where
171240 f [contentsPath] _ = loadBody (fromFilePath contentsPath)
172− f _ i = error $
173− "Too many arguments to function 'snippet()' in item " ++
174− show (itemIdentifier i)
241+ f [] _ = fail "No argument to function 'snippet()'"
242+ f _ _ = fail "Too many arguments to function 'snippet()'"
175243
176244--------------------------------------------------------------------------------
177245-- | A context that contains (in that order)
@@ -191,8 +259,7 @@ defaultContext =
191259 metadataField `mappend`
192260 urlField "url" `mappend`
193261 pathField "path" `mappend`
194− titleField "title" `mappend`
195− missingField
262+ titleField "title"
196263
197264
198265--------------------------------------------------------------------------------
@@ -210,15 +277,20 @@ bodyField key = field key $ return . itemBody
210277-- | Map any field to its metadata value, if present
211278metadataField :: Context a
212279metadataField = Context $ \k _ i -> do
213− value <- getMetadataField (itemIdentifier i) k
214− maybe empty (return . StringField) value
280+ let id = itemIdentifier i
281+ empty' = noResult $ "No '" ++ k ++ "' field in metadata " ++
282+ "of item " ++ show id
283+ value <- getMetadataField id k
284+ maybe empty' (return . StringField) value
215285
216286
217287--------------------------------------------------------------------------------
218288-- | Absolute url to the resulting item
219289urlField :: String -> Context a
220−urlField key = field key $
221− fmap (maybe empty toUrl) . getRoute . itemIdentifier
290+urlField key = field key $ \i -> do
291+ let id = itemIdentifier i
292+ empty' = fail $ "No route url found for item " ++ show id
293+ fmap (maybe empty' toUrl) $ getRoute id
222294
223295
224296--------------------------------------------------------------------------------
@@ -269,6 +341,12 @@ titleField = mapContext takeBaseName . pathField
269341-- that begins with @yyyy-mm-dd@ . For example:
270342-- @folder//yyyy-mm-dd-title//dist//main.extension@ .
271343-- In case of multiple matches, the rightmost one is used.
344+--
345+-- As another alternative, if none of the above matches, and the file has a
346+-- path which contains nested directories specifying a date, then that date
347+-- will be used. In other words, if the path is of the form
348+-- @**//yyyy//mm//dd//**//main.extension@ .
349+-- As above, in case of multiple matches, the rightmost one is used.
272350
273351dateField :: String -- ^ Key in which the rendered date should be placed
274352 -> String -- ^ Format to use on the date
@@ -279,7 +357,7 @@ dateField = dateFieldWith defaultTimeLocale
279357--------------------------------------------------------------------------------
280358-- | This is an extended version of 'dateField' that allows you to
281359-- specify a time locale that is used for outputting the date. For more
282−-- details, see 'dateField'.
360+-- details, see 'dateField' and 'formatTime'.
283361dateFieldWith :: TimeLocale -- ^ Output time locale
284362 -> String -- ^ Destination key
285363 -> String -- ^ Format to use on the date
@@ -300,12 +378,13 @@ getItemUTC :: MonadMetadata m
300378getItemUTC locale id' = do
301379 metadata <- getMetadata id'
302380 let tryField k fmt = lookupString k metadata >>= parseTime' fmt
303− paths = splitDirectories $ toFilePath id'
381+ paths = splitDirectories $ (dropExtension . toFilePath) id'
304382
305383 maybe empty' return $ msum $
306384 [tryField "published" fmt | fmt <- formats] ++
307385 [tryField "date" fmt | fmt <- formats] ++
308− [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths]
386+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ take 3 $ splitAll "-" fnCand | fnCand <- reverse paths] ++
387+ [parseTime' "%Y-%m-%d" $ intercalate "-" $ fnCand | fnCand <- map (take 3) $ reverse . tails $ paths]
309388 where
310389 empty' = fail $ "Hakyll.Web.Template.Context.getItemUTC: " ++
311390 "could not parse time for " ++ show id'
@@ -333,6 +412,7 @@ getItemModificationTime identifier = do
333412
334413
335414--------------------------------------------------------------------------------
415+-- | Creates a field with the last modification date of the underlying item.
336416modificationTimeField :: String -- ^ Key
337417 -> String -- ^ Format
338418 -> Context a -- ^ Resulting context
@@ -340,6 +420,8 @@ modificationTimeField = modificationTimeFieldWith defaultTimeLocale
340420
341421
342422--------------------------------------------------------------------------------
423+-- | Creates a field with the last modification date of the underlying item
424+-- in a custom localisation format (see 'formatTime').
343425modificationTimeFieldWith :: TimeLocale -- ^ Time output locale
344426 -> String -- ^ Key
345427 -> String -- ^ Format
@@ -378,10 +460,11 @@ teaserFieldWithSeparator separator key snapshot = field key $ \item -> do
378460
379461
380462--------------------------------------------------------------------------------
463+-- | Constantly reports any field as missing. Mostly for internal usage,
464+-- it is the last choice in every context used in a template application.
381465missingField :: Context a
382−missingField = Context $ \k _ i -> fail $
383− "Missing field $" ++ k ++ "$ in context for item " ++
384− show (itemIdentifier i)
466+missingField = Context $ \k _ _ -> noResult $
467+ "Missing field '" ++ k ++ "' in context"
385468
386469parseTimeM :: Bool -> TimeLocale -> String -> String -> Maybe UTCTime
387470#if MIN_VERSION_time(1,5,0)
@@ -389,3 +472,10 @@ parseTimeM = TF.parseTimeM
389472#else
390473parseTimeM _ = TF.parseTime
391474#endif
475+
476+--------------------------------------------------------------------------------
477+
478+-- | Binds an 'Item' to a given 'Context', allowing it to be combined with any
479+-- other 'Context' of any type.
480+bindItem :: Context a -> Item a -> forall b. Context b
481+bindItem (Context ctx) ia = Context $ \k args _ -> ctx k args ia
lib/Hakyll/Web/Template/Internal.hs+103−44
@@ -1,15 +1,18 @@
1+{-# LANGUAGE DeriveAnyClass #-}
2+{-# LANGUAGE DeriveGeneric #-}
13{-# LANGUAGE GeneralizedNewtypeDeriving #-}
24{-# LANGUAGE ScopedTypeVariables #-}
5+
36module Hakyll.Web.Template.Internal
47 ( Template (..)
58 , template
69 , templateBodyCompiler
710 , templateCompiler
811 , applyTemplate
9− , applyTemplate'
1012 , loadAndApplyTemplate
1113 , applyAsTemplate
1214 , readTemplate
15+ , compileTemplateItem
1316 , unsafeReadTemplateFile
1417
1518 , module Hakyll.Web.Template.Internal.Element
@@ -18,16 +21,19 @@ module Hakyll.Web.Template.Internal
1821
1922
2023--------------------------------------------------------------------------------
21−import Control.Monad.Except (MonadError (..))
24+import Control.Monad (forM)
25+import Control.Monad.Except (MonadError (..), catchError)
2226import Data.Binary (Binary)
2327import Data.List (intercalate)
28+import qualified Data.List.NonEmpty as NonEmpty
2429import Data.Typeable (Typeable)
2530import GHC.Exts (IsString (..))
26−import Prelude hiding (id)
31+import GHC.Generics (Generic)
2732
2833
2934--------------------------------------------------------------------------------
3035import Hakyll.Core.Compiler
36+import Hakyll.Core.Compiler.Internal
3137import Hakyll.Core.Identifier
3238import Hakyll.Core.Item
3339import Hakyll.Core.Writable
@@ -38,9 +44,10 @@ import Hakyll.Web.Template.Internal.Trim
3844
3945--------------------------------------------------------------------------------
4046-- | Datatype used for template substitutions.
41−newtype Template = Template
42− { unTemplate :: [TemplateElement]
43− } deriving (Show, Eq, Binary, Typeable)
47+data Template = Template
48+ { tplElements :: [TemplateElement]
49+ , tplOrigin :: FilePath -- Only for error messages.
50+ } deriving (Show, Eq, Generic, Binary, Typeable)
4451
4552
4653--------------------------------------------------------------------------------
@@ -56,39 +63,68 @@ instance IsString Template where
5663
5764--------------------------------------------------------------------------------
5865-- | Wrap the constructor to ensure trim is called.
59−template :: [TemplateElement] -> Template
60−template = Template . trim
66+template :: FilePath -> [TemplateElement] -> Template
67+template p = flip Template p . trim
6168
6269
6370--------------------------------------------------------------------------------
71+-- | Parse a string into a template.
72+-- You should prefer 'compileTemplateItem' over this.
6473readTemplate :: String -> Template
65−readTemplate = Template . trim . readTemplateElems
74+readTemplate = either error (template origin) . parseTemplateElemsFile origin
75+ where
76+ origin = "{literal}"
77+{-# DEPRECATED readTemplate "Use templateCompiler instead" #-}
78+
79+--------------------------------------------------------------------------------
80+-- | Parse an item body into a template.
81+-- Provides useful error messages in the 'Compiler' monad.
82+compileTemplateItem :: Item String -> Compiler Template
83+compileTemplateItem item = let file = itemIdentifier item
84+ in compileTemplateFile file (itemBody item)
85+
86+--------------------------------------------------------------------------------
87+compileTemplateFile :: Identifier -> String -> Compiler Template
88+compileTemplateFile file = either fail (return . template origin)
89+ . parseTemplateElemsFile origin
90+ where
91+ origin = show file
6692
6793--------------------------------------------------------------------------------
6894-- | Read a template, without metadata header
6995templateBodyCompiler :: Compiler (Item Template)
7096templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
7197 item <- getResourceBody
72− file <- getResourceFilePath
73− return $ fmap (template . readTemplateElemsFile file) item
98+ file <- getUnderlying
99+ withItemBody (compileTemplateFile file) item
74100
75101--------------------------------------------------------------------------------
76102-- | Read complete file contents as a template
77103templateCompiler :: Compiler (Item Template)
78104templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
79105 item <- getResourceString
80− file <- getResourceFilePath
81− return $ fmap (template . readTemplateElemsFile file) item
106+ file <- getUnderlying
107+ withItemBody (compileTemplateFile file) item
82108
83109
84110--------------------------------------------------------------------------------
111+-- | Interpolate template expressions from context values in a page
85112applyTemplate :: Template -- ^ Template
86113 -> Context a -- ^ Context
87114 -> Item a -- ^ Page
88115 -> Compiler (Item String) -- ^ Resulting item
89116applyTemplate tpl context item = do
90− body <- applyTemplate' (unTemplate tpl) context item
117+ body <- applyTemplate' (tplElements tpl) context item `catchError` handler
91118 return $ itemSetBody body item
119+ where
120+ tplName = tplOrigin tpl
121+ itemName = show $ itemIdentifier item
122+ handler es = fail $ "Hakyll.Web.Template.applyTemplate: Failed to " ++
123+ (if tplName == itemName
124+ then "interpolate template in item " ++ itemName
125+ else "apply template " ++ tplName ++ " to item " ++ itemName) ++
126+ ":\n" ++ intercalate ",\n" es
127+
92128
93129
94130--------------------------------------------------------------------------------
@@ -105,9 +141,6 @@ applyTemplate' tes context x = go tes
105141
106142 go = fmap concat . mapM applyElem
107143
108− trimError = error $ "Hakyll.Web.Template.applyTemplate: template not " ++
109− "fully trimmed."
110−
111144 ---------------------------------------------------------------------------
112145
113146 applyElem :: TemplateElement -> Compiler String
@@ -118,29 +151,43 @@ applyTemplate' tes context x = go tes
118151
119152 applyElem (Chunk c) = return c
120153
121− applyElem (Expr e) = applyExpr e >>= getString e
154+ applyElem (Expr e) = withErrorMessage evalMsg (applyStringExpr typeMsg e)
155+ where
156+ evalMsg = "In expr '$" ++ show e ++ "$'"
157+ typeMsg = "expr '$" ++ show e ++ "$'"
122158
123159 applyElem Escaped = return "$"
124160
125− applyElem (If e t mf) = (applyExpr e >> go t) `catchError` handler
161+ applyElem (If e t mf) = compilerTry (applyExpr e) >>= handle
126162 where
127− handler _ = case mf of
128− Nothing -> return ""
129− Just f -> go f
130−
131− applyElem (For e b s) = applyExpr e >>= \cf -> case cf of
132− StringField _ -> fail $
133− "Hakyll.Web.Template.applyTemplateWith: expected ListField but " ++
134− "got StringField for expr " ++ show e
135− ListField c xs -> do
163+ f = maybe (return "") go mf
164+ handle (Right _) = go t
165+ handle (Left (CompilationNoResult _)) = f
166+ handle (Left (CompilationFailure es)) = debug (NonEmpty.toList es) >> f
167+ debug = compilerDebugEntries ("Hakyll.Web.Template.applyTemplate: " ++
168+ "[ERROR] in 'if' condition on expr '" ++ show e ++ "':")
169+
170+ applyElem (For e b s) = withErrorMessage headMsg (applyExpr e) >>= \cf -> case cf of
171+ EmptyField -> expected "list" "boolean" typeMsg
172+ StringField _ -> expected "list" "string" typeMsg
173+ ListField c xs -> withErrorMessage bodyMsg $ do
136174 sep <- maybe (return "") go s
137− bs <- mapM (applyTemplate' b c) xs
175+ bs <- forM xs $ applyTemplate' b $ c <> bindItem context x
138176 return $ intercalate sep bs
139−
140− applyElem (Partial e) = do
141− p <- applyExpr e >>= getString e
142− Template tpl' <- loadBody (fromFilePath p)
143− applyTemplate' tpl' context x
177+ where
178+ headMsg = "In expr '$for(" ++ show e ++ ")$'"
179+ typeMsg = "loop expr '" ++ show e ++ "'"
180+ bodyMsg = "In loop context of '$for(" ++ show e ++ ")$'"
181+
182+ applyElem (Partial e) = withErrorMessage headMsg $
183+ applyStringExpr typeMsg e >>= \p ->
184+ withErrorMessage inclMsg $ do
185+ tpl' <- loadBody (fromFilePath p)
186+ itemBody <$> applyTemplate tpl' context x
187+ where
188+ headMsg = "In expr '$partial(" ++ show e ++ ")$'"
189+ typeMsg = "partial expr '" ++ show e ++ "'"
190+ inclMsg = "In inclusion of '$partial(" ++ show e ++ ")$'"
144191
145192 ---------------------------------------------------------------------------
146193
@@ -149,17 +196,29 @@ applyTemplate' tes context x = go tes
149196 applyExpr (Ident (TemplateKey k)) = context' k [] x
150197
151198 applyExpr (Call (TemplateKey k) args) = do
152− args' <- mapM (\e -> applyExpr e >>= getString e) args
199+ args' <- mapM (\e -> applyStringExpr (typeMsg e) e) args
153200 context' k args' x
201+ where
202+ typeMsg e = "argument '" ++ show e ++ "'"
154203
155204 applyExpr (StringLiteral s) = return (StringField s)
156205
157206 ----------------------------------------------------------------------------
158207
159− getString _ (StringField s) = return s
160− getString e (ListField _ _) = fail $
161− "Hakyll.Web.Template.applyTemplateWith: expected StringField but " ++
162− "got ListField for expr " ++ show e
208+ applyStringExpr :: String -> TemplateExpr -> Compiler String
209+ applyStringExpr msg expr =
210+ applyExpr expr >>= getString
211+ where
212+ getString EmptyField = expected "string" "boolean" msg
213+ getString (StringField s) = return s
214+ getString (ListField _ _) = expected "string" "list" msg
215+
216+ expected typ act expr = fail $ unwords ["Hakyll.Web.Template.applyTemplate:",
217+ "expected", typ, "but got", act, "for", expr]
218+
219+ -- expected to never happen with all templates constructed by 'template'
220+ trimError = fail $
221+ "Hakyll.Web.Template.applyTemplate: template not fully trimmed."
163222
164223
165224--------------------------------------------------------------------------------
@@ -189,14 +248,14 @@ loadAndApplyTemplate identifier context item = do
189248applyAsTemplate :: Context String -- ^ Context
190249 -> Item String -- ^ Item and template
191250 -> Compiler (Item String) -- ^ Resulting item
192−applyAsTemplate context item =
193− let tpl = template $ readTemplateElemsFile file (itemBody item)
194− file = toFilePath $ itemIdentifier item
195− in applyTemplate tpl context item
251+applyAsTemplate context item = do
252+ tpl <- compileTemplateItem item
253+ applyTemplate tpl context item
196254
197255
198256--------------------------------------------------------------------------------
199257unsafeReadTemplateFile :: FilePath -> Compiler Template
200258unsafeReadTemplateFile file = do
201259 tpl <- unsafeCompiler $ readFile file
202− pure $ template $ readTemplateElemsFile file tpl
260+ compileTemplateFile (fromFilePath file) tpl
261+{-# DEPRECATED unsafeReadTemplateFile "Use templateCompiler" #-}
lib/Hakyll/Web/Template/Internal/Element.hs+7−14
@@ -7,14 +7,14 @@ module Hakyll.Web.Template.Internal.Element
77 , TemplateExpr (..)
88 , TemplateElement (..)
99 , templateElems
10− , readTemplateElems
11− , readTemplateElemsFile
10+ , parseTemplateElemsFile
1211 ) where
1312
1413
1514--------------------------------------------------------------------------------
16−import Control.Applicative ((<|>))
15+import Control.Applicative ((<|>), (<*))
1716import Control.Monad (void)
17+import Control.Arrow (left)
1818import Data.Binary (Binary, get, getWord8, put, putWord8)
1919import Data.List (intercalate)
2020import Data.Maybe (isJust)
@@ -107,17 +107,10 @@ instance Binary TemplateExpr where
107107 2 -> StringLiteral <$> get
108108 _ -> error "Hakyll.Web.Template.Internal: Error reading cached template"
109109
110−
111−--------------------------------------------------------------------------------
112−readTemplateElems :: String -> [TemplateElement]
113−readTemplateElems = readTemplateElemsFile "{literal}"
114−
115−
116110--------------------------------------------------------------------------------
117−readTemplateElemsFile :: FilePath -> String -> [TemplateElement]
118−readTemplateElemsFile file input = case P.parse templateElems file input of
119− Left err -> error $ "Cannot parse template: " ++ show err
120− Right t -> t
111+parseTemplateElemsFile :: FilePath -> String -> Either String [TemplateElement]
112+parseTemplateElemsFile file = left (\e -> "Cannot parse template " ++ show e)
113+ . P.parse (templateElems <* P.eof) file
121114
122115
123116--------------------------------------------------------------------------------
@@ -167,7 +160,7 @@ trimOpen = do
167160--------------------------------------------------------------------------------
168161trimClose :: P.Parser Bool
169162trimClose = do
170− trimIfR <- P.optionMaybe $ P.try (P.char '-')
163+ trimIfR <- P.optionMaybe $ (P.char '-')
171164 void $ P.char '$'
172165 pure $ isJust trimIfR
173166
stack.yaml+9−7
@@ -1,5 +1,4 @@
1−resolver: lts-11.7
2−extra-package-dbs: []
1+resolver: lts-13.29
32save-hackage-creds: false
43
54flags:
@@ -24,8 +23,11 @@ build:
2423 haddock-deps: false
2524
2625extra-deps:
27−- 'pandoc-2.2'
28−- 'pandoc-types-1.17.4.2'
29−- 'pandoc-citeproc-0.14.3.1'
30−- 'tasty-1.1.0.1'
31−- 'fsnotify-0.3.0.0'
26+- 'cmark-gfm-0.2.0'
27+- 'hslua-module-system-0.2.1'
28+- 'ipynb-0.1'
29+- 'lrucache-1.2.0.1'
30+- 'pandoc-2.7.3'
31+- 'pandoc-citeproc-0.16.2'
32+- 'skylighting-0.8.2'
33+- 'skylighting-core-0.8.2'
tests/Hakyll/Core/UnixFilter/Tests.hs+6−14
@@ -6,18 +6,16 @@ module Hakyll.Core.UnixFilter.Tests
66
77
88--------------------------------------------------------------------------------
9−import Data.List (isInfixOf)
10−import Test.Tasty (TestTree, testGroup)
11−import Test.Tasty.HUnit (testCase)
12−import qualified Test.Tasty.HUnit as H
9+import Test.Tasty (TestTree, testGroup)
10+import Test.Tasty.HUnit (testCase)
11+import qualified Test.Tasty.HUnit as H
1312
1413
1514--------------------------------------------------------------------------------
1615import Hakyll.Core.Compiler
17−import Hakyll.Core.Compiler.Internal
16+import Hakyll.Core.Identifier
1817import Hakyll.Core.Item
1918import Hakyll.Core.UnixFilter
20−import Hakyll.Core.Identifier
2119import TestSuite.Util
2220
2321
@@ -51,10 +49,7 @@ unixFilterFalse :: H.Assertion
5149unixFilterFalse = do
5250 store <- newTestStore
5351 provider <- newTestProvider store
54− result <- testCompiler store provider testMarkdown compiler
55− case result of
56− CompilerError es -> True H.@=? any ("exit code" `isInfixOf`) es
57− _ -> H.assertFailure "Expecting CompilerError"
52+ testCompilerError store provider testMarkdown compiler "exit code"
5853 cleanTestEnv
5954 where
6055 compiler = getResourceString >>= withItemBody (unixFilter "false" [])
@@ -65,10 +60,7 @@ unixFilterError :: H.Assertion
6560unixFilterError = do
6661 store <- newTestStore
6762 provider <- newTestProvider store
68− result <- testCompiler store provider testMarkdown compiler
69− case result of
70− CompilerError es -> True H.@=? any ("invalid option" `isInfixOf`) es
71− _ -> H.assertFailure "Expecting CompilerError"
63+ testCompilerError store provider testMarkdown compiler "option"
7264 cleanTestEnv
7365 where
7466 compiler = getResourceString >>= withItemBody (unixFilter "head" ["-#"])
tests/Hakyll/Web/Template/Context/Tests.hs+40−3
@@ -13,16 +13,19 @@ import Test.Tasty.HUnit (Assertion, testCase, (@=?))
1313--------------------------------------------------------------------------------
1414import Hakyll.Core.Compiler
1515import Hakyll.Core.Identifier
16+import Hakyll.Core.Item
1617import Hakyll.Core.Provider
1718import Hakyll.Core.Store (Store)
1819import Hakyll.Web.Template.Context
20+import Hakyll.Web.Template.Internal
1921import TestSuite.Util
2022
2123
2224--------------------------------------------------------------------------------
2325tests :: TestTree
24−tests = testGroup "Hakyll.Core.Template.Context.Tests"
26+tests = testGroup "Hakyll.Web.Template.Context.Tests"
2527 [ testCase "testDateField" testDateField
28+ , testCase "testOuerLoopContextAccess" testOuerLoopContextAccess
2629 ]
2730
2831
@@ -41,6 +44,15 @@ testDateField = do
4144 dateField "date" "%B %e, %Y"
4245 date2 @=? "August 26, 2010"
4346
47+ date3 <- testContextDone store provider
48+ "posts/2018-09-26.md" "date" $
49+ dateField "date" "%B %e, %Y"
50+ date3 @=? "September 26, 2018"
51+
52+ date4 <- testContextDone store provider
53+ "posts/2019/05/10/tomorrow.md" "date" $
54+ dateField "date" "%B %e, %Y"
55+ date4 @=? "May 10, 2019"
4456 cleanTestEnv
4557
4658
@@ -53,6 +65,31 @@ testContextDone store provider identifier key context =
5365 cf <- unContext context key [] item
5466 case cf of
5567 StringField str -> return str
56− ListField _ _ -> error $
68+ _ -> error $
5769 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
58− "Didn't expect ListField"
70+ "expected StringField"
71+
72+--------------------------------------------------------------------------------
73+
74+testOuerLoopContextAccess :: Assertion
75+testOuerLoopContextAccess = do
76+ store <- newTestStore
77+ provider <- newTestProvider store
78+ test store provider ctx "baz"
79+ test store provider (ctx' <> ctx) "not baz"
80+ test store provider (ctx <> ctx') "baz"
81+
82+ cleanTestEnv
83+ where
84+ tpl = readTemplate "$for(foo)$$for(bar)$$qux$$endfor$$endfor$"
85+ ctx = mconcat [
86+ field "qux" $ const $ return "baz"
87+ , listField "foo" (listField "bar" mempty $ return [mockItem])
88+ $ return [mockItem]
89+ ]
90+ ctx' = field "qux" $ const $ return "not baz"
91+ mockItem = Item "" ()
92+ test store provider context str = do
93+ str' <- testCompilerDone store provider ""
94+ $ applyTemplate tpl context mockItem
95+ str @=? itemBody str'
tests/Hakyll/Web/Template/Tests.hs+49−17
@@ -1,5 +1,6 @@
11--------------------------------------------------------------------------------
22{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE TemplateHaskell #-}
34module Hakyll.Web.Template.Tests
45 ( tests
56 ) where
@@ -7,9 +8,10 @@ module Hakyll.Web.Template.Tests
78
89--------------------------------------------------------------------------------
910import Test.Tasty (TestTree, testGroup)
10−import Test.Tasty.HUnit (Assertion, testCase, (@=?),
11− (@?=))
11+import Test.Tasty.HUnit (Assertion, assertBool, testCase,
12+ (@=?), (@?=))
1213
14+import Data.Either (isLeft)
1315
1416--------------------------------------------------------------------------------
1517import Hakyll.Core.Compiler
@@ -25,20 +27,20 @@ import TestSuite.Util
2527
2628--------------------------------------------------------------------------------
2729tests :: TestTree
28−tests = testGroup "Hakyll.Core.Template.Tests" $ concat
30+tests = testGroup "Hakyll.Web.Template.Tests" $ concat
2931 [ [ testCase "case01" $ test ("template.html.out", "template.html", "example.md")
3032 , testCase "case02" $ test ("strip.html.out", "strip.html", "example.md")
3133 , testCase "case03" $ test ("just-meta.html.out", "just-meta.html", "example.md")
3234 , testCase "applyJoinTemplateList" testApplyJoinTemplateList
3335 ]
3436
35− , fromAssertions "readTemplate"
36− [ [Chunk "Hello ", Expr (Call "guest" [])]
37− @=? readTemplateElems "Hello $guest()$"
38− , [If (Call "a" [StringLiteral "bar"]) [Chunk "foo"] Nothing]
39− @=? readTemplateElems "$if(a(\"bar\"))$foo$endif$"
37+ , fromAssertions "parseTemplate"
38+ [ Right [Chunk "Hello ", Expr (Call "guest" [])]
39+ @=? parse "Hello $guest()$"
40+ , Right [If (Call "a" [StringLiteral "bar"]) [Chunk "foo"] Nothing]
41+ @=? parse "$if(a(\"bar\"))$foo$endif$"
4042 -- 'If' trim check.
41− , [ TrimL
43+ , Right [ TrimL
4244 , If (Ident (TemplateKey "body"))
4345 [ TrimR
4446 , Chunk "\n"
@@ -54,29 +56,39 @@ tests = testGroup "Hakyll.Core.Template.Tests" $ concat
5456 ])
5557 , TrimR
5658 ]
57− @=? readTemplateElems "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
59+ @=? parse "$-if(body)-$\n$body$\n$-else-$\n$body$\n$-endif-$"
5860 -- 'For' trim check.
59− , [ TrimL
61+ , Right [ TrimL
6062 , For (Ident (TemplateKey "authors"))
6163 [TrimR, Chunk "\n body \n", TrimL]
6264 Nothing
6365 , TrimR
6466 ]
65− @=? readTemplateElems "$-for(authors)-$\n body \n$-endfor-$"
67+ @=? parse "$-for(authors)-$\n body \n$-endfor-$"
6668 -- 'Partial' trim check.
67− , [ TrimL
69+ , Right [ TrimL
6870 , Partial (StringLiteral "path")
6971 , TrimR
7072 ]
71− @=? readTemplateElems "$-partial(\"path\")-$"
73+ @=? parse "$-partial(\"path\")-$"
7274 -- 'Expr' trim check.
73− , [ TrimL
75+ , Right [ TrimL
7476 , Expr (Ident (TemplateKey "foo"))
7577 , TrimR
7678 ]
77− @=? readTemplateElems "$-foo-$"
79+ @=? parse "$-foo-$"
80+ -- fail on incomplete template.
81+ , assertBool "did not yield error" $ isLeft $
82+ parse "a$b"
83+ -- fail on mismatched template syntax.
84+ , assertBool "did not fail to parse" $ isLeft $
85+ parse "$for(xs)$\n <p>foo</p>\n$endif$"
7886 ]
87+
88+ , [testCase "embeddedTemplate" testEmbeddedTemplate]
7989 ]
90+ where
91+ parse = parseTemplateElemsFile ""
8092
8193
8294--------------------------------------------------------------------------------
@@ -113,6 +125,8 @@ testApplyJoinTemplateList :: Assertion
113125testApplyJoinTemplateList = do
114126 store <- newTestStore
115127 provider <- newTestProvider store
128+ tpl <- testCompilerDone store provider "tpl" $
129+ compileTemplateItem (Item "tpl" "<b>$body$</b>")
116130 str <- testCompilerDone store provider "item3" $
117131 applyJoinTemplateList ", " tpl defaultContext [i1, i2]
118132
@@ -121,4 +135,22 @@ testApplyJoinTemplateList = do
121135 where
122136 i1 = Item "item1" "Hello"
123137 i2 = Item "item2" "World"
124− tpl = readTemplate "<b>$body$</b>"
138+
139+
140+--------------------------------------------------------------------------------
141+embeddedTemplate :: Template
142+embeddedTemplate = $(embedTemplate "tests/data/embed.html")
143+
144+--------------------------------------------------------------------------------
145+testEmbeddedTemplate :: Assertion
146+testEmbeddedTemplate = do
147+ store <- newTestStore
148+ provider <- newTestProvider store
149+ str <- testCompilerDone store provider "item3" $
150+ applyTemplate embeddedTemplate defaultContext item
151+
152+ itemBody str @?= "<p>Hello, world</p>\n"
153+ cleanTestEnv
154+ where
155+ item = Item "item1" "Hello, world"
156+
tests/TestSuite.hs+2
@@ -28,6 +28,7 @@ import qualified Hakyll.Web.Pandoc.FileType.Tests
2828#endif
2929import qualified Hakyll.Web.Template.Context.Tests
3030import qualified Hakyll.Web.Template.Tests
31+import qualified Hakyll.Web.Tags.Tests
3132
3233
3334--------------------------------------------------------------------------------
@@ -49,6 +50,7 @@ main = defaultMain $ testGroup "Hakyll"
4950#ifdef USE_PANDOC
5051 , Hakyll.Web.Pandoc.FileType.Tests.tests
5152#endif
53+ , Hakyll.Web.Tags.Tests.tests
5254 , Hakyll.Web.Template.Context.Tests.tests
5355 , Hakyll.Web.Template.Tests.tests
5456 ]
tests/TestSuite/Util.hs+11−2
@@ -6,6 +6,7 @@ module TestSuite.Util
66 , newTestProvider
77 , testCompiler
88 , testCompilerDone
9+ , testCompilerError
910 , testConfiguration
1011 , cleanTestEnv
1112 , renderParagraphs
@@ -13,7 +14,7 @@ module TestSuite.Util
1314
1415
1516--------------------------------------------------------------------------------
16−import Data.List (intercalate)
17+import Data.List (intercalate, isInfixOf)
1718import Data.Monoid (mempty)
1819import qualified Data.Set as S
1920import Test.Tasty
@@ -80,13 +81,21 @@ testCompilerDone store provider underlying compiler = do
8081 CompilerDone x _ -> return x
8182 CompilerError e -> fail $
8283 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
83− " threw: " ++ intercalate "; " e
84+ " threw: " ++ intercalate "; " (compilerErrorMessages e)
8485 CompilerRequire i _ -> fail $
8586 "TestSuite.Util.testCompilerDone: compiler " ++ show underlying ++
8687 " requires: " ++ show i
8788 CompilerSnapshot _ _ -> fail
8889 "TestSuite.Util.testCompilerDone: unexpected CompilerSnapshot"
8990
91+testCompilerError :: Store -> Provider -> Identifier -> Compiler a -> String -> IO ()
92+testCompilerError store provider underlying compiler expectedMessage = do
93+ result <- testCompiler store provider underlying compiler
94+ case result of
95+ CompilerError e ->
96+ any (expectedMessage `isInfixOf`) (compilerErrorMessages e) @?
97+ "Expecting '" ++ expectedMessage ++ "' error"
98+ _ -> assertFailure "Expecting CompilerError"
9099
91100--------------------------------------------------------------------------------
92101testConfiguration :: Configuration
tests/data/embed.htmlnew file+1
@@ -0,0 +1 @@
1+<p>$body$</p>
tests/data/posts/2018-09-26.mdnew file+1
@@ -0,0 +1 @@
1+Something happened today.
tests/data/posts/2019/05/10/tomorrow.mdnew file+1
@@ -0,0 +1 @@
1+This day hasn't happened yet (as of writing this).
web/css/syntax.css+61−18
@@ -1,18 +1,61 @@
1−/* Generated by pandoc. */
2−table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre
3− { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
4−td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
5−td.sourceCode { padding-left: 5px; }
6−.sourceCode span.kw { color: #007020; font-weight: bold; }
7−.sourceCode span.dt { color: #902000; }
8−.sourceCode span.dv { color: #40a070; }
9−.sourceCode span.bn { color: #40a070; }
10−.sourceCode span.fl { color: #40a070; }
11−.sourceCode span.ch { color: #4070a0; }
12−.sourceCode span.st { color: #4070a0; }
13−.sourceCode span.co { color: #60a0b0; font-style: italic; }
14−.sourceCode span.ot { color: #007020; }
15−.sourceCode span.al { color: red; font-weight: bold; }
16−.sourceCode span.fu { color: #06287e; }
17−.sourceCode span.re { }
18−.sourceCode span.er { color: red; font-weight: bold; }
1+a.sourceLine { display: inline-block; line-height: 1.25; }
2+a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
3+a.sourceLine:empty { height: 1.2em; }
4+.sourceCode { overflow: visible; }
5+code.sourceCode { white-space: pre; position: relative; }
6+div.sourceCode { margin: 1em 0; }
7+pre.sourceCode { margin: 0; }
8+@media screen {
9+div.sourceCode { overflow: auto; }
10+}
11+@media print {
12+code.sourceCode { white-space: pre-wrap; }
13+a.sourceLine { text-indent: -1em; padding-left: 1em; }
14+}
15+pre.numberSource a.sourceLine
16+ { position: relative; left: -4em; }
17+pre.numberSource a.sourceLine::before
18+ { content: attr(title);
19+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
20+ border: none; pointer-events: all; display: inline-block;
21+ -webkit-touch-callout: none; -webkit-user-select: none;
22+ -khtml-user-select: none; -moz-user-select: none;
23+ -ms-user-select: none; user-select: none;
24+ padding: 0 4px; width: 4em;
25+ color: #aaaaaa;
26+ }
27+pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
28+div.sourceCode
29+ { }
30+@media screen {
31+a.sourceLine::before { text-decoration: underline; }
32+}
33+code span.al { color: #ff0000; font-weight: bold; } /* Alert */
34+code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
35+code span.at { color: #7d9029; } /* Attribute */
36+code span.bn { color: #40a070; } /* BaseN */
37+code span.bu { } /* BuiltIn */
38+code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
39+code span.ch { color: #4070a0; } /* Char */
40+code span.cn { color: #880000; } /* Constant */
41+code span.co { color: #60a0b0; font-style: italic; } /* Comment */
42+code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
43+code span.do { color: #ba2121; font-style: italic; } /* Documentation */
44+code span.dt { color: #902000; } /* DataType */
45+code span.dv { color: #40a070; } /* DecVal */
46+code span.er { color: #ff0000; font-weight: bold; } /* Error */
47+code span.ex { } /* Extension */
48+code span.fl { color: #40a070; } /* Float */
49+code span.fu { color: #06287e; } /* Function */
50+code span.im { } /* Import */
51+code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
52+code span.kw { color: #007020; font-weight: bold; } /* Keyword */
53+code span.op { color: #666666; } /* Operator */
54+code span.ot { color: #007020; } /* Other */
55+code span.pp { color: #bc7a00; } /* Preprocessor */
56+code span.sc { color: #4070a0; } /* SpecialChar */
57+code span.ss { color: #bb6688; } /* SpecialString */
58+code span.st { color: #4070a0; } /* String */
59+code span.va { color: #19177c; } /* Variable */
60+code span.vs { color: #4070a0; } /* VerbatimString */
61+code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
web/examples.markdown+20−6
@@ -45,7 +45,7 @@ directly with the default Hakyll site.
4545- <http://www.regisfoucault.com/>,
4646 [source](https://github.com/regisfoucault/blog)
4747- <http://www.chaoxuprime.com/>,
48− [source](https://github.com/Mgccl/blog)
48+ [source](https://github.com/chaoxu/chaoxu.github.io/tree/develop)
4949- <http://www.skybluetrades.net/>,
5050 [source](https://github.com/ian-ross/blog)
5151- <http://chromaticleaves.com/>,
@@ -98,8 +98,8 @@ directly with the default Hakyll site.
9898 [source](https://github.com/Libbum/AxiomaticSemantics)
9999- [https://tesser.org/](http://web.archive.org/web/20161022221713/https://tesser.org/),
100100 [source](https://github.com/fractalcat/tesser.org)
101−- <https://wei2912.github.io/>,
102− [source](https://github.com/wei2912/blog_src)
101+- <https://weien.io/>,
102+  [source](https://github.com/wei2912/blog-src)
103103- <http://www.metasepi.org/>,
104104 [source](https://github.com/metasepi/metasepi-website)
105105- <http://gisli.hamstur.is/>,
@@ -166,10 +166,24 @@ directly with the default Hakyll site.
166166 [source](https://github.com/bendo/bendo.github.io)
167167- <http://adarsh.cc/>,
168168 [source](https://github.com/adarshp/adarsh.cc)
169−- <http://zer0.degree/>,
170− [source](https://github.com/arrchhy/zer0.degree)
169+- <http://0a.io>,
170+ [source](https://github.com/arrchyy/0a.io)
171171- <https://nasy.moe/>,
172− [source](https://github.com/nasyxx/nasyxx.github.io)
172+ [source](https://github.com/nasyxx/NasyMoe)
173+- <http://uniprocess.org/>,
174+ [source](https://gitlab.com/uniprocess/uniprocess.org)
175+- <https://regularflolloping.com/>,
176+ [source](https://github.com/techieAgnostic/rf)
177+- <http://enter-haken.github.io/>,
178+ [source](https://github.com/enter-haken/blog)
179+- <https://modular.blind.guru/>,
180+ [source](https://github.com/mlang/eurorack-metadata)
181+- <http://www.jonashietala.se/>,
182+ [source](https://github.com/treeman/jonashietala)
183+- <https://abhinavsarkar.net/>,
184+ [source](https://github.com/abhin4v/abhin4v.github.io)
185+- <https://dailyreadingnotes.com/>,
186+ [source](https://github.com/hackeryarn/daily-reading-notes)
173187
174188## Hakyll 3.X
175189
web/site.hs+14−32
@@ -1,8 +1,7 @@
11--------------------------------------------------------------------------------
22{-# LANGUAGE OverloadedStrings #-}
33import Control.Arrow (second)
4−import Control.Monad (forM_)
5−import Data.Char (isDigit)
4+import Control.Monad (filterM, forM_)
65import Data.List (isPrefixOf, sortBy)
76import Data.Monoid ((<>))
87import Data.Ord (comparing)
@@ -57,17 +56,11 @@ main = hakyllWith config $ do
5756 create ["tutorials.html"] $ do
5857 route idRoute
5958 compile $ do
60− tuts <-
59+ ctx <- tutorialsCtx <$>
6160 sortBy (comparing itemIdentifier) <$> loadAll "tutorials/*"
62−
63− let tutorialsCtx =
64− constField "title" "Tutorials" `mappend`
65− listField "tutorials" tutorialCtx (return tuts) `mappend`
66− defaultContext
67−
6861 makeItem ""
69− >>= loadAndApplyTemplate "templates/tutorials.html" tutorialsCtx
70− >>= loadAndApplyTemplate "templates/default.html" tutorialsCtx
62+ >>= loadAndApplyTemplate "templates/tutorials.html" ctx
63+ >>= loadAndApplyTemplate "templates/default.html" ctx
7164 >>= relativizeUrls
7265
7366 -- Templates
@@ -108,28 +101,17 @@ hackage url
108101 reverse $ splitPath url
109102
110103
111−--------------------------------------------------------------------------------
112−data TutorialType = SeriesTutorial | ArticlesTutorial | ExternalTutorial
113− deriving (Eq)
114−
115−
116104--------------------------------------------------------------------------------
117105-- | Partition tutorials into tutorial series, other articles, external articles
118−tutorialCtx :: Context String
119−tutorialCtx =
120− field "isSeries" (isTutorialType SeriesTutorial) <>
121− field "isArticle" (isTutorialType ArticlesTutorial) <>
122− field "isExternal" (isTutorialType ExternalTutorial) <>
106+tutorialsCtx :: [Item String] -> Context String
107+tutorialsCtx tuts =
108+ constField "title" "Tutorials" <>
109+ listField "main" defaultContext (ofType "main") <>
110+ listField "articles" defaultContext (ofType "article") <>
111+ listField "externals" defaultContext (ofType "external") <>
112+ listField "robertwpearce" defaultContext (ofType "robertwpearce") <>
123113 defaultContext
124114 where
125− getTutorialType item = do
126− mbExternal <- getMetadataField (itemIdentifier item) "external"
127− return $ case mbExternal of
128− Just _ -> ExternalTutorial
129− _ -> case splitPath (toFilePath $ itemIdentifier item) of
130− [_, (x : _)] -> if isDigit x then SeriesTutorial else ArticlesTutorial
131− _ -> ArticlesTutorial
132−
133− isTutorialType ty0 item = do
134− ty1 <- getTutorialType item
135− if ty0 == ty1 then return "yes" else fail "no"
115+ ofType ty = filterM (\item -> do
116+ mbType <- getMetadataField (itemIdentifier item) "type"
117+ return $ Just ty == mbType) tuts
web/templates/tutorials.html+24−18
@@ -1,23 +1,19 @@
11<h1>Tutorials about Hakyll</h1>
22<h2 id="series">Tutorial series</h2>
33<ul>
4− $for(tutorials)$
5− $if(isSeries)$
6− <li>
7− <a href="$url$">$title$</a>
8− </li>
9− $endif$
4+ $for(main)$
5+ <li>
6+ <a href="$url$">$title$</a>
7+ </li>
108 $endfor$
119</ul>
1210<h2 id="articles">Other articles</h2>
1311<p>In no particular order:</p>
1412<ul>
15− $for(tutorials)$
16− $if(isArticle)$
17− <li>
18− <a href="$url$">$title$</a> by <em>$author$</em>
19− </li>
20− $endif$
13+ $for(articles)$
14+ <li>
15+ <a href="$url$">$title$</a> by <em>$author$</em>
16+ </li>
2117 $endfor$
2218</ul>
2319<h2 id="external-articles">External articles</h2>
@@ -28,12 +24,22 @@
2824</p>
2925<p>In no particular order:</p>
3026<ul>
31− $for(tutorials)$
32− $if(isExternal)$
33− <li>
34− <a href="$url$">$title$</a> by <em>$author$</em>
35− </li>
36− $endif$
27+ $for(externals)$
28+ <li>
29+ <a href="$url$">$title$</a> by <em>$author$</em>
30+ </li>
31+ $endfor$
32+</ul>
33+<h2 id="robertwpearce">Robert Pearce's series</h2>
34+<p>
35+ <a href="https://robertwpearce.com/">Robert Pearce</a> has been writing an
36+ excellent tutorial-style series on Hakyll as well. You can find those here:
37+</p>
38+<ul>
39+ $for(robertwpearce)$
40+ <li>
41+ <a href="$url$">$title$</a>
42+ </li>
3743 $endfor$
3844</ul>
3945<p>
web/tutorials/01-installation.markdown+4−2
@@ -1,6 +1,7 @@
11---
22title: Installation
33author: Jasper Van der Jeugt
4+type: main
45---
56
67Installation
@@ -17,7 +18,8 @@ different distributions. For installation from source (i.e. via Hackage),
1718Linux distro packages:
1819
1920- [Debian unstable](http://packages.debian.org/source/sid/haskell-hakyll)
20−- [Fedora](https://apps.fedoraproject.org/packages/ghc-hakyll-devel)
21+- [Fedora](https://apps.fedoraproject.org/packages/ghc-hakyll)
22+- [Nix](https://nixos.org/nixos/packages.html#hakyll): `$ nix-env -i hakyll`
2123
2224Building the example site
2325-------------------------
@@ -26,7 +28,7 @@ Apart from the main Hakyll library, the cabal package also provides you with an
2628executable `hakyll-init` to create an example site. This is an easy way to get
2729started:
2830
29− $ hakyll-init my-site
31+ $ stack exec hakyll-init my-site
3032
3133This creates a folder `my-site` in the current directory, with some example
3234content and a generic configuration.
web/tutorials/02-basics.markdown+1
@@ -1,6 +1,7 @@
11---
22title: The basics
33author: Jasper Van der Jeugt
4+type: main
45---
56
67Building and cleaning
web/tutorials/03-rules-routes-compilers.markdown+1
@@ -1,6 +1,7 @@
11---
22title: Rules, routes and compilers
33author: Jasper Van der Jeugt
4+type: main
45---
56
67Basic rules
web/tutorials/04-compilers.markdown+1
@@ -1,6 +1,7 @@
11---
22title: 'More on compilers: load, and templates'
33author: Jasper Van der Jeugt
4+type: main
45---
56
67Loading items
web/tutorials/05-snapshots-feeds.markdown+1
@@ -1,6 +1,7 @@
11---
22title: Snapshots, and how to produce an RSS/Atom feed
33author: Jasper Van der Jeugt
4+type: main
45---
56
67Basic feed configuration
web/tutorials/06-versions.markdown+1
@@ -1,6 +1,7 @@
11---
22title: Producing multiple versions of a single file
33author: Jasper Van der Jeugt
4+type: main
45---
56
67Basics
web/tutorials/a-guide-to-the-hakyll-module-zoo.markdown+1
@@ -1,6 +1,7 @@
11---
22title: A Guide to the Hakyll Module Zoo
33author: Brent Yorgey
4+type: article
45---
56
67The hakyll package [contains a bewildering array](/reference/) of modules, and
web/tutorials/external-add-tags-to-your-hakyll-blog.md+1−1
@@ -2,5 +2,5 @@
22title: Add tags to your Hakyll blog
33author: Javran Cheng
44url: https://javran.github.io/posts/2014-03-01-add-tags-to-your-hakyll-blog.html
5−external: true
5+type: external
66---
web/tutorials/external-blogger-port.md+1−1
@@ -2,5 +2,5 @@
22title: Port an existing Blogger blog to Hakyll
33author: Daniel Campoverde
44url: 'http://www.sillybytes.net/posts/from_blogger_to_hakyll.html'
5−external: true
5+type: external
66---
web/tutorials/external-cassius-template.md+1−1
@@ -2,5 +2,5 @@
22title: Using Cassius templating with Hakyll
33author: Daniel Campoverde
44url: 'http://www.sillybytes.net/posts/using_hakyll_with_cassius.html'
5−external: true
5+type: external
66---
web/tutorials/external-clean-urls-with-hakyll.md+1−1
@@ -2,5 +2,5 @@
22title: Clean URLs with Hakyll
33author: Rohan Jain
44url: http://www.rohanjain.in/hakyll-clean-urls/
5−external: true
5+type: external
66---
web/tutorials/external-deploying-with-widely.md+1−1
@@ -2,5 +2,5 @@
22title: Deploying with Widely
33author: Kyle Marek-Spartz
44url: http://kyle.marek-spartz.org/posts/2013-12-09-widely-and-hakyll.html
5−external: true
5+type: external
66---
web/tutorials/external-external-code-inclusion.mdnew file+6
@@ -0,0 +1,6 @@
1+---
2+title: 'External code inclusion with Hakyll'
3+author: 'Tobias Pleyer'
4+url: 'http://blog.tpleyer.de/posts/2019-04-21-external-code-inclusion-with-hakyll.html'
5+type: external
6+---
web/tutorials/external-functionfield.md+1−1
@@ -2,5 +2,5 @@
22title: Hakyll's functionField
33author: Beerend Lauwers
44url: http://beerendlauwers.be/posts/2015-09-21-hakylls-functionfield.html
5−external: true
5+type: external
66---
web/tutorials/external-github-pages-circle-ci.md+1−1
@@ -2,5 +2,5 @@
22title: Create a GitHub page with Hakyll and CircleCI
33author: Juan Pedro Villa
44url: https://www.stackbuilders.com/news/dr-hakyll-create-a-github-page-with-hakyll-and-circleci
5−external: true
5+type: external
66---
web/tutorials/external-inlining-and-compressing-css.md+1−1
@@ -2,5 +2,5 @@
22title: Inlining and compressing CSS
33author: Kyle Marek-Spartz
44url: http://kyle.marek-spartz.org/posts/2014-12-09-hakyll-css-template-compiler.html
5−external: true
5+type: external
66---
web/tutorials/faq.markdown+1
@@ -1,6 +1,7 @@
11---
22title: FAQ
33author: Jasper Van der Jeugt
4+type: article
45---
56
67## "hGetContents: invalid argument" or "commitBuffer: invalid argument"
web/tutorials/github-pages-tutorial.md+1
@@ -1,6 +1,7 @@
11---
22title: Using Hakyll with GitHub Pages
33author: Erik Stevenson
4+type: article
45---
56
67## Introduction
web/tutorials/hakyll-3-to-hakyll4-migration-guide.markdown+1
@@ -1,6 +1,7 @@
11---
22title: Hakyll 3 to Hakyll 4 migration guide
33author: Jasper Van der Jeugt
4+type: article
45---
56
67Introduction
web/tutorials/robertwpearce-01-setup-and-initial-customization.htmlnew file+5
@@ -0,0 +1,5 @@
1+---
2+title: 'Pt. 1: Setup & Initial Customization'
3+url: 'https://robertwpearce.com/hakyll-pt-1-setup-and-initial-customization.html'
4+type: robertwpearce
5+---
web/tutorials/robertwpearce-02-generating-a-sitemap-xml-file.htmlnew file+5
@@ -0,0 +1,5 @@
1+---
2+title: 'Pt. 2: Generating a Sitemap XML File'
3+url: 'https://robertwpearce.com/hakyll-pt-2-generating-a-sitemap-xml-file.html'
4+type: robertwpearce
5+---
web/tutorials/robertwpearce-03-generating-rss-and-atom-xml-feeds.htmlnew file+5
@@ -0,0 +1,5 @@
1+---
2+title: 'Pt. 3: Generating RSS and Atom XML Feeds'
3+url: 'https://robertwpearce.com/hakyll-pt-3-generating-rss-and-atom-xml-feeds.html'
4+type: robertwpearce
5+---
web/tutorials/robertwpearce-04-copying-static-files-for-your-build.htmlnew file+5
@@ -0,0 +1,5 @@
1+---
2+title: 'Pt. 4: Copying Static Files For Your Build'
3+url: 'https://robertwpearce.com/hakyll-pt-4-copying-static-files-for-your-build.html'
4+type: robertwpearce
5+---
web/tutorials/robertwpearce-05-generating-custom-post-filenames-from-a-title-slug.htmlnew file+5
@@ -0,0 +1,5 @@
1+---
2+title: 'Pt. 5 – Generating Custom Post Filenames From a Title Slug'
3+url: 'https://robertwpearce.com/hakyll-pt-5-generating-custom-post-filenames-from-a-title-slug.html'
4+type: robertwpearce
5+---
web/tutorials/using-clay-with-hakyll.markdown+1
@@ -1,6 +1,7 @@
11---
22title: Using Clay with Hakyll
33author: Jasper Van der Jeugt
4+type: article
45---
56
67[Clay](http://sebastiaanvisser.github.com/clay/) is a nice CSS preprocesser
web/tutorials/using-teasers-in-hakyll.markdown+1
@@ -1,6 +1,7 @@
11---
22title: Using teasers in Hakyll
33author: Ivan Veselov
4+type: article
45---
56
67## Introduction