Yes, your guess absolutely right.
Thank you for broad answer, actually I will need both described examples.
Post by Jasper Van der JeugtNot really. The problem is that you're (I'm making an educated guess
here) using `defaultContext`, which is
defaultContext :: Context String
whereas you need something of the form
imageContext :: Context CopyField
Say that `templates/image.html` has the template for a single image
(using `$url$`) and I want to create a webpage listing all images. I'd
match "images/*" $ do
route idRoute
compile copyFileCompiler
create ["images.html"] $ do
route idRoute
compile $ do
let imageCtx :: Context CopyFile
imageCtx = mconcat
[ urlField "url"
, missingField -- For better error messages
]
images <- loadAll "images/*"
imageTpl <- loadBody "templates/image.html"
applyTemplateList imageTpl imageCtx images >>= makeItem
This solution uses templates which might be a bit bloated for what you need.
Another alternative option would be something like
imageIdentifiers <- getMatches "images/*" :: Compiler [Identifier]
and then use
getRoute :: Identifier -> Compiler (Maybe FilePath)
to obtain the route. With
toUrl :: FilePath -> String
you prefix the filepath with an `/`, which is probably necessary.
Hope this helps,
Peace,
Jasper
On Tue, Jan 8, 2013 at 3:29 PM, Sergey Bushnyak
Post by Sergey BushnyakFollow up question, how can I explicitly get url to those images? For
example I need to fill carousel on main page through one template,
then make gallery in another and just some in posts.
I'm getting something like this
[ERROR] Hakyll.Core.Compiler.Require.load: images/promo/promo-four.jpg
(snapshot _final) was found in the cache, but does not have the right
expected [Char] but got CopyFile
which is actually right, since I use copyFileCompiler at first for all
images. Do I need a custom compiler and then use case like in thread -
Hakyll 4 & mutliple compilers for the same source
https://groups.google.com/forum/?fromgroups=#!topic/hakyll/OZpggt3SaBw?
Post by Jasper Van der JeugtHello Sergey,
You can use
match "images/**" $ do
route idRoute
compile copyFileCompiler
To search subdirectories as well.
Hope this helps,
Peace,
Jasper
Post by s***@public.gmane.orgWhat is the proper way to match and copy files in subdirs?
I have a lot of images in subdirectories, basic
match "images/*" $ do
route idRoute
compile copyFileCompiler
handle only first level, I tried something like this, by analogy when
matching static pages
match (fromList ["images/*", "images/promo/*, "images/as/*""]) $ do
route idRoute
compile copyFileCompiler
but this doesn't copy any image at all. I definitely missing
something.