jekyll_picture_tag 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +5 -1
- data/jekyll-picture-tag.gemspec +44 -0
- data/jekyll_picture_tag.gemspec +9 -8
- data/lib/jekyll-picture-tag.rb +23 -0
- data/lib/jekyll_picture_tag/defaults/global.yml +1 -0
- data/lib/jekyll_picture_tag/generated_image.rb +6 -16
- data/lib/jekyll_picture_tag/instructions/configuration.rb +42 -7
- data/lib/jekyll_picture_tag/instructions/html_attributes.rb +1 -1
- data/lib/jekyll_picture_tag/output_formats.rb +1 -0
- data/lib/jekyll_picture_tag/output_formats/basics.rb +1 -0
- data/lib/jekyll_picture_tag/output_formats/naked_srcset.rb +12 -0
- data/lib/jekyll_picture_tag/output_formats/readme.md +48 -0
- data/lib/jekyll_picture_tag/srcsets/basics.rb +2 -12
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +68 -654
- metadata +29 -13
- data/migration.md +0 -178
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92f25151354c1e1d62aa3b9097316538012dfa84bcd91bad49af2349adc25b12
|
4
|
+
data.tar.gz: b80c014044abfb092c8949faf674281d57f130384ca2c37b0b17715a445048eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b16a09afffe03178211c01840eb3767f0fc7c21b597f1148dff9d6f35fedefa6830288b23c63bd28bc75a67683ad3d8d633c2c3ce44af2c5916f7cee16722685
|
7
|
+
data.tar.gz: 45875378703e55d08f11f1d0a102fdfe9cae09c75a6aae8edd16d83277b8cccb4d72e3307c02a592a66481a7f39f5e8f3c078e97dbf57013dbc1d968d64a40e3
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'jekyll_picture_tag/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'jekyll-picture-tag'
|
7
|
+
spec.version = PictureTag::VERSION
|
8
|
+
spec.authors = ['Robert Wierzbowski', 'Brendan Tobolaski',
|
9
|
+
'Robert Buchberger']
|
10
|
+
spec.email = ['robert@buchberger.cc']
|
11
|
+
|
12
|
+
spec.summary = 'Easy responsive images for Jekyll.'
|
13
|
+
spec.description = <<~HEREDOC
|
14
|
+
____ _ _
|
15
|
+
| _ \ ___ _ __ _ __ ___ ___ __ _| |_ ___ __| |
|
16
|
+
| | | |/ _ \ '_ \| '__/ _ \/ __/ _` | __/ _ \/ _` |
|
17
|
+
| |_| | __/ |_) | | | __/ (_| (_| | || __/ (_| |
|
18
|
+
|____/ \___| .__/|_| \___|\___\__,_|\__\___|\__,_|
|
19
|
+
|_|
|
20
|
+
|
21
|
+
This gem has been renamed! Use jekyll_picture_tag instead, which is now
|
22
|
+
hosted on rubygems.
|
23
|
+
HEREDOC
|
24
|
+
spec.homepage = 'https://github.com/rbuchberger/jekyll-picture-tag'
|
25
|
+
spec.license = 'BSD-3-Clause'
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
f.match(%r{^(test|spec|features)/})
|
30
|
+
end
|
31
|
+
|
32
|
+
spec.required_ruby_version = ['>= 2.5', '< 3']
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'pry'
|
36
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
37
|
+
|
38
|
+
spec.add_dependency 'fastimage', '~> 2'
|
39
|
+
spec.add_dependency 'mime-types', '~> 3'
|
40
|
+
spec.add_dependency 'mini_magick', '~> 4'
|
41
|
+
spec.add_dependency 'objective_elements', '~> 1.1'
|
42
|
+
|
43
|
+
spec.add_runtime_dependency 'jekyll', '< 5'
|
44
|
+
end
|
data/jekyll_picture_tag.gemspec
CHANGED
@@ -7,17 +7,17 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = PictureTag::VERSION
|
8
8
|
spec.authors = ['Robert Wierzbowski', 'Brendan Tobolaski',
|
9
9
|
'Robert Buchberger']
|
10
|
-
spec.email = ['
|
11
|
-
'robert@buchberger.cc']
|
10
|
+
spec.email = ['robert@buchberger.cc']
|
12
11
|
|
13
12
|
spec.summary = 'Easy responsive images for Jekyll.'
|
14
13
|
spec.description = <<-HEREDOC
|
15
|
-
Jekyll Picture Tag is a liquid tag that adds responsive images to your
|
16
|
-
|
17
|
-
|
18
|
-
with a little YAML configuration and a
|
14
|
+
Jekyll Picture Tag is a liquid tag that adds responsive images to your
|
15
|
+
Jekyll static site.Jekyll Picture Tag automatically creates resized source
|
16
|
+
images, is fully configurable, and covers all use cases — including art
|
17
|
+
direction and resolution switching — with a little YAML configuration and a
|
18
|
+
simple template tag.
|
19
19
|
HEREDOC
|
20
|
-
spec.homepage = 'https://github.com/
|
20
|
+
spec.homepage = 'https://github.com/rbuchberger/jekyll-picture-tag'
|
21
21
|
spec.license = 'BSD-3-Clause'
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
@@ -32,8 +32,9 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'rake', '~> 12.3'
|
33
33
|
|
34
34
|
spec.add_dependency 'fastimage', '~> 2'
|
35
|
+
spec.add_dependency 'mime-types', '~> 3'
|
35
36
|
spec.add_dependency 'mini_magick', '~> 4'
|
36
37
|
spec.add_dependency 'objective_elements', '~> 1.1'
|
37
38
|
|
38
|
-
spec.add_runtime_dependency 'jekyll', '<
|
39
|
+
spec.add_runtime_dependency 'jekyll', '< 5'
|
39
40
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
puts '-' * 80
|
2
|
+
|
3
|
+
puts <<~HEREDOC
|
4
|
+
\033[31;1;4m
|
5
|
+
Important message from Jekyll Picture Tag:
|
6
|
+
\033[0m
|
7
|
+
Good news! We're back up on rubygems.
|
8
|
+
Bad news. You need to update your Gemfile. Remove the following line:
|
9
|
+
|
10
|
+
gem 'jekyll-picture-tag', git: 'https://github.com/robwierzbowski/jekyll-picture-tag/'
|
11
|
+
|
12
|
+
and replace it with:
|
13
|
+
|
14
|
+
gem 'jekyll_picture_tag', '~> 1.3'
|
15
|
+
|
16
|
+
Sorry about that. For an explanation, see issue #120:
|
17
|
+
https://github.com/rbuchberger/jekyll-picture-tag/issues/120
|
18
|
+
|
19
|
+
HEREDOC
|
20
|
+
|
21
|
+
puts '-' * 80
|
22
|
+
|
23
|
+
require_relative 'jekyll_picture_tag'
|
@@ -6,16 +6,15 @@ class GeneratedImage
|
|
6
6
|
|
7
7
|
def initialize(source_file:, width:, format:)
|
8
8
|
@source = source_file
|
9
|
+
@width = width
|
9
10
|
@format = format
|
10
11
|
|
11
|
-
@size = build_size(width)
|
12
|
-
|
13
12
|
generate_image unless File.exist? absolute_filename
|
14
13
|
end
|
15
14
|
|
16
15
|
def name
|
17
16
|
name = @source.base_name
|
18
|
-
name << "-#{@
|
17
|
+
name << "-#{@width}-"
|
19
18
|
name << @source.digest
|
20
19
|
name << '.' + @format
|
21
20
|
end
|
@@ -25,28 +24,17 @@ class GeneratedImage
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def width
|
28
|
-
@
|
27
|
+
@width
|
29
28
|
end
|
30
29
|
|
31
30
|
private
|
32
31
|
|
33
|
-
def build_size(width)
|
34
|
-
if width < @source.width
|
35
|
-
{
|
36
|
-
width: width,
|
37
|
-
height: (width / @source.aspect_ratio).round
|
38
|
-
}
|
39
|
-
else
|
40
|
-
@source.size
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
32
|
def generate_image
|
45
33
|
puts 'Generating new image file: ' + name
|
46
34
|
image = MiniMagick::Image.open(@source.name)
|
47
35
|
# Scale and crop
|
48
36
|
image.combine_options do |i|
|
49
|
-
i.resize "#{@
|
37
|
+
i.resize "#{@width}x"
|
50
38
|
i.auto_orient
|
51
39
|
i.strip
|
52
40
|
end
|
@@ -56,6 +44,8 @@ class GeneratedImage
|
|
56
44
|
check_dest_dir
|
57
45
|
|
58
46
|
image.write absolute_filename
|
47
|
+
|
48
|
+
FileUtils.chmod(0644, absolute_filename)
|
59
49
|
end
|
60
50
|
|
61
51
|
# Make sure destination directory exists
|
@@ -11,6 +11,13 @@ module PictureTag
|
|
11
11
|
@content[key]
|
12
12
|
end
|
13
13
|
|
14
|
+
# Digs into jekyll context, returns current environment
|
15
|
+
def jekyll_env
|
16
|
+
# It would be really great if the jekyll devs actually documented
|
17
|
+
# the context object.
|
18
|
+
PictureTag.context.environments.first['jekyll']['environment']
|
19
|
+
end
|
20
|
+
|
14
21
|
# Site.source is the master jekyll source directory
|
15
22
|
# Source dir is the jekyll-picture-tag source directory.
|
16
23
|
def source_dir
|
@@ -24,12 +31,18 @@ module PictureTag
|
|
24
31
|
File.join PictureTag.site.dest, self['picture']['output']
|
25
32
|
end
|
26
33
|
|
27
|
-
#
|
34
|
+
# Generated images, not source images.
|
35
|
+
# https://example.com/my-base-path/assets/generated-images/image.jpg
|
36
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
37
|
+
# | domain | baseurl | j-p-t output dir | filename
|
28
38
|
def build_url(filename)
|
29
39
|
File.join url_prefix, self['picture']['output'], filename
|
30
40
|
end
|
31
41
|
|
32
42
|
# For linking source images
|
43
|
+
# https://example.com/my-base-path/assets/source-images/image.jpg
|
44
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
45
|
+
# | domain | baseurl | j-p-t source dir | filename
|
33
46
|
def build_source_url(filename)
|
34
47
|
File.join url_prefix, self['picture']['source'], filename
|
35
48
|
end
|
@@ -68,15 +81,37 @@ module PictureTag
|
|
68
81
|
end
|
69
82
|
end
|
70
83
|
|
84
|
+
# Juuust complicated enough to extract to its own function.
|
85
|
+
def cdn?
|
86
|
+
self['picture']['cdn_url'] &&
|
87
|
+
self['picture']['cdn_environments'].include?( jekyll_env )
|
88
|
+
end
|
89
|
+
|
90
|
+
# https://example.com/my-base-path/assets/generated-images/image.jpg
|
91
|
+
# ^^^^^^^^^^^^^^^^^^^^
|
92
|
+
# | domain | baseurl | j-p-t output dir | filename
|
93
|
+
def domain
|
94
|
+
if cdn?
|
95
|
+
self['picture']['cdn_url']
|
96
|
+
elsif self['picture']['relative_url']
|
97
|
+
''
|
98
|
+
else
|
99
|
+
self['url']
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
71
103
|
# https://example.com/my-base-path/assets/generated-images/image.jpg
|
72
|
-
#
|
73
|
-
# |
|
104
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
105
|
+
# | domain | baseurl | j-p-t output dir | filename
|
74
106
|
def url_prefix
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
107
|
+
# We use file.join because the ruby url methods don't like relative
|
108
|
+
# urls.
|
109
|
+
File.join(
|
110
|
+
domain,
|
111
|
+
self['baseurl'],
|
112
|
+
)
|
79
113
|
end
|
114
|
+
|
80
115
|
end
|
81
116
|
end
|
82
117
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Writing Output Formats
|
2
|
+
|
3
|
+
|
4
|
+
## Naming and Instantiating
|
5
|
+
|
6
|
+
Names from the configuration wiAn output format is instantiated will be
|
7
|
+
converted from snake case to title case (I'm not sure what it's called.) And
|
8
|
+
instantiated.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
|
12
|
+
In `_data/picture.yml`: `markup: example_format` will cause the plugin to use
|
13
|
+
an instance of `ExampleFormat` (with no arguments.)
|
14
|
+
|
15
|
+
You'll need to add an appropriate `require_relative` statement to
|
16
|
+
`../output_formats.rb`
|
17
|
+
|
18
|
+
## Input
|
19
|
+
|
20
|
+
When instantiated, your new class doesn't get any arguments. You can find
|
21
|
+
information by calling class methods on PictureTag. I'm no computer scientist,
|
22
|
+
so if this is a terrible way to do things I'd love to hear all about it. I did
|
23
|
+
it this way because information flow was getting arduous; I was passing a lot
|
24
|
+
of information to classes which only needed it to pass on to classes they
|
25
|
+
instantiate.
|
26
|
+
|
27
|
+
`PictureTag.source_images` returns a hash of the source images provided in the
|
28
|
+
liquid tag. This relies on 2 properties of ruby hashes: They maintain their
|
29
|
+
order, and `nil` is a perfectly good key. The first image (unqualified) is
|
30
|
+
stored under `PictureTag.source_images[nil]`, and the rest of the keys are
|
31
|
+
media queries named in `_data/picture.yml`.
|
32
|
+
|
33
|
+
There's a lot of information available, dig around in `../instructions.rb`. Output formats should only consume this information, never modify it.
|
34
|
+
|
35
|
+
## Producing output
|
36
|
+
|
37
|
+
The instance of your new class should implement the `to_s` method, which
|
38
|
+
returns the desired markup. In the course of generating this markup, it should
|
39
|
+
also ensure that the necessary images are generated as well.
|
40
|
+
|
41
|
+
When you generate one of the srcsets prodvided under `../srcsets/`, it will
|
42
|
+
both provide an appropriate html attribute (only the part inside the quotes)
|
43
|
+
and generate the respective images.
|
44
|
+
|
45
|
+
## Basics module
|
46
|
+
|
47
|
+
`basics.rb` is a module which includes a few methods to do things common to
|
48
|
+
most/all output formats.
|
@@ -9,6 +9,7 @@ module PictureTag
|
|
9
9
|
# pixels.
|
10
10
|
module Basics
|
11
11
|
require 'fastimage'
|
12
|
+
require 'mime-types'
|
12
13
|
attr_reader :media, :source_image
|
13
14
|
|
14
15
|
def initialize(media:, format:)
|
@@ -27,7 +28,7 @@ module PictureTag
|
|
27
28
|
# Allows us to add a type attribute to whichever element contains this
|
28
29
|
# srcset.
|
29
30
|
def mime_type
|
30
|
-
|
31
|
+
MIME::Types.type_for(@format).first.to_s
|
31
32
|
end
|
32
33
|
|
33
34
|
# Some srcsets have them, for those that don't return nil.
|
@@ -72,17 +73,6 @@ module PictureTag
|
|
72
73
|
)
|
73
74
|
end
|
74
75
|
|
75
|
-
# Hardcoding these isn't ideal, but I'm not pulling in a new dependency
|
76
|
-
# for 9 lines of easy code.
|
77
|
-
def mime_types
|
78
|
-
{
|
79
|
-
'gif' => 'image/gif',
|
80
|
-
'jpg' => 'image/jpeg',
|
81
|
-
'jpeg' => 'image/jpeg',
|
82
|
-
'png' => 'image/png',
|
83
|
-
'webp' => 'image/webp'
|
84
|
-
}
|
85
|
-
end
|
86
76
|
end
|
87
77
|
end
|
88
78
|
end
|
data/readme.md
CHANGED
@@ -10,7 +10,7 @@ Jekyll Picture Tag is a liquid tag that adds responsive images to your
|
|
10
10
|
reformatted source images, is fully configurable, implements sensible defaults,
|
11
11
|
and solves both the art direction and resolution switching problems, with a
|
12
12
|
little YAML configuration and a simple template tag. It can be configured to
|
13
|
-
work with JavaScript libraries such as
|
13
|
+
work with JavaScript libraries such as
|
14
14
|
[LazyLoad](https://github.com/verlok/lazyload).
|
15
15
|
|
16
16
|
## Why use Jekyll Picture Tag?
|
@@ -23,7 +23,7 @@ want to do more than just resize images for different screen sizes.
|
|
23
23
|
|
24
24
|
**Developer Sanity:** Image downloading starts before the browser has parsed your CSS and
|
25
25
|
JavaScript; this gets them on the page *fast*, but it leads to some ridiculously verbose markup.
|
26
|
-
Ultimately, to serve responsive images correctly, we must:
|
26
|
+
Ultimately, to serve responsive images correctly, we must:
|
27
27
|
|
28
28
|
- Generate, name, and organize the required images (formats \* resolutions, for each source image)
|
29
29
|
- Inform the browser about the image itself-- format, size, URI, and the screen sizes where it
|
@@ -48,22 +48,16 @@ It's a lot. It's tedious and complicated. Jekyll Picture Tag automates it.
|
|
48
48
|
* Optionally, automatically link to the source image. Or manually link to anywhere else, with just a
|
49
49
|
tag parameter!
|
50
50
|
|
51
|
-
# Required Knowledge
|
52
51
|
|
53
|
-
|
54
|
-
guide](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).
|
55
|
-
If you don't know the difference between resolution switching and art direction, stop now and read it
|
56
|
-
in detail. Ideally, play around with a basic HTML file, a few test images, and a few different
|
57
|
-
browser widths until you understand it.
|
52
|
+
# Documentation
|
58
53
|
|
59
|
-
|
54
|
+
It's mostly in the wiki.
|
60
55
|
|
61
|
-
* [Installation](
|
62
|
-
* [Usage](
|
63
|
-
* [
|
64
|
-
|
65
|
-
|
66
|
-
* [Other notes](#miscellaneous-tidbits)
|
56
|
+
* [Installation](https://github.com/rbuchberger/jekyll-picture-tag/wiki/Installation)
|
57
|
+
* [Usage](https://github.com/rbuchberger/jekyll-picture-tag/wiki/Liquid-Tag-Usage)
|
58
|
+
* [Global settings](https://github.com/rbuchberger/jekyll-picture-tag/wiki/Global-Configuration)
|
59
|
+
* [Presets](https://github.com/rbuchberger/jekyll-picture-tag/wiki/Writing-Presets)
|
60
|
+
* [Other notes](https://github.com/rbuchberger/jekyll-picture-tag/wiki/Miscellaneous-notes-and-FAQ)
|
67
61
|
* [Contribute](#contribute)
|
68
62
|
* [Release History](#release-history)
|
69
63
|
* [License](#license)
|
@@ -72,33 +66,31 @@ browser widths until you understand it.
|
|
72
66
|
|
73
67
|
**All configuration is optional.** Here's the simplest possible use case:
|
74
68
|
|
75
|
-
Add
|
69
|
+
Add j_p_t to your gemfile:
|
76
70
|
|
77
71
|
```ruby
|
78
|
-
group :jekyll_plugins do
|
79
|
-
gem '
|
80
|
-
end
|
72
|
+
group :jekyll_plugins do
|
73
|
+
gem 'jekyll_picture_tag'
|
74
|
+
end
|
81
75
|
```
|
82
76
|
|
83
|
-
|
77
|
+
Put this liquid tag somewhere:
|
84
78
|
|
85
79
|
`{% picture test.jpg %}`
|
86
80
|
|
87
|
-
Get this:
|
81
|
+
Get this in your generated site:
|
88
82
|
|
89
83
|
```html
|
90
84
|
<!-- Line breaks added for readability, the actual markup will not have them. -->
|
91
|
-
|
92
|
-
|
93
|
-
srcset="
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
http://localhost:4000/generated/test-1000by563-195f7d.jpg 1000w"
|
98
|
-
>
|
85
|
+
|
86
|
+
<img src="/generated/test-800-195f7d.jpg"
|
87
|
+
srcset="/generated/test-400-195f7d.jpg 400w,
|
88
|
+
/generated/test-600-195f7d.jpg 600w,
|
89
|
+
/generated/test-800-195f7d.jpg 800w,
|
90
|
+
/generated/test-1000-195f7d.jpg 1000w">
|
99
91
|
```
|
100
92
|
|
101
|
-
|
93
|
+
### Here's a more complete example:
|
102
94
|
|
103
95
|
With this configuration:
|
104
96
|
|
@@ -113,7 +105,7 @@ markup_presets:
|
|
113
105
|
default:
|
114
106
|
widths: [600, 900, 1200]
|
115
107
|
formats: [webp, original]
|
116
|
-
sizes:
|
108
|
+
sizes:
|
117
109
|
mobile: 80vw
|
118
110
|
size: 500px
|
119
111
|
|
@@ -126,657 +118,79 @@ Write this:
|
|
126
118
|
Get this:
|
127
119
|
|
128
120
|
```html
|
129
|
-
|
130
121
|
<!-- Formatted for readability -->
|
122
|
+
|
131
123
|
<picture>
|
132
|
-
<source
|
133
|
-
sizes="(max-width: 600px) 80vw,
|
124
|
+
<source
|
125
|
+
sizes="(max-width: 600px) 80vw, 600px"
|
134
126
|
media="(max-width: 600px)"
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
srcset="
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
127
|
+
srcset="
|
128
|
+
/generated/test2-600-21bb6f.webp 600w,
|
129
|
+
/generated/test2-900-21bb6f.webp 900w,
|
130
|
+
/generated/test2-1200-21bb6f.webp 1200w
|
131
|
+
"
|
132
|
+
type="image/webp">
|
133
|
+
<source
|
134
|
+
sizes="(max-width: 600px) 80vw, 600px"
|
135
|
+
srcset="
|
136
|
+
/generated/test-600-195f7d.webp 600w,
|
137
|
+
/generated/test-900-195f7d.webp 900w,
|
138
|
+
/generated/test-1200-195f7d.webp 1200w
|
139
|
+
"
|
140
|
+
type="image/webp">
|
141
|
+
<source
|
142
|
+
sizes="(max-width: 600px) 80vw, 600px"
|
149
143
|
media="(max-width: 600px)"
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
srcset="
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
144
|
+
srcset="
|
145
|
+
/generated/test2-600-21bb6f.jpg 600w,
|
146
|
+
/generated/test2-900-21bb6f.jpg 900w,
|
147
|
+
/generated/test2-1200-21bb6f.jpg 1200w
|
148
|
+
"
|
149
|
+
type="image/jpeg">
|
150
|
+
<source
|
151
|
+
sizes="(max-width: 600px) 80vw, 600px"
|
152
|
+
srcset="
|
153
|
+
/generated/test-600-195f7d.jpg 600w,
|
154
|
+
/generated/test-900-195f7d.jpg 900w,
|
155
|
+
/generated/test-1200-195f7d.jpg 1200w
|
156
|
+
"
|
157
|
+
type="image/jpeg">
|
158
|
+
<img src="/generated/test-800-195f7d.jpg" alt="Alternate Text">
|
165
159
|
</picture>
|
166
160
|
```
|
167
161
|
|
168
|
-
# Installation
|
169
|
-
|
170
|
-
Add `jekyll-picture-tag` to your Gemfile in the `:jekyll_plugins` group.
|
171
|
-
For now I don't have push access to RubyGems, meaning you have to point your gemfile at this git repo.
|
172
|
-
If you don't you'll get an old, incompatible version.
|
173
|
-
|
174
|
-
```ruby
|
175
|
-
group :jekyll_plugins do
|
176
|
-
gem 'jekyll-picture-tag', git: 'https://github.com/robwierzbowski/jekyll-picture-tag/'
|
177
|
-
end
|
178
|
-
```
|
179
|
-
|
180
|
-
### ImageMagick
|
181
|
-
|
182
162
|
Jekyll Picture Tag ultimately relies on [ImageMagick](https://www.imagemagick.org/script/index.php)
|
183
163
|
for image conversions, so it must be installed on your system. There's a very good chance you
|
184
164
|
already have it. If you want to build webp images, you will need to install a webp delegate for it
|
185
165
|
as well.
|
186
166
|
|
187
|
-
Verify it's installed by entering the following into a terminal:
|
188
|
-
|
189
|
-
$ convert --version
|
190
|
-
|
191
|
-
You should see something like this:
|
192
|
-
|
193
|
-
chronos@localhost ~ $ convert --version
|
194
|
-
Version: ImageMagick 7.0.8-14 Q16 x86_64 2018-10-31 https://imagemagick.org
|
195
|
-
Copyright: © 1999-2018 ImageMagick Studio LLC
|
196
|
-
License: https://imagemagick.org/script/license.php
|
197
|
-
Features: Cipher DPC HDRI OpenMP
|
198
|
-
Delegates (built-in): bzlib fontconfig freetype jng jp2 jpeg lcms lzma pangocairo png tiff webp xml zlib
|
199
|
-
|
200
|
-
Note webp under delegates. This is required if you want to generate webp files.
|
201
|
-
|
202
|
-
If you get a 'command not found' error, you'll need to install it. Most Linux package managers
|
203
|
-
include it, otherwise it can be downloaded [here](https://imagemagick.org/script/download.php)
|
204
|
-
|
205
|
-
# Usage
|
206
|
-
|
207
|
-
The tag takes a mix of user input and pointers to configuration settings:
|
208
|
-
|
209
|
-
`{% picture [preset] (source image) [alternate images] [attributes] %}`
|
210
|
-
|
211
|
-
Note the tag parser separates arguments by looking for some whitespace followed by `'--'`. If you
|
212
|
-
need to set HTML attribute values which begin with `'--'`, either set them first
|
213
|
-
(`class="--my-class"`) or using `_data/picture.yml` settings. `class="some-class
|
214
|
-
--some-other-class"` will break things.
|
215
|
-
|
216
|
-
* **Preset**
|
217
|
-
|
218
|
-
*Format:* `(name of a markup preset described in _data/picture.yml)`
|
219
|
-
|
220
|
-
*Default:* `default`
|
221
|
-
|
222
|
-
Optionally specify a markup [preset](#markup-presets) to use, or leave blank for the `default` preset.
|
223
|
-
|
224
|
-
* **Source Image** (Required)
|
225
|
-
|
226
|
-
*Format:* `(Image filename, relative to source setting in _config.yml)`
|
227
|
-
|
228
|
-
The base image that will be resized for your picture sources. Can be a jpeg, png, webp, or gif.
|
229
|
-
|
230
|
-
* **Alternate images**
|
231
|
-
|
232
|
-
*Format:* `(media query preset): (image filename, relative to source directory)`
|
233
|
-
|
234
|
-
*Example:* `tablet: img_cropped.jpg mobile: img_cropped_more.jpg`
|
235
|
-
|
236
|
-
Optionally specify any number of alternate base images for given [media queries](#media-presets)
|
237
|
-
(specified in `_data/picture.yml`). This is one of of picture's strongest features, often referred
|
238
|
-
to as the [art direction use case](http://usecases.responsiveimages.org/#art-direction).
|
239
|
-
|
240
|
-
Give your images in order of ascending specificity (The first image is the most general). They will
|
241
|
-
be provided to the browser in reverse order, and it will select the first one with a media query
|
242
|
-
that evaluates true.
|
243
|
-
|
244
|
-
* **Attributes**
|
245
|
-
|
246
|
-
Optionally specify any number of HTML attributes. These will be added to any attributes you've
|
247
|
-
set in a preset. They can take a few different formats:
|
248
|
-
|
249
|
-
##### `--link`
|
250
|
-
|
251
|
-
*Format:* `--link (some url)`
|
252
|
-
|
253
|
-
*Examples*: `--link https://example.com`, `--link /blog/some_post/`
|
254
|
-
|
255
|
-
Wrap the image in an anchor tag, with the `href` attribute set to whatever value you give it.
|
256
|
-
This will override automatic source image linking, if you have enabled it.
|
257
|
-
|
258
|
-
**Note**: Don't disable the `nomarkdown` global setting if you would like do this within markdown
|
259
|
-
files and you are using Kramdown (Jekyll's default markdown parser.)
|
260
|
-
|
261
|
-
##### `--(element)`
|
262
|
-
|
263
|
-
*Format:* `--(picture|img|source|a|parent|alt) (Whatever HTML attributes you want)`
|
264
|
-
|
265
|
-
*Example:* `--img class="awesome-fade-in" id="coolio" --a data-awesomeness="11"`
|
266
|
-
|
267
|
-
Apply attributes to a given HTML element. Your options are:
|
268
|
-
|
269
|
-
* `picture`
|
270
|
-
* `img`
|
271
|
-
* `source`
|
272
|
-
* `a` (anchor tag)
|
273
|
-
* `parent`
|
274
|
-
* `alt`
|
275
|
-
|
276
|
-
`--parent` will be applied to the `<picture>` if present, otherwise the `<img>`; useful when using
|
277
|
-
the `auto` output format.
|
278
|
-
|
279
|
-
`--alt` is a shortcut for `--img alt="..."`
|
280
|
-
*Example:* `--alt Here is my alt text!`
|
281
|
-
|
282
|
-
##### Old syntax
|
283
|
-
|
284
|
-
The old syntax is to just dump all attributes at the end:
|
285
|
-
|
286
|
-
`{% picture example.jpg alt="alt text" class="super-duper" %}`
|
287
|
-
|
288
|
-
This will continue to work. For backwards compatibility, behavior of previous versions is
|
289
|
-
maintained: all attributes specified this way are applied to the img tag.
|
290
|
-
|
291
|
-
#### Line breaks
|
292
|
-
Line breaks and spaces are interchangeable, the following is perfectly acceptable:
|
293
|
-
|
294
|
-
```
|
295
|
-
{%
|
296
|
-
picture my-preset
|
297
|
-
img.jpg
|
298
|
-
mobile: alt.jpg
|
299
|
-
--alt Alt Text
|
300
|
-
--picture class="stumpy"
|
301
|
-
%}
|
302
|
-
```
|
303
|
-
#### Liquid variables
|
304
|
-
|
305
|
-
You can use liquid variables in a picture tag:
|
306
|
-
|
307
|
-
`html {% picture {{ post.featured_image }} --alt Our Project %}`
|
308
|
-
|
309
|
-
# Configuration
|
310
|
-
|
311
|
-
**All configuration is optional**. If you are happy with the defaults, you don't have to touch a
|
312
|
-
single yaml file.
|
313
|
-
|
314
|
-
## Global Configuration
|
315
|
-
|
316
|
-
Global settings are stored under the `picture:` key in `/_config.yml`.
|
317
|
-
|
318
|
-
**Example config:**
|
319
|
-
|
320
|
-
```yml
|
321
|
-
picture:
|
322
|
-
source: "assets/images/fullsize"
|
323
|
-
output: "assets/images/generated"
|
324
|
-
```
|
325
|
-
|
326
|
-
* **Source Image Directory**
|
327
|
-
|
328
|
-
*Format:* `source: (directory)`
|
329
|
-
|
330
|
-
*Example:* `source: images/`
|
331
|
-
|
332
|
-
*Default:* Jekyll site root.
|
333
|
-
|
334
|
-
To make writing tags easier you can specify a source directory for your assets. Base images in the
|
335
|
-
tag will be relative to the `source` directory, which is relative to the Jekyll site root.
|
336
|
-
|
337
|
-
For example, if `source` is set to `assets/images/_fullsize`, the tag
|
338
|
-
`{% picture enishte/portrait.jpg --alt An unsual picture %}` will look for a file at
|
339
|
-
`assets/images/_fullsize/enishte/portrait.jpg`.
|
340
|
-
|
341
|
-
* **Destination Image Directory**
|
342
|
-
|
343
|
-
*Format:* `output: (directory)`
|
344
|
-
|
345
|
-
*Example:* `output: resized_images/`
|
346
|
-
|
347
|
-
*Default*: `generated/`
|
348
|
-
|
349
|
-
Jekyll Picture Tag saves resized, reformatted images to the `output` directory in your compiled
|
350
|
-
site. The organization of your `source` directory is maintained.
|
351
|
-
|
352
|
-
This setting is relative to your compiled site, which means `_site` unless you've changed it.
|
353
|
-
|
354
|
-
* **Suppress Warnings**
|
355
|
-
|
356
|
-
*Format:* `suppress_warnings: (true|false)`
|
357
|
-
|
358
|
-
*Example:* `suppress_warnings: true`
|
359
|
-
|
360
|
-
*Default*: `false`
|
361
|
-
|
362
|
-
Jekyll Picture Tag will warn you in a few different scenarios, such as when your base image is
|
363
|
-
smaller than one of the sizes in your preset. (Note that Jekyll Picture Tag will never resize an
|
364
|
-
image to be larger than its source). Set this value to `true`, and these warnings will not be shown.
|
365
|
-
|
366
|
-
* **Use Relative Urls**
|
367
|
-
|
368
|
-
*Format:* `relative_url: (true|false)`
|
369
|
-
|
370
|
-
*Example:* `relative_url: false`
|
371
|
-
|
372
|
-
*Default*: `true`
|
373
|
-
|
374
|
-
Whether to use relative (`/generated/test(...).jpg`) or absolute
|
375
|
-
(`https://example.com/generated/test(...).jpg`) urls in your src and srcset attributes.
|
376
|
-
|
377
|
-
* **Kramdown nomarkdown fix**
|
378
|
-
|
379
|
-
*Format:* `nomarkdown: (true|false)`
|
380
|
-
|
381
|
-
*Example:* `nomarkdown: false`
|
382
|
-
|
383
|
-
*Default*: `true`
|
384
|
-
|
385
|
-
Whether or not to surround j-p-t's output with a `{::nomarkdown}..{:/nomarkdown}` block when called
|
386
|
-
from within a markdown file. This one requires some explanation, but you can probably just leave
|
387
|
-
it enabled.
|
388
|
-
|
389
|
-
Under certain circumstances, Kramdown (Jekyll's default markdown parser) will get confused by HTML
|
390
|
-
and will subsequently butcher it. One instance is when you wrap a block level element (such as a
|
391
|
-
`<picture>`) within a span level element (such as an anchor tag). This flag fixes that issue.
|
392
|
-
|
393
|
-
You should disable this if one of the following applies:
|
394
|
-
* You have changed the markdown parser to something other than kramdown.
|
395
|
-
* You will never wrap your images with links within a markdown file, and it's important that
|
396
|
-
your generated markup is pretty.
|
397
|
-
* It's causing issues. If you're seeing stray `{::nomarkdown}` or garbled HTML, try disabling
|
398
|
-
this and in either case please file a bug report!
|
399
|
-
|
400
|
-
Kramdown is finicky about when it will or won't listen to the `nomarkdown` option, depending on the
|
401
|
-
line breaks before, after, and within the block. The most general solution I've found is to remove
|
402
|
-
all line breaks from j-p-t's output, giving the whole shebang on one line. It makes for ugly markup,
|
403
|
-
but it's pretty much only ever seen by the browser anyway. If you know a better way to accomplish
|
404
|
-
this, I'm all ears!
|
405
|
-
|
406
|
-
## Preset Configuration
|
407
|
-
|
408
|
-
Presets are stored in `_data/picture.yml`, to avoid cluttering `_config.yml`. You will have to
|
409
|
-
create this file, and probably the `_data/` directory as well.
|
410
|
-
|
411
|
-
All settings are optional, moderately sensible defaults have been implemented. A template can be
|
412
|
-
found in the [example data file](examples/_data/picture.yml) in the examples directory.
|
413
|
-
|
414
|
-
**Example settings:**
|
415
|
-
|
416
|
-
```yml
|
417
|
-
|
418
|
-
# _data/picture.yml
|
419
|
-
|
420
|
-
media_presets:
|
421
|
-
wide_desktop: 'min-width: 1801px'
|
422
|
-
desktop: 'max-width: 1800px'
|
423
|
-
wide_tablet: 'max-width: 1200px'
|
424
|
-
tablet: 'max-width: 900px'
|
425
|
-
mobile: 'max-width: 600px'
|
426
|
-
|
427
|
-
markup_presets:
|
428
|
-
default:
|
429
|
-
formats: [webp, original]
|
430
|
-
widths: [200, 400, 800, 1600]
|
431
|
-
media_widths:
|
432
|
-
mobile: [200, 400, 600]
|
433
|
-
tablet: [400, 600, 800]
|
434
|
-
size: 800px
|
435
|
-
sizes:
|
436
|
-
mobile: 100vw
|
437
|
-
desktop: 60vw
|
438
|
-
attributes:
|
439
|
-
picture: 'class="awesome" data-volume="11"'
|
440
|
-
img: 'class="some-other-class"'
|
441
|
-
|
442
|
-
icon:
|
443
|
-
base-width: 20
|
444
|
-
pixel_ratios: [1, 1.5, 2]
|
445
|
-
|
446
|
-
lazy:
|
447
|
-
markup: data_auto
|
448
|
-
formats: [webp, original]
|
449
|
-
widths: [200, 400, 600, 800]
|
450
|
-
noscript: true
|
451
|
-
attributes:
|
452
|
-
img: class="lazy"
|
453
|
-
|
454
|
-
```
|
455
|
-
|
456
|
-
#### Media Presets
|
457
|
-
|
458
|
-
*Format:*
|
459
|
-
|
460
|
-
```yml
|
461
|
-
media_presets:
|
462
|
-
(name): (css media query)
|
463
|
-
(name): (css media query)
|
464
|
-
(name): (css media query)
|
465
|
-
(...)
|
466
|
-
|
467
|
-
```
|
468
|
-
|
469
|
-
*Example:*
|
470
|
-
|
471
|
-
```yml
|
472
|
-
media_presets:
|
473
|
-
desktop: 'min-width: 1200px'
|
474
|
-
```
|
475
|
-
|
476
|
-
These are named media queries for use in a few different places.
|
477
|
-
|
478
|
-
Keys are names by which you can refer to the media queries supplied as their respective values.
|
479
|
-
These are used for specifying alternate source images in your liquid tag, and for building the
|
480
|
-
'sizes' attribute within your presets. Quotes are required around the media
|
481
|
-
queries, because yml gets confused by free colons.
|
482
|
-
|
483
|
-
#### Markup Presets
|
484
|
-
|
485
|
-
*Format:*
|
486
|
-
|
487
|
-
```yml
|
488
|
-
markup_presets:
|
489
|
-
(name):
|
490
|
-
(option): (setting)
|
491
|
-
(option): (setting)
|
492
|
-
(option): (setting)
|
493
|
-
(...)
|
494
|
-
(another name):
|
495
|
-
(option): (setting)
|
496
|
-
(option): (setting)
|
497
|
-
(option): (setting)
|
498
|
-
(...)
|
499
|
-
```
|
500
|
-
|
501
|
-
*Example:*
|
502
|
-
|
503
|
-
```yml
|
504
|
-
markup_presets:
|
505
|
-
default:
|
506
|
-
formats: [webp, original]
|
507
|
-
widths: [200, 400, 800, 1600]
|
508
|
-
link_source: true
|
509
|
-
lazy:
|
510
|
-
markup: data_auto
|
511
|
-
widths: [200, 400, 800, 1600]
|
512
|
-
link_source: true
|
513
|
-
noscript: true
|
514
|
-
```
|
515
|
-
|
516
|
-
These are the 'presets' from previous versions, with different structure. Each entry is a
|
517
|
-
pre-defined collection of settings to build a given chunk of HTML and its respective images. You
|
518
|
-
can select one as the first argument given to the tag:
|
519
|
-
|
520
|
-
`{% picture my-preset image.jpg %}`
|
521
|
-
|
522
|
-
The `default` preset will be used if none is specified. A preset name can't contain the `.`, `:`,
|
523
|
-
or `/` characters.
|
524
|
-
|
525
|
-
#### A Note on srcsets, for the bad kids who didn't do the required reading.
|
526
|
-
|
527
|
-
There are 2 srcset formats, one based on providing widths, the other based on providing multipliers.
|
528
|
-
|
529
|
-
Width based srcsets look like this: `srcset="img.jpg 600w, img2.jpg 800w, img3.jpg 1000w"`. The
|
530
|
-
`(number)w` tells the browser how wide that image file is. Browsers are smart, they know their
|
531
|
-
device's pixel ratio, so in combination with the sizes attribute (if given, otherwise it assumes the
|
532
|
-
image will be 100vw) they can select the best-fitting image for the space it will fill on the screen.
|
533
|
-
|
534
|
-
Multiplier based srcsets look like this: `srcset="img.jpg 1x, img2.jpg 1.5x, img3.jpg 3x"`. The
|
535
|
-
browser is less smart here; it looks at its own device's pixel ratio, compares it to the given
|
536
|
-
multiplier, and picks the closest one. It doesn't consider anything else at all. Multiplier based
|
537
|
-
srcsets are best used when the image will always be the same size, on all screen sizes.
|
538
|
-
|
539
|
-
To use a width based srcset in a preset, specify a `widths` setting (or don't, for the default), and
|
540
|
-
optionally the `sizes` and `size` settings.
|
541
|
-
|
542
|
-
To use a multiplier based srcset, set `pixel_ratios` and `base_width`.
|
543
|
-
|
544
|
-
* **Markup format**
|
545
|
-
|
546
|
-
*Format:* `markup: (setting)`
|
547
|
-
|
548
|
-
*Default*: `auto`
|
549
|
-
|
550
|
-
Defines what format the generated HTML will take. Here are your options:
|
551
|
-
|
552
|
-
* `picture`: `<picture>` element surrounding a `<source>` tag for each required srcset, and a
|
553
|
-
fallback `<img>`.
|
554
|
-
* `img`: output a single `<img>` tag with a `srcset` entry.
|
555
|
-
* `auto`: Supply an img tag when you have only one srcset, otherwise supply a picture tag.
|
556
|
-
* `data_picture`, `data_img`, `data_auto`: Analogous to their counterparts,
|
557
|
-
but instead of `src`, `srcset`, and `sizes`, you get `data-src`, `data-srcset`, and
|
558
|
-
`data-sizes`. This allows you to use javascript for things like [lazy loading](https://github.com/verlok/lazyload)
|
559
|
-
* `direct_url`: Generates an image and returns only its url. Uses `fallback_` properties (width
|
560
|
-
and format)
|
561
|
-
|
562
|
-
* **Image Formats**
|
563
|
-
|
564
|
-
*Format:* `format: [format1, format2, (...)]`
|
565
|
-
|
566
|
-
*Example:* `format: [webp, original]`
|
567
|
-
|
568
|
-
*Default*: `original`
|
569
|
-
|
570
|
-
Array (yml sequence) of the image formats you'd like to generate, in decreasing order
|
571
|
-
of preference. Browsers will render the first format they find and understand, so if you put jpg
|
572
|
-
before webp, your webp images will never be used. `original` does what you'd expect. To supply
|
573
|
-
webp, you must have an imagemagick webp delegate installed, described [here](#imagemagick).
|
574
|
-
|
575
|
-
* **widths**
|
576
|
-
|
577
|
-
*Format:* `widths: [integer, integer, (...)]`
|
578
|
-
|
579
|
-
*Example:* `widths: [600, 800, 1200]`
|
580
|
-
|
581
|
-
*Default*: `[400, 600, 800, 1000]`
|
582
|
-
|
583
|
-
Array of image widths to generate, in pixels. For use when you want a size-based srcset
|
584
|
-
(`srcset="img.jpg 800w, img2.jpg 1600w"`).
|
585
|
-
|
586
|
-
* **media_widths**
|
587
|
-
|
588
|
-
*Format:*
|
589
|
-
|
590
|
-
```yml
|
591
|
-
media_widths:
|
592
|
-
(media preset name): [integer, integer, (...)]
|
593
|
-
```
|
594
|
-
|
595
|
-
*Example:*
|
596
|
-
|
597
|
-
```yml
|
598
|
-
media_widths:
|
599
|
-
mobile: [400, 600, 800]
|
600
|
-
```
|
601
|
-
|
602
|
-
*Default:* Widths setting
|
603
|
-
|
604
|
-
If you are using art direction, there is no sense in generating desktop-size files for your mobile
|
605
|
-
image. You can specify sets of widths to associate with given media queries. If not specified,
|
606
|
-
will use `widths` setting.
|
607
|
-
|
608
|
-
* **Fallback Image**
|
609
|
-
|
610
|
-
*Format:* `fallback_width: (integer)`
|
611
|
-
`fallback_format: (format)`
|
612
|
-
|
613
|
-
*Example:* `fallback_width: 800`
|
614
|
-
`fallback_format: jpg`
|
615
|
-
|
616
|
-
*Default*: `800` and `original`
|
617
|
-
|
618
|
-
Properties of the fallback image, format and width.
|
619
|
-
|
620
|
-
* **Sizes**
|
621
|
-
|
622
|
-
*Format:*
|
623
|
-
```yml
|
624
|
-
sizes:
|
625
|
-
(media query): (CSS dimension)
|
626
|
-
(media query): (CSS dimension)
|
627
|
-
(media query): (CSS dimension)
|
628
|
-
(...)
|
629
|
-
```
|
630
|
-
|
631
|
-
*Example:*
|
632
|
-
```yml
|
633
|
-
sizes:
|
634
|
-
mobile: 80vw
|
635
|
-
tablet: 60vw
|
636
|
-
desktop: 900px
|
637
|
-
```
|
638
|
-
|
639
|
-
Conditional sizes, used to construct the `sizes=` HTML attribute telling the browser how wide your
|
640
|
-
image will be (on the screen) when a given media query is true. CSS dimensions can be given in
|
641
|
-
`px`, `em`, or `vw`. To be used along with a width based srcset.
|
642
|
-
|
643
|
-
You don't have to provide a sizes attribute at all. If you don't, the browser will assume the
|
644
|
-
image is 100% the width of the viewport.
|
645
|
-
|
646
|
-
The same sizes attribute is used for every source tag in a given picture tag. This causes some
|
647
|
-
redundant markup, specifying sizes for situations when an image will never be rendered, but it
|
648
|
-
simplifies configuration greatly.
|
649
|
-
|
650
|
-
* **Size**
|
651
|
-
|
652
|
-
*Format:* `size: (CSS Dimension)`
|
653
|
-
|
654
|
-
*Example:* `size: 80vw`
|
655
|
-
|
656
|
-
Unconditional image width to give the browser (by way of the html sizes attribute), to be supplied
|
657
|
-
either alone or after all conditional sizes.
|
658
|
-
|
659
|
-
* **Pixel Ratios**
|
660
|
-
|
661
|
-
*Format:* `pixel_ratios: [number, number, number (...)]`
|
662
|
-
|
663
|
-
*Example:* `pixel_ratios: [1, 1.5, 2]`
|
664
|
-
|
665
|
-
Array of images to construct, given in multiples of the base width. If you set this, you must also
|
666
|
-
give a `base_width`.
|
667
|
-
|
668
|
-
Set this when you want a multiplier based srcset (example: `srcset="img.jpg 1x, img2.jpg 2x"`).
|
669
|
-
|
670
|
-
* **Base Width**
|
671
|
-
|
672
|
-
*Format:* `base_width: integer`
|
673
|
-
|
674
|
-
*Example:* `base_width: 100`
|
675
|
-
|
676
|
-
When using pixel ratios, you must supply a base width. This sets how wide the 1x image should be.
|
677
|
-
|
678
|
-
* **HTML Attributes**
|
679
|
-
|
680
|
-
*Format:*
|
681
|
-
|
682
|
-
```yml
|
683
|
-
attributes:
|
684
|
-
(element): '(attributes)'
|
685
|
-
(element): '(attributes)'
|
686
|
-
(element): '(attributes)'
|
687
|
-
(...)
|
688
|
-
```
|
689
|
-
|
690
|
-
*Example:*
|
691
|
-
|
692
|
-
```yml
|
693
|
-
attributes:
|
694
|
-
img: 'class="soopercool" data-awesomeness="11"'
|
695
|
-
picture: 'class="even-cooler"'
|
696
|
-
```
|
697
|
-
|
698
|
-
HTML attributes you would like to add. The same arguments are available here as in the liquid
|
699
|
-
tag; element names, `alt:`, `url:`, and `parent:`. Unescaped double quotes cause problems with
|
700
|
-
yml, so it's recommended to surround them with single quotes.
|
701
|
-
|
702
|
-
* **Noscript**
|
703
|
-
|
704
|
-
*Format:* `noscript: (true|false)`
|
705
|
-
|
706
|
-
*Example:* `noscript: true`
|
707
|
-
|
708
|
-
*Default:* `false`
|
709
|
-
|
710
|
-
For use with the `data_` output formats. When true, will include a basic `img` fallback within a
|
711
|
-
`<noscript>` tag after the standard html. This allows you to use lazy loading or other javascript
|
712
|
-
image tools, without breaking all of your images for non-javascript-enabled users.
|
713
|
-
|
714
|
-
* **Source Image Linking**
|
715
|
-
|
716
|
-
*Format:* `link_source: (true|false)`
|
717
|
-
|
718
|
-
*Example:* `link_source: true`
|
719
|
-
|
720
|
-
*Default:* `false`
|
721
|
-
|
722
|
-
Surround image with a link to the original source file. Your source image directory must
|
723
|
-
be published as part of the compiled site. The same caveats apply as the `--url` flag: don't
|
724
|
-
disable `nomarkdown` if you'll be using this from within a kramdown parsed markdown file.
|
725
|
-
|
726
|
-
# Miscellaneous Tidbits
|
727
|
-
|
728
|
-
### Lazy Loading, and other javascript related tomfoolery
|
729
|
-
|
730
|
-
Use one of the `data_` output formats and something like
|
731
|
-
[LazyLoad](https://github.com/verlok/lazyload). The 'lazy' preset in the example config will work.
|
732
|
-
|
733
|
-
### PictureFill
|
734
|
-
|
735
|
-
[Picturefill](http://scottjehl.github.io/picturefill/) version 3 no longer requires special markup.
|
736
|
-
Standard outputs should be compatible.
|
737
|
-
|
738
|
-
### Managing Generated Images
|
739
|
-
|
740
|
-
Jekyll Picture Tag creates resized versions of your images when you build the site. It uses a smart
|
741
|
-
caching system to speed up site compilation, and re-uses images as much as possible. Filenames
|
742
|
-
take the following format:
|
743
|
-
|
744
|
-
`(original filename without extension)_(width)by(height)_(source hash).(format)`
|
745
|
-
|
746
|
-
Source hash is the first 5 characters of an md5 checksum of the source image.
|
747
|
-
|
748
|
-
Try to use a base image that is larger than the largest resized image you need. Jekyll Picture Tag
|
749
|
-
will warn you if a base image is too small, and won't upscale images.
|
750
|
-
|
751
|
-
By specifying a `source` directory that is ignored by Jekyll you can prevent huge base images from
|
752
|
-
being copied to the compiled site. For example, `source: assets/images/_fullsize` and `output:
|
753
|
-
generated` will result in a compiled site that contains resized images but not the originals. Note
|
754
|
-
that this will break source image linking, if you wish to enable it. (Can't link to images that
|
755
|
-
aren't public!)
|
756
|
-
|
757
|
-
The `output` directory is never deleted by Jekyll. You may want to manually clean it every once in a
|
758
|
-
while to remove unused images.
|
759
|
-
|
760
167
|
# Contribute
|
761
168
|
|
762
|
-
Report bugs and feature proposals in the
|
169
|
+
Report bugs and feature proposals in the
|
763
170
|
[Github issue tracker](https://github.com/robwierzbowski/jekyll-picture-tag/issues).
|
764
171
|
|
765
172
|
Pull requests are encouraged. With a few exceptions, this plugin is written to follow the Rubocop
|
766
173
|
default settings (except the frozen string literal comment).
|
767
174
|
|
768
175
|
If you add a new setting, it is helpful to add a default value (look under `lib/defaults/`) and
|
769
|
-
relevant documentation
|
770
|
-
|
176
|
+
relevant documentation. Don't let that stop you from submitting a pull request, though! Just allow
|
177
|
+
modifications and I'll take care of it.
|
771
178
|
|
772
179
|
# Release History
|
773
180
|
|
181
|
+
* 1.4.0 Jun 26, 2019:
|
182
|
+
* Rename gem from `jekyll-picture-tag` to `jekyll_picture_tag`, allowing us to use rubygems again.
|
183
|
+
* Add new output format: `naked_srcset`.
|
184
|
+
* 1.3.1 Jun 21, 2019: Bugfix
|
185
|
+
* 1.3.0 Jun 7, 2019: Initial compatibility with Jekyll 4.0, bugfixes, change to generated image
|
186
|
+
naming. The first build after this update will be longer, and you might want to clear out your
|
187
|
+
generated images.
|
774
188
|
* 1.2.0 Feb 9, 2019: Add nomarkdown fix, noscript option, relative url option, anchor tag wrappers
|
775
189
|
* 1.1.0 Jan 22, 2019: Add direct_url markup format, auto-orient images before stripping metadata.
|
776
190
|
* 1.0.2 Jan 18, 2019: Fix ruby version specification
|
777
191
|
* 1.0.1 Jan 13, 2019: Added ruby version checking for more helpful error messages when running old versions of ruby.
|
778
192
|
* **1.0.0** Nov 27, 2018: Rewrite from the ground up. See [migration.md](/migration.md).
|
779
|
-
* 0.2.2 Aug 2, 2013: Bugfixes.
|
193
|
+
* 0.2.2 Aug 2, 2013: Bugfixes.
|
780
194
|
* 0.2.1 Jul 17, 2013: Refactor again, add Liquid parsing.
|
781
195
|
* 0.2.0 Jul 14, 2013: Rewrite code base, bring in line with Jekyll Image Tag.
|
782
196
|
* 0.1.1 Jul 5, 2013: Quick round of code improvements.
|