Doesn't work while serving
Closed this issue · 4 comments
This is pretty convoluted. I'll try to explain with an example:
{% assign path = "/assets/image.jpg" %}
{% responsive_image_block %}
path: {{ path }}
{% endresponsive_image_block %}
Now: jekyll serve
I kept getting Invalid image path specified
if my path looked like above. I tracked down the problem to image_processor.rb.
I'm not familiar with ruby but I'm guessing:
raise SyntaxError.new("Invalid image path specified: #{image_path}") unless File.file?(absolute_image_path)
is like a try-catch? And it seems to be checking whether the path that I pass into path
is actually a valid file or not.
Of course while serving (as opposed to building), /assets/image.jpg
is not going to be a valid file because the valid file is localhost:4000/assets/image.jpg
So, I need to prove that /assets/image.jpg
is a valid file before the plugin does it's thing without any errors (only after which the serving begins at localhost).. I can do this using absolute path:
{% assign path = "D:/MyWebsite/assets/image.jpg" %}
{% responsive_image_block %}
path: {{ path }}
{% endresponsive_image_block %}
So now the File.file?
check passes through, but when the website is served up it tries to find the image at: `localhost:4000/D:/MyWebsite/assets/image.jpg".
And there's the problem.
I can get around this by tweaking the template file and manually strip out D:/MyWebsite/
:
{% capture srcset %}
{% for i in resized %}
/{{ i.path }} {{ i.width }}w,
{% endfor %}
{% endcapture %}
<img src="{{ path | split: site.url }}" alt="{{ alt }}" srcset="{{ srcset | strip_newlines }} {{ original.path | remove: site.url }} {{ original.width }}w">
Clearly, this precarious workaround is not ideal. I only got it to work locally, not sure what'll happen live.
Any ideas on how to solve this?
Hiya, thanks for the detailed report! Could you confirm that jekyll build
works fine and that the issue only occurs with jekyll serve
? Would you also be able to paste the full error so I can see the path that it's checking?
The File#file
check that you found is to ensure that the asset you want to resize actually exists on disk, and throws a (slightly) more useful error early rather than letting the resize operation blow up. The absolute_image_path
that it is checking should be the asset path prefixed with your Jekyll source directory (usually just the main directory). I have never tested this plugin on Windows, so it's possible that I've managed to write some anti-Windows code.
But anyways if you can confirm the build
vs serve
thing and paste the full error, that'll give me some clues as to what's going on. If that doesn't help I'll boot up a Windows VM and dig around.
Indeed it wasn't a build vs. serve thing, the same exact error pops up in both:
Liquid Exception: Invalid image path specified: \assets\image.jpg\assets\image.jpg in B:/Websites/MyWebsite/_posts/post.md
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-responsive-image-1.1.0/lib/jekyll-responsive-image/image_processor.rb:9:in `process': Invalid image path specified: \assets\image.jpg\assets\image.jpg (SyntaxError)
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-responsive-image-1.1.0/lib/jekyll-responsive-image/image_processor.rb:21:in `process'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-responsive-image-1.1.0/lib/jekyll-responsive-image/renderer.rb:18:in `render_responsive_image'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-responsive-image-1.1.0/lib/jekyll-responsive-image/block.rb:8:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:151:in `render_token'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:5:in `block in render_token_with_profiling'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler.rb:80:in `profile_token_render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:4:in `render_token_with_profiling'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:135:in `block in render_all'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `render_all'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:108:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:210:in `block in render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:262:in `with_profiling'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:209:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:222:in `render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:28:in `block (2 levels) in render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:40:in `measure_bytes'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:27:in `block in render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:47:in `measure_time'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:26:in `render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/tags/include.rb:138:in `block in render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/context.rb:132:in `stack'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/tags/include.rb:136:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:151:in `render_token'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:5:in `block in render_token_with_profiling'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler.rb:80:in `profile_token_render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:4:in `render_token_with_profiling'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:135:in `block in render_all'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:122:in `render_all'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:108:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:210:in `block in render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:262:in `with_profiling'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:209:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/template.rb:222:in `render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:28:in `block (2 levels) in render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:40:in `measure_bytes'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:27:in `block in render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:47:in `measure_time'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/liquid_renderer/file.rb:26:in `render!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/renderer.rb:134:in `render_liquid'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/renderer.rb:82:in `run'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:452:in `block (2 levels) in render_docs'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:450:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:450:in `block in render_docs'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:449:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:449:in `render_docs'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:190:in `render'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/site.rb:69:in `process'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/command.rb:26:in `process_site'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:63:in `build'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:34:in `process'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/hawkins-2.0.5/lib/hawkins/liveserve.rb:52:in `start'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/hawkins-2.0.5/lib/hawkins/liveserve.rb:43:in `block (2 levels) in init_with_program'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/jekyll-3.3.1/exe/jekyll:13:in `<top (required)>'
from C:/Ruby23-x64/bin/jekyll:22:in `load'
from C:/Ruby23-x64/bin/jekyll:22:in `<main>'
(This is when I pass in /assets/image.jpg
as the path
)
It doesn't seem to be picking up the Jekyll source directory at all.
Ah, I didn't notice before — can you try assets/image.jpg
instead of /assets/image.jpg
?
I'm having almost the exact same error:
I use Jekyll page generator to create recipe files and it freaks out with this code below. I'd greatly appreciate any help that you can offer. (Traceback is at the bottom) My repository with the code is datapolitical:chrisfnicholson.github.io
"Invalid image path specified: nil
Liquid Exception: no decode delegate for this image format `' @ error/constitute.c/ReadImage/572 in recipes/olive-oil-apple-cake-with-spiced-sugar.html"
{% capture image_path %}
{{ page.image_url }}
{% endcapture %}
<article class="post">
<div class="image">
{% responsive_image_block %}
path: {{ image_path }}
alt: {{ page.name }}
{% if page.name %}
title: {{ page.name }}
{% endif %}
{% endresponsive_image_block %}
</div>
Yet it works for the directory page (which generates using a for loop to access the data)
{% for i in (0..5) reversed %}
{% for recipe in site.data.recipes %}
{% if recipe.rating == i and recipe.image_url %}
{% for category in recipe.categories %}
{% if category == "Web" %}
<a class="image-container" href="/recipes/{{ recipe.name | downcase | replace: " ", "-" | remove: "(" | remove: ")" | remove: "'" | remove: "&" | remove: "," }}.html">
{% responsive_image_block %}
path: {{recipe.image_url}}
alt: {{ recipe.name }}
{% if recipe.name %}
title: {{ recipe.name }}
{% endif %}
{% endresponsive_image_block %}
<!-- <img class="photo-large lazysizes" data-src="{{ recipe.image_url | default: "" }}"> -->
<div class="bottom-left"><b><h3 class="text-hover">{{ recipe.name }}</h3></b></div>
</a>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
Here's the trace
Jekyll Feed: Generating feed for posts
Invalid image path specified: nil
Liquid Exception: no decode delegate for this image format `' @ error/constitute.c/ReadImage/572 in recipes/olive-oil-apple-cake-with-spiced-sugar.html
jekyll 3.9.0 | Error: no decode delegate for this image format `' @ error/constitute.c/ReadImage/572
Traceback (most recent call last):
41: from /Users/chris/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
40: from /Users/chris/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
39: from /Users/chris/.rvm/gems/ruby-2.7.0/bin/jekyll:23:in `<main>'
38: from /Users/chris/.rvm/gems/ruby-2.7.0/bin/jekyll:23:in `load'
37: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/exe/jekyll:15:in `<top (required)>'
36: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
35: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
34: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
33: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
32: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
31: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:75:in `block (2 levels) in init_with_program'
30: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:93:in `start'
29: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:93:in `each'
28: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:93:in `block in start'
27: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:36:in `process'
26: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/commands/build.rb:65:in `build'
25: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/command.rb:28:in `process_site'
24: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/site.rb:71:in `process'
23: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/site.rb:192:in `render'
22: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/site.rb:471:in `render_pages'
21: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/site.rb:471:in `each'
20: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/site.rb:472:in `block in render_pages'
19: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/site.rb:479:in `render_regenerated'
18: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/renderer.rb:62:in `run'
17: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/renderer.rb:79:in `render_document'
16: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/renderer.rb:126:in `render_liquid'
15: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
14: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
13: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
12: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
11: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-3.9.0/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
10: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:220:in `render!'
9: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:207:in `render'
8: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:242:in `with_profiling'
7: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/liquid-4.0.3/lib/liquid/template.rb:208:in `block in render'
6: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:82:in `render'
5: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:103:in `render_node_to_output'
4: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-responsive-image-1.5.5/lib/jekyll-responsive-image/block.rb:14:in `render'
3: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-responsive-image-1.5.5/lib/jekyll-responsive-image/renderer.rb:18:in `render_responsive_image'
2: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-responsive-image-1.5.5/lib/jekyll-responsive-image/image_processor.rb:21:in `process'
1: from /Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-responsive-image-1.5.5/lib/jekyll-responsive-image/image_processor.rb:12:in `process'
/Users/chris/.rvm/gems/ruby-2.7.0/gems/jekyll-responsive-image-1.5.5/lib/jekyll-responsive-image/image_processor.rb:12:in `read': no decode delegate for this image format `' @ error/constitute.c/ReadImage/572 (Magick::ImageMagickError)