From 41ba569234598b7aed952d5052c4b4b350846e62 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Fri, 24 Jan 2020 18:23:37 -0500 Subject: [PATCH] Added experimental match & route to resize images to previews It does not yet *use* the previews, it just puts them into a path with 'thumbnail' prepended. Thanks, hakyll-gallery, for the inspiration. --- blag.cabal | 1 + site.hs | 19 ++++++++++++++++++- stack.yaml | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/blag.cabal b/blag.cabal index 95d68ff..1bcf143 100644 --- a/blag.cabal +++ b/blag.cabal @@ -7,6 +7,7 @@ executable site main-is: site.hs build-depends: base == 4.* , hakyll >= 4.6 + , hakyll-images >= 0.4.4 , filepath , containers , pandoc diff --git a/site.hs b/site.hs index 3d6ddec..5c70563 100644 --- a/site.hs +++ b/site.hs @@ -9,6 +9,7 @@ Portability : POSIX {-# LANGUAGE OverloadedStrings #-} import Data.Monoid (mappend) import Hakyll +import Hakyll.Images import System.FilePath import Text.Pandoc.Options import qualified GHC.IO.Encoding as E @@ -61,7 +62,23 @@ main = do tags <- buildTags "posts/*" (fromCapture "tags/*.html") let postCtxTags = postCtxWithTags tags - match ("images/**" .||. "assets/**" .||. "assets_external/**" .||. "css/*" .||. "js/**") $ do + -- Pass through all full-size images: + match ("images/**") $ version "full" $ do + route idRoute + compile copyFileCompiler + + -- But also, make 640x480 reduced versions with /thumbnail + -- prepended to their path: + match ("images/**.jpg" .||. "images/**.png") $ version "thumbnail" $ do + route $ customRoute $ combine "./thumbnail/" . toFilePath + compile $ loadImage + >>= scaleImageCompiler 640 480 + + -- (I don't fully understand what role "version" plays here except + -- that it appears to be required for me to have two matches on + -- the same file paths.) + + match ("assets/**" .||. "assets_external/**" .||. "css/*" .||. "js/**") $ do route idRoute compile copyFileCompiler diff --git a/stack.yaml b/stack.yaml index fe25ab4..4481c07 100644 --- a/stack.yaml +++ b/stack.yaml @@ -7,3 +7,4 @@ nix: packages: [zlib] extra-deps: +- hakyll-images-0.4.4