jekyll-assets
jekyll-assets copied to clipboard
Absolute path to assets
- [x] I tried updating to the latest version.
- [x] I can't, there is an issue.
- [ ] I Am on Windows
- [ ] Ubuntu Bash on Windows
- [ ] Fedora Bash on Windows
- [ ] Other Bash on Windows
- [ ] I Am on Linux
- [ ] Ubuntu
- [ ] Fedora
- [x] I Am on macOS
- [x] I'm on Docker
- [x] I understand Docker may be unsupported.
We use jekyll 3.8.1 and jekyll-assets 3.0.11 (before the upgrade 2.4.0)
Description
We have a multilanguage site based on jekyll-multiple-languages-plugin, and server the default language under /
while an english version is served under /en/
.
Assets are excluded from translations and compiled to /assets/
We previously used asset_path
which always gave the correct path to the assets.
Using the new asset
the asset url is now relative to the language path e.g. /en/assets/...
<link rel="stylesheet" href="{% asset_path main %}" type="text/css">
was converted to (both versions below don't work and will return the prefixed path)
<link rel="stylesheet" href="{% asset main @path %}" type="text/css">
or
<link rel="stylesheet" href="{% asset 'main.css' @path %}" type="text/css">
Expected
We need a way to get the absolute path to the assets, or at least relative to the root.
What is the output result?
It's
/en/assets/main-54ec998fc60245ee09c449e01a2549e752690ad7f1ded1c198dee85acb69b189.css
while I expect it to be
/assets/main-54ec998fc60245ee09c449e01a2549e752690ad7f1ded1c198dee85acb69b189.css
.
I'll consider fixing the problem, but this is their bug, not mine, they alter the base URL in a way that alters Jekyll's default behavior, this puts the problem square in their hands, and it should be their's to fix, not mine, it's bad software practice to expect me to fix bugs in another persons software.
Hmm, I see that the bug is not within jekyll-assets
, and I don't expect you to alter your software to be compatible with a (mostly unmaintained jekyll plugin) to fix this ;)
Since behaviour/api changed from 2.4.* to 3.* I hoped that I missed something in the documentation that can give me the absolute asset path.
Do you think of a workaround, as we unfortunately cannot get rid of the multilanguage plugin, but still want to have dependencies on the latest possible version?
Previously in 2.x I think we worked around the issue by giving them a special configuration, but that was a bit hacky and I didn't necessarily like it so if I remember right, I removed it. I might add in a secondary method that allows you to achieve what you want, how I'll go about it I don't know, but you can always just remove it with:
{% asset asset.png | remove: site.baseurl %}
(that might or might not work, I don't remember if builtin stuff accepts liquid variables. The problem comes in that we set the baseURL expecting it's like most setups, but they hack the baseURL to achieve what they want (not a big deal really but it does affect other plugins considerably in the way of optimization.)
I have a different use case for needing an absolute path to an asset, namely the og:image tag (set via a meta tag) for Facebook preview must be an absolute path. The Facebook debugger returns an error with a relative path. Thanks for considering this.
Is there any update on this ? I'm also interested about this
~A quick workaround for this is to inline your CSS~
~{% asset main.css @inline %}
~
~But be aware, your CSS will no longer be cached.~
This way is much better. Replace /pl
with whatever is your secondary language.
<!-- {% asset main.css %} -->
<link rel="stylesheet" href="{{ assets['main.scss'].digest_path | remove: '/pl'}}">
Note that the asset must first be called in order for it to be generated. It is then commented out so it doesn't interfere.
Having the same issue. It looks like there is code specifically for this issue, but it does not work for some reason:
https://github.com/envygeeks/jekyll-assets/blob/ce5c8cc43df9911e0788f06423a27375ee67c00f/lib/jekyll/assets/utils.rb#L233
I have a different use case for needing an absolute path to an asset, namely the og:image tag (set via a meta tag) for Facebook preview must be an absolute path. The Facebook debugger returns an error with a relative path. Thanks for considering this.
If anyone finds this, I solved the above problem with:
<meta content="{{ site.url}}{% asset 'my-image.png' @path %}" property="og:image">
It would be great if something like the following worked...
<meta content="{% asset 'my-image.png' @path | absolute_url %}" property="og:image">
I don't think I'll ever consider | absolute_url
but I'd be happy to look into {% asset img.png @url %}
I don't think I'll ever consider
| absolute_url
but I'd be happy to look into{% asset img.png @url %}
This looks like a cool solution - yes please if you're able!
Thanks for the lib too. Getting to grips with it.