hakyll icon indicating copy to clipboard operation
hakyll copied to clipboard

Absolute provider filepaths

Open hpacheco opened this issue 7 years ago • 6 comments

I have noticed that Hakyll rules cannot locate absolute filepaths outside of the configuration providerDirectory. Is this a premeditated choice or a misfeature? If so, I believe that it would be helpful to generalize providerDirectory to be a list.

I was trying to build a package with built-in hakyll templates, hence it would be useful to refer to those package-dependent files.

hpacheco avatar Sep 11 '17 09:09 hpacheco

This would also be useful for vendoring: I have a provider directory ./root/ but want to copy the bootstrap js from ./vendor/bootstrap to ./root/js/.

lukasstevens avatar Apr 10 '21 17:04 lukasstevens

I'm not Hakyll's author, so I can't provide you a rationale, but if providerDirectory was a list, how would Hakyll resolve relative paths? For example:

  1. suppose providerDirectory is [ "./root/", "./vendor/" ]
  2. both ./root/bootstrap and ./vendor/bootstrap exist
  3. I have a match "bootstrap/*" $ … in my Hakyll rules — how would Hakyll figure out which of the two "bootstrap" directories to use?

Also, in @lukasstevens's case, why not move the provider directory up a level, so it incudes both "root" and "vendor" as sub-directories?

Minoru avatar Apr 10 '21 19:04 Minoru

Hm, for me it would be enough if you could escape from the providerDirectory if you use a relative path that leaves the directory. Moving providerDirectory up is inconvenient because you have to always delete the directory root/ from the route using gsubRoute.

lukasstevens avatar Apr 10 '21 19:04 lukasstevens

Moving providerDirectory up is inconvenient because you have to always delete the directory root/ from the route using gsubRoute.

You have Haskell at your disposal, surely you could abstract this away ;)

Minoru avatar Apr 10 '21 19:04 Minoru

You are correct, of course :). Nevertheless, I find it a bit surprising that you can't access paths outside the directory.

lukasstevens avatar Apr 10 '21 19:04 lukasstevens

Yeah, would agree that the provider abstraction isn't great. I think there may be some ways to fix this but I want to be careful about backward-compatibility. As a workaround, you can always do something like:

create ["foo.html"] $ do
    compile $ do
        content <- unsafeCompile $ readFile "/some/absolute/path/...
        ...

The drawback of this is that changes to /some/absolute/path/... will not be tracked be the provider abstraction, so you may need to do a full rebuild of your site once in a while.

jaspervdj avatar Apr 11 '21 07:04 jaspervdj