Discussion:
Matching files in subdirectories
s***@public.gmane.org
2013-01-08 08:45:21 UTC
Permalink
What 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.
Jasper Van der Jeugt
2013-01-08 08:52:22 UTC
Permalink
Hello 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.org
What 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.
Sergey Bushnyak
2013-01-08 09:15:28 UTC
Permalink
Thanks, that second * was the case, didn't know about it.
Post by Jasper Van der Jeugt
Hello 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.org
What 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.
Sergey Bushnyak
2013-01-08 14:29:27 UTC
Permalink
Follow 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 type:
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 Jeugt
Hello 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.org
What 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.
Jasper Van der Jeugt
2013-01-08 14:41:32 UTC
Permalink
Not 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
use something like:

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 Bushnyak
Follow 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
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 Jeugt
Hello 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.org
What 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.
Sergey Bushnyak
2013-01-08 14:56:17 UTC
Permalink
Yes, your guess absolutely right.
Thank you for broad answer, actually I will need both described examples.
Post by Jasper Van der Jeugt
Not 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 Bushnyak
Follow 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 Jeugt
Hello 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.org
What 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.
z***@gmail.com
2016-05-16 13:20:20 UTC
Permalink
does it actually work? didn't work for me though? no files were copied to
generated site
Post by Jasper Van der Jeugt
Hello 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.org
What 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.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2016-05-16 19:10:31 UTC
Permalink
I just verified it with the example site to make and it should be in
perfect working order. Two things to check:

1. Are you sure you are using the "**" in the pattern instead of just
"*", to match subdirectories as well?
2. Are you overriding the rule later by giving another "images/**"
pattern?

Peace,
Jasper
Post by z***@gmail.com
does it actually work? didn't work for me though? no files were copied to
generated site
Post by Jasper Van der Jeugt
Hello 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.org
What 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.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sergey Bushnyak
2016-05-25 17:50:14 UTC
Permalink
Still works perfectly for me, share some of your code. That way we can help
you out
Post by z***@gmail.com
does it actually work? didn't work for me though? no files were copied to
generated site
Post by Jasper Van der Jeugt
Hello 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.org
What 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.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
s***@gmail.com
2016-06-19 22:00:11 UTC
Permalink
So, you actually might have to run `stack build` and `stack exec site
rebuild` for that take effect. I wasn't getting any result either until I
dug around the documents more and found out about it.
Post by z***@gmail.com
does it actually work? didn't work for me though? no files were copied to
generated site
Post by Jasper Van der Jeugt
Hello 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.org
What 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.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2016-06-21 08:45:25 UTC
Permalink
Yes, whenever you change your site's source code, you need to recompile
the executable first.

Peace,
Jasper
Post by s***@gmail.com
So, you actually might have to run `stack build` and `stack exec site
rebuild` for that take effect. I wasn't getting any result either until I
dug around the documents more and found out about it.
Post by z***@gmail.com
does it actually work? didn't work for me though? no files were copied to
generated site
Post by Jasper Van der Jeugt
Hello 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.org
What 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.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...