Fixed image previews just in time to not want Hakyll anymore
This commit is contained in:
parent
41ba569234
commit
f12c4b3773
27
site.hs
27
site.hs
@ -52,13 +52,15 @@ options = Options { verbosity = True
|
||||
}
|
||||
}
|
||||
|
||||
reducedExtn :: FilePath -> FilePath
|
||||
reducedExtn x = replaceExtension x (".reduced" ++ takeExtension x)
|
||||
|
||||
-- | Main entry point for generating all code via Hakyll
|
||||
main :: IO ()
|
||||
main = do
|
||||
E.setLocaleEncoding E.utf8
|
||||
hakyll $ do
|
||||
--hakyllWithArgs config options $ do
|
||||
-- Build up tags
|
||||
--hakyllWithArgs config options $ do tags
|
||||
tags <- buildTags "posts/*" (fromCapture "tags/*.html")
|
||||
let postCtxTags = postCtxWithTags tags
|
||||
|
||||
@ -67,12 +69,13 @@ main = 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
|
||||
-- But also, make reduced versions with (e.g.) that replace
|
||||
-- "foo.jpg" with ".reduced.jpg":
|
||||
match ("images/**.jpg" .||. "images/**.png") $ version "reduced" $ do
|
||||
--route $ customRoute $ combine "./thumbnail/" . toFilePath
|
||||
route $ customRoute $ reducedExtn . toFilePath
|
||||
compile $ loadImage
|
||||
>>= scaleImageCompiler 640 480
|
||||
>>= scaleImageCompiler 500 500
|
||||
|
||||
-- (I don't fully understand what role "version" plays here except
|
||||
-- that it appears to be required for me to have two matches on
|
||||
@ -161,8 +164,16 @@ main = do
|
||||
route idRoute
|
||||
compile $ do
|
||||
posts <- recentFirst =<< loadAllSnapshots "works/*" "content"
|
||||
let getExtn x = do
|
||||
s <- getMetadataField' (itemIdentifier x) "img"
|
||||
return $ reducedExtn s
|
||||
-- TODO: Can't I make this a simpler (well... maybe)
|
||||
-- one-liner?
|
||||
let ctxt2 = postCtxTags `mappend` (field "imgpreview" getExtn)
|
||||
-- Why does this work? I guess imgpreview needs to be
|
||||
-- inside the listField (given how I use it).
|
||||
let archiveCtx =
|
||||
listField "works" postCtxTags (return posts) `mappend`
|
||||
listField "works" ctxt2 (return posts) `mappend`
|
||||
constField "title" "Something" `mappend`
|
||||
defaultContext
|
||||
makeItem ""
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<div class="col-sm-6">
|
||||
<h3>$title$</h3>
|
||||
<a href="$img$">
|
||||
<img src="$img$" class="img-responsive"/>
|
||||
<img src="$imgpreview$" class="img-responsive"/>
|
||||
</a>
|
||||
<!-- N.B. use img-fluid for Bootstrap 4 -->
|
||||
$if(description)$
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user