UTF-8 support (#31)
* Create failing test case * Force image filename encoding to UTF-8. Fixes #30
This commit is contained in:
parent
f8c699c6de
commit
756eccc5c3
|
@ -10,12 +10,12 @@ Feature: Extra image generation
|
|||
- width: 100
|
||||
|
||||
extra_images:
|
||||
- assets/test.png
|
||||
- assets/everybody-loves-jalapeño-pineapple-cornbread.png
|
||||
"""
|
||||
|
||||
And I have a file "index.html" with "Hello, world!"
|
||||
When I run Jekyll
|
||||
Then the image "assets/resized/test-100x50.png" should have the dimensions "100x50"
|
||||
Then the image "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should have the dimensions "100x50"
|
||||
|
||||
Scenario: Using glob patterns
|
||||
Given I have a responsive_image configuration with:
|
||||
|
@ -29,7 +29,7 @@ Feature: Extra image generation
|
|||
|
||||
And I have a file "index.html" with "Hello, world!"
|
||||
When I run Jekyll
|
||||
Then the image "assets/resized/test-100x50.png" should have the dimensions "100x50"
|
||||
Then the image "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should have the dimensions "100x50"
|
||||
|
||||
Scenario: No extra images
|
||||
Given I have a responsive_image configuration with:
|
||||
|
@ -40,4 +40,4 @@ Feature: Extra image generation
|
|||
|
||||
And I have a file "index.html" with "Hello, world!"
|
||||
When I run Jekyll
|
||||
Then the file "assets/resized/test-100x50.png" should not exist
|
||||
Then the file "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should not exist
|
||||
|
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
@ -11,9 +11,9 @@ Feature: Responsive image generation
|
|||
- width: 100
|
||||
"""
|
||||
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/test.png alt: Foobar %}"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png alt: Foobar %}"
|
||||
When I run Jekyll
|
||||
Then the image "assets/resized/test-100x50.png" should have the dimensions "100x50"
|
||||
Then the image "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should have the dimensions "100x50"
|
||||
|
||||
Scenario: Handling subdirectories
|
||||
Given I have a responsive_image configuration with:
|
||||
|
@ -26,11 +26,11 @@ Feature: Responsive image generation
|
|||
|
||||
And I have a file "index.html" with:
|
||||
"""
|
||||
{% responsive_image path: assets/test.png %}
|
||||
{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png %}
|
||||
{% responsive_image path: assets/subdir/test.png %}
|
||||
{% responsive_image path: assets/test.png cache: true %}
|
||||
{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png cache: true %}
|
||||
"""
|
||||
|
||||
When I run Jekyll
|
||||
Then the file "assets/resized/test-100.png" should exist
|
||||
Then the file "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100.png" should exist
|
||||
And the file "assets/resized/subdir/test-100.png" should exist
|
||||
|
|
|
@ -7,7 +7,7 @@ Feature: Jekyll responsive_image_block tag
|
|||
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
||||
And I have a file "index.html" with:
|
||||
"""
|
||||
{% assign path = 'assets/test.png' %}
|
||||
{% assign path = 'assets/everybody-loves-jalapeño-pineapple-cornbread.png' %}
|
||||
{% assign alt = 'Lorem ipsum' %}
|
||||
|
||||
{% responsive_image_block %}
|
||||
|
@ -17,13 +17,13 @@ Feature: Jekyll responsive_image_block tag
|
|||
{% endresponsive_image_block %}
|
||||
"""
|
||||
When I run Jekyll
|
||||
Then I should see "<img alt=\"Lorem ipsum\" src=\"/assets/test.png\" title=\"Magic rainbow adventure!\"" in "_site/index.html"
|
||||
Then I should see "<img alt=\"Lorem ipsum\" src=\"/assets/everybody-loves-jalapeño-pineapple-cornbread.png\" title=\"Magic rainbow adventure!\"" in "_site/index.html"
|
||||
|
||||
Scenario: Global variables available in templates
|
||||
Given I have a file "index.html" with:
|
||||
"""
|
||||
{% responsive_image_block %}
|
||||
path: assets/test.png
|
||||
path: assets/everybody-loves-jalapeño-pineapple-cornbread.png
|
||||
{% endresponsive_image_block %}
|
||||
"""
|
||||
And I have a configuration with:
|
||||
|
@ -33,13 +33,13 @@ Feature: Jekyll responsive_image_block tag
|
|||
template: _includes/base-url.html
|
||||
"""
|
||||
When I run Jekyll
|
||||
Then I should see "<img src=\"https://wildlyinaccurate.com/assets/test.png\">" in "_site/index.html"
|
||||
Then I should see "<img src=\"https://wildlyinaccurate.com/assets/everybody-loves-jalapeño-pineapple-cornbread.png\">" in "_site/index.html"
|
||||
|
||||
Scenario: More complex logic in the block tag
|
||||
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
||||
And I have a file "index.html" with:
|
||||
"""
|
||||
{% assign path = 'assets/test.png' %}
|
||||
{% assign path = 'assets/everybody-loves-jalapeño-pineapple-cornbread.png' %}
|
||||
{% assign alt = 'Lorem ipsum' %}
|
||||
|
||||
{% responsive_image_block %}
|
||||
|
@ -53,7 +53,7 @@ Feature: Jekyll responsive_image_block tag
|
|||
{% endresponsive_image_block %}
|
||||
"""
|
||||
When I run Jekyll
|
||||
Then I should see "<img alt=\"Lorem ipsum\" src=\"/assets/test.png\"" in "_site/index.html"
|
||||
Then I should see "<img alt=\"Lorem ipsum\" src=\"/assets/everybody-loves-jalapeño-pineapple-cornbread.png\"" in "_site/index.html"
|
||||
|
||||
Scenario: Handling a nil path
|
||||
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
||||
|
|
|
@ -5,12 +5,12 @@ Feature: Jekyll responsive_image tag
|
|||
|
||||
Scenario: Simple image tag
|
||||
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/test.png alt: Foobar %}"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png alt: Foobar %}"
|
||||
When I run Jekyll
|
||||
Then I should see "<img alt=\"Foobar\" src=\"/assets/test.png\"" in "_site/index.html"
|
||||
Then I should see "<img alt=\"Foobar\" src=\"/assets/everybody-loves-jalapeño-pineapple-cornbread.png\"" in "_site/index.html"
|
||||
|
||||
Scenario: Global variables available in templates
|
||||
Given I have a file "index.html" with "{% responsive_image path: assets/test.png %}"
|
||||
Given I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png %}"
|
||||
And I have a configuration with:
|
||||
"""
|
||||
baseurl: https://wildlyinaccurate.com
|
||||
|
@ -18,22 +18,22 @@ Feature: Jekyll responsive_image tag
|
|||
template: _includes/base-url.html
|
||||
"""
|
||||
When I run Jekyll
|
||||
Then I should see "<img src=\"https://wildlyinaccurate.com/assets/test.png\">" in "_site/index.html"
|
||||
Then I should see "<img src=\"https://wildlyinaccurate.com/assets/everybody-loves-jalapeño-pineapple-cornbread.png\">" in "_site/index.html"
|
||||
|
||||
Scenario: Adding custom attributes
|
||||
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
||||
And I have a file "index.html" with:
|
||||
"""
|
||||
{% responsive_image path: assets/test.png alt: 'Foobar bazbar' title: "Lorem Ipsum" %}
|
||||
{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png alt: 'Foobar bazbar' title: "Lorem Ipsum" %}
|
||||
"""
|
||||
When I run Jekyll
|
||||
Then I should see "<img alt=\"Foobar bazbar\" src=\"/assets/test.png\" title=\"Lorem Ipsum\"" in "_site/index.html"
|
||||
Then I should see "<img alt=\"Foobar bazbar\" src=\"/assets/everybody-loves-jalapeño-pineapple-cornbread.png\" title=\"Lorem Ipsum\"" in "_site/index.html"
|
||||
|
||||
Scenario: UTF-8 attributes
|
||||
Given I have a responsive_image configuration with "template" set to "_includes/responsive-image.html"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/test.png alt: 'かっこいい! ジェケルが好きです!' %}"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png alt: 'かっこいい! ジェケルが好きです!' %}"
|
||||
When I run Jekyll
|
||||
Then I should see "<img alt=\"かっこいい! ジェケルが好きです!\" src=\"/assets/test.png\"" in "_site/index.html"
|
||||
Then I should see "<img alt=\"かっこいい! ジェケルが好きです!\" src=\"/assets/everybody-loves-jalapeño-pineapple-cornbread.png\"" in "_site/index.html"
|
||||
|
||||
Scenario: Image with multiple sizes
|
||||
Given I have a responsive_image configuration with:
|
||||
|
@ -43,14 +43,14 @@ Feature: Jekyll responsive_image tag
|
|||
- width: 100
|
||||
- width: 200
|
||||
"""
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/test.png %}"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png %}"
|
||||
When I run Jekyll
|
||||
Then I should see "<img alt=\"\" src=\"/assets/test.png\"" in "_site/index.html"
|
||||
And I should see "/assets/resized/test-100x50.png 100w" in "_site/index.html"
|
||||
And I should see "/assets/resized/test-200x100.png 200w" in "_site/index.html"
|
||||
And I should see "/assets/test.png 300w" in "_site/index.html"
|
||||
And the file "assets/resized/test-100x50.png" should exist
|
||||
And the file "assets/resized/test-200x100.png" should exist
|
||||
Then I should see "<img alt=\"\" src=\"/assets/everybody-loves-jalapeño-pineapple-cornbread.png\"" in "_site/index.html"
|
||||
And I should see "/assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png 100w" in "_site/index.html"
|
||||
And I should see "/assets/resized/everybody-loves-jalapeño-pineapple-cornbread-200x100.png 200w" in "_site/index.html"
|
||||
And I should see "/assets/everybody-loves-jalapeño-pineapple-cornbread.png 300w" in "_site/index.html"
|
||||
And the file "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-100x50.png" should exist
|
||||
And the file "assets/resized/everybody-loves-jalapeño-pineapple-cornbread-200x100.png" should exist
|
||||
|
||||
Scenario: Overriding the template
|
||||
Given I have a responsive_image configuration with:
|
||||
|
@ -61,7 +61,7 @@ Feature: Jekyll responsive_image tag
|
|||
- width: 200
|
||||
- width: 300
|
||||
"""
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/test.png template: _includes/custom-template.html %}"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png template: _includes/custom-template.html %}"
|
||||
When I run Jekyll
|
||||
Then I should see "[100, 200, 300]" in "_site/index.html"
|
||||
|
||||
|
@ -73,7 +73,7 @@ Feature: Jekyll responsive_image tag
|
|||
sizes:
|
||||
- width: 100
|
||||
"""
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/test.png %}"
|
||||
And I have a file "index.html" with "{% responsive_image path: assets/everybody-loves-jalapeño-pineapple-cornbread.png %}"
|
||||
When I run Jekyll
|
||||
Then I should see "/assets/test.png-resized/100/test-50.png 100w" in "_site/index.html"
|
||||
And the file "assets/test.png-resized/100/test-50.png" should exist
|
||||
Then I should see "/assets/everybody-loves-jalapeño-pineapple-cornbread.png-resized/100/everybody-loves-jalapeño-pineapple-cornbread-50.png 100w" in "_site/index.html"
|
||||
And the file "assets/everybody-loves-jalapeño-pineapple-cornbread.png-resized/100/everybody-loves-jalapeño-pineapple-cornbread-50.png" should exist
|
||||
|
|
|
@ -13,7 +13,8 @@ module Jekyll
|
|||
|
||||
next unless needs_resizing?(img, width)
|
||||
|
||||
filepath = format_output_path(config['output_path_format'], config['base_path'], img.filename, width, height)
|
||||
image_path = img.filename.force_encoding(Encoding::UTF_8)
|
||||
filepath = format_output_path(config['output_path_format'], config['base_path'], image_path, width, height)
|
||||
resized.push(image_hash(config['base_path'], filepath, width, height))
|
||||
|
||||
# Don't resize images more than once
|
||||
|
|
Loading…
Reference in New Issue