jekyll_picture_tag 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -7
- data/Dockerfile +9 -0
- data/docs/Gemfile.lock +183 -88
- data/docs/contributing.md +50 -16
- data/docs/example_presets.md +1 -1
- data/docs/index.md +26 -20
- data/docs/installation.md +22 -7
- data/docs/presets.md +106 -54
- data/docs/releases.md +4 -0
- data/docs/usage.md +68 -38
- data/jekyll_picture_tag.gemspec +2 -1
- data/lib/jekyll_picture_tag/defaults/presets.yml +1 -0
- data/lib/jekyll_picture_tag/generated_image.rb +47 -15
- data/lib/jekyll_picture_tag/instructions.rb +1 -0
- data/lib/jekyll_picture_tag/instructions/arg_splitter.rb +68 -0
- data/lib/jekyll_picture_tag/instructions/preset.rb +34 -14
- data/lib/jekyll_picture_tag/instructions/set.rb +18 -8
- data/lib/jekyll_picture_tag/instructions/tag_parser.rb +59 -69
- data/lib/jekyll_picture_tag/output_formats/basic.rb +28 -11
- data/lib/jekyll_picture_tag/router.rb +8 -0
- data/lib/jekyll_picture_tag/srcsets/basic.rb +20 -7
- data/lib/jekyll_picture_tag/utils.rb +18 -0
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +35 -16
- metadata +21 -5
data/docs/example_presets.md
CHANGED
@@ -75,7 +75,7 @@ markup_presets:
|
|
75
75
|
# your source images will need to be part of the deployed site for this to
|
76
76
|
# work. If you have issues such as mangled HTML or extra {::nomarkdown}
|
77
77
|
# tags floating around, see docs/notes.md
|
78
|
-
|
78
|
+
link_source: true
|
79
79
|
|
80
80
|
# This is an example of how you would create a 'multiplier' based srcset;
|
81
81
|
# useful when an image will always be the same size on all screens (icons,
|
data/docs/index.md
CHANGED
@@ -39,10 +39,10 @@ markup_presets:
|
|
39
39
|
|
40
40
|
### Here's a more complete demonstration:
|
41
41
|
|
42
|
-
[Presets]({{ site.baseurl }}/presets) are named collections of settings
|
43
|
-
|
44
|
-
|
45
|
-
examples).
|
42
|
+
[Presets]({{ site.baseurl }}/presets) are named collections of settings, and come in 2 kinds: Media
|
43
|
+
Presets are named CSS media queries, and Markup Presets determine the output text and images. You
|
44
|
+
choose one with the second [tag parameter]({{ site.baseurl }}/usage), or omit for the `default` (as
|
45
|
+
in these examples). They are located in `_data/picture.yml`. Here's an example:
|
46
46
|
|
47
47
|
```yml
|
48
48
|
media_presets:
|
@@ -57,13 +57,15 @@ markup_presets:
|
|
57
57
|
size: 500px
|
58
58
|
```
|
59
59
|
|
60
|
-
|
60
|
+
Imagemagick can easily crop images to an aspect ratio, though you should **read the whole
|
61
|
+
installation guide before using this feature**. With the above preset, if you write this:
|
62
|
+
|
61
63
|
|
62
64
|
{% raw %}
|
63
|
-
`{% picture test.jpg mobile: test2.jpg --alt Alternate Text %}`
|
65
|
+
`{% picture test.jpg 3:2 mobile: test2.jpg 1:1 --alt Alternate Text %}`
|
64
66
|
{% endraw %}
|
65
67
|
|
66
|
-
|
68
|
+
You'll get something like this:
|
67
69
|
|
68
70
|
```html
|
69
71
|
<!-- Formatted for readability -->
|
@@ -73,36 +75,40 @@ Get this:
|
|
73
75
|
sizes="(max-width: 600px) 80vw, 600px"
|
74
76
|
media="(max-width: 600px)"
|
75
77
|
srcset="
|
76
|
-
/generated/test2-600-
|
77
|
-
/generated/test2-900-
|
78
|
-
/generated/test2-1200-
|
78
|
+
/generated/test2-600-21bb6fGUW.webp 600w,
|
79
|
+
/generated/test2-900-21bb6fGUW.webp 900w,
|
80
|
+
/generated/test2-1200-21bb6fGUW.webp 1200w
|
79
81
|
"
|
80
82
|
type="image/webp">
|
81
83
|
<source
|
82
84
|
sizes="(max-width: 600px) 80vw, 600px"
|
83
85
|
srcset="
|
84
|
-
/generated/test-600-
|
85
|
-
/generated/test-900-
|
86
|
-
/generated/test-1200-
|
86
|
+
/generated/test-600-195f7d192.webp 600w,
|
87
|
+
/generated/test-900-195f7d192.webp 900w,
|
88
|
+
/generated/test-1200-195f7d192.webp 1200w
|
87
89
|
"
|
88
90
|
type="image/webp">
|
89
91
|
<source
|
90
92
|
sizes="(max-width: 600px) 80vw, 600px"
|
91
93
|
media="(max-width: 600px)"
|
92
94
|
srcset="
|
93
|
-
/generated/test2-600-
|
94
|
-
/generated/test2-900-
|
95
|
-
/generated/test2-1200-
|
95
|
+
/generated/test2-600-21bb6fGUW.jpg 600w,
|
96
|
+
/generated/test2-900-21bb6fGUW.jpg 900w,
|
97
|
+
/generated/test2-1200-21bb6fGUW.jpg 1200w
|
96
98
|
"
|
97
99
|
type="image/jpeg">
|
98
100
|
<source
|
99
101
|
sizes="(max-width: 600px) 80vw, 600px"
|
100
102
|
srcset="
|
101
|
-
/generated/test-600-
|
102
|
-
/generated/test-900-
|
103
|
-
/generated/test-1200-
|
103
|
+
/generated/test-600-195f7d192.jpg 600w,
|
104
|
+
/generated/test-900-195f7d192.jpg 900w,
|
105
|
+
/generated/test-1200-195f7d192.jpg 1200w
|
104
106
|
"
|
105
107
|
type="image/jpeg">
|
106
|
-
<img src="/generated/test-800-
|
108
|
+
<img src="/generated/test-800-195f7dGUW.jpg" alt="Alternate Text">
|
107
109
|
</picture>
|
108
110
|
```
|
111
|
+
|
112
|
+
In other words, you have the art direction, format switching, and resolution switching problems
|
113
|
+
*solved*, with a one-liner and a nicely readable config file that is 1/3 as long as the output
|
114
|
+
markup. Lighthouse is happy, and you don't even need to crop things yourself.
|
data/docs/installation.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
---
|
2
2
|
---
|
3
|
+
|
3
4
|
# Installation
|
4
5
|
|
5
|
-
|
6
|
+
- Add `jekyll_picture_tag` to your Gemfile in the `:jekyll_plugins` group:
|
6
7
|
|
7
8
|
```ruby
|
8
9
|
group :jekyll_plugins do
|
@@ -10,21 +11,35 @@
|
|
10
11
|
end
|
11
12
|
```
|
12
13
|
|
13
|
-
|
14
|
+
- Run `$ bundle install`
|
14
15
|
|
15
|
-
|
16
|
+
- See if you have ImageMagick with `$ convert --version`. You should see something like this:
|
16
17
|
|
17
18
|
```
|
18
|
-
~ $ convert --version
|
19
|
+
~ $ convert --version
|
19
20
|
Version: ImageMagick 7.0.8-14 Q16 x86_64 2018-10-31 https://imagemagick.org
|
20
21
|
Copyright: © 1999-2018 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php
|
21
22
|
Features: Cipher DPC HDRI OpenMP Delegates (built-in): bzlib fontconfig freetype jng jp2 jpeg lcms
|
22
23
|
lzma pangocairo png tiff webp xml zlib
|
23
24
|
```
|
25
|
+
|
24
26
|
If you get a 'command not found' error, you'll need to install it. Most package managers know about
|
25
27
|
ImageMagick, otherwise it can be found [here](https://imagemagick.org/script/download.php).
|
26
28
|
|
27
|
-
|
28
|
-
you want to handle will require an appropriate delegate; You may have to install additional packages
|
29
|
-
to accomplish this.
|
29
|
+
- **Note webp under delegates.** This is required if you want to generate webp files. Any image format
|
30
|
+
you want to handle will require an appropriate delegate; You may have to install additional packages
|
31
|
+
to accomplish this.
|
32
|
+
|
33
|
+
## Cropping and Imagemagick
|
34
|
+
|
35
|
+
Cropping to an aspect ratio depends on ImageMagick 7+. Ubuntu, somewhat annoyingly, only offers
|
36
|
+
version 6 in its official repositories. This matters even if you don't run Ubuntu, because many
|
37
|
+
build & deployment services you might use (including Netlify and Travis CI) do.
|
38
|
+
|
39
|
+
If you'd like to use both the cropping feature and such a service, or it's inconvenient to install
|
40
|
+
version 7 in your development environment, you will likely want to build your site in a docker
|
41
|
+
container. The Alpine Linux repos include version 7, so you'll want an Alpine Linux based image
|
42
|
+
rather than an Ubuntu based one. Convenienly this includes the [offical Jekyll
|
43
|
+
image](https://hub.docker.com/r/jekyll/jekyll).
|
30
44
|
|
45
|
+
Once I work out how to actually do that, I'll add some guidance here.
|
data/docs/presets.md
CHANGED
@@ -22,7 +22,7 @@ browser widths until you understand it.
|
|
22
22
|
|
23
23
|
## Media Presets
|
24
24
|
|
25
|
-
|
25
|
+
_Format:_
|
26
26
|
|
27
27
|
```yml
|
28
28
|
media_presets:
|
@@ -32,11 +32,11 @@ media_presets:
|
|
32
32
|
|
33
33
|
```
|
34
34
|
|
35
|
-
|
35
|
+
_Example:_
|
36
36
|
|
37
37
|
```yml
|
38
38
|
media_presets:
|
39
|
-
desktop:
|
39
|
+
desktop: "min-width: 1200px"
|
40
40
|
```
|
41
41
|
|
42
42
|
These are named media queries for use in a few different places: specifying alternate source images
|
@@ -45,7 +45,7 @@ settings. Quotes are recommended around the media queries, because yml gets conf
|
|
45
45
|
|
46
46
|
## Markup Presets
|
47
47
|
|
48
|
-
|
48
|
+
_Format:_
|
49
49
|
|
50
50
|
```yml
|
51
51
|
markup_presets:
|
@@ -56,7 +56,7 @@ markup_presets:
|
|
56
56
|
(...)
|
57
57
|
```
|
58
58
|
|
59
|
-
|
59
|
+
_Example:_
|
60
60
|
|
61
61
|
```yml
|
62
62
|
markup_presets:
|
@@ -84,29 +84,28 @@ The `default` preset will be used if none is specified. A preset name can't cont
|
|
84
84
|
|
85
85
|
For images that are different sizes on different screens (most images), use a width-based srcset
|
86
86
|
(which is the default). Specify a `widths` setting (or don't, for the default set), and optionally
|
87
|
-
the `sizes` and `size` settings.
|
87
|
+
the `sizes` and `size` settings.
|
88
88
|
|
89
89
|
Use a multiplier-based srcset when the image will always be the same size, regardless of screen
|
90
90
|
width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratios` and `base_width`.
|
91
91
|
|
92
92
|
### Settings reference
|
93
93
|
|
94
|
-
|
94
|
+
- **Markup format**
|
95
95
|
|
96
|
-
|
96
|
+
_Format:_ `markup: (setting)`
|
97
97
|
|
98
|
-
|
98
|
+
_Default_: `auto`
|
99
99
|
|
100
100
|
Defines what format the generated text will take. They are documented [here]({{ site.baseurl }}/output).
|
101
101
|
|
102
|
-
|
103
102
|
* **Image Formats**
|
104
103
|
|
105
|
-
|
104
|
+
_Format:_ `format: [format1, format2, (...)]`
|
106
105
|
|
107
|
-
|
106
|
+
_Example:_ `format: [webp, original]`
|
108
107
|
|
109
|
-
|
108
|
+
_Default_: `original`
|
110
109
|
|
111
110
|
Array (yml sequence) of the image formats you'd like to generate, in decreasing order of
|
112
111
|
preference. Browsers will render the first format they find and understand, so **If you put jpg
|
@@ -114,37 +113,37 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
114
113
|
webp, you must have an imagemagick webp delegate installed. (Most package managers just name it
|
115
114
|
'webp')
|
116
115
|
|
117
|
-
|
118
|
-
list by running `$ convert --version
|
116
|
+
_Supported formats are anything which imagemagick supports, and has an installed delegate. See a
|
117
|
+
list by running `$ convert --version`_
|
119
118
|
|
120
119
|
* **Widths**
|
121
120
|
|
122
|
-
|
121
|
+
_Format:_ `widths: [integer, integer, (...)]`
|
123
122
|
|
124
|
-
|
123
|
+
_Example:_ `widths: [600, 800, 1200]`
|
125
124
|
|
126
|
-
|
125
|
+
_Default_: `[400, 600, 800, 1000]`
|
127
126
|
|
128
127
|
Array of image widths to generate, in pixels. For use when you want a width-based srcset
|
129
128
|
(`srcset="img.jpg 800w, img2.jpg 1600w"`).
|
130
129
|
|
131
130
|
* **Media_widths**
|
132
131
|
|
133
|
-
|
132
|
+
_Format:_
|
134
133
|
|
135
134
|
```yml
|
136
135
|
media_widths:
|
137
136
|
(media preset name): [integer, integer, (...)]
|
138
137
|
```
|
139
138
|
|
140
|
-
|
139
|
+
_Example:_
|
141
140
|
|
142
141
|
```yml
|
143
142
|
media_widths:
|
144
143
|
mobile: [400, 600, 800]
|
145
144
|
```
|
146
145
|
|
147
|
-
|
146
|
+
_Default:_ Widths setting
|
148
147
|
|
149
148
|
If you are using art direction, there is no sense in generating desktop-size files for your mobile
|
150
149
|
image. You can specify sets of widths to associate with given media queries. If not specified,
|
@@ -152,7 +151,7 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
152
151
|
|
153
152
|
* **Sizes**
|
154
153
|
|
155
|
-
|
154
|
+
_Format:_
|
156
155
|
|
157
156
|
```yml
|
158
157
|
sizes:
|
@@ -160,7 +159,7 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
160
159
|
(...)
|
161
160
|
```
|
162
161
|
|
163
|
-
|
162
|
+
_Example:_
|
164
163
|
|
165
164
|
```yml
|
166
165
|
sizes:
|
@@ -173,7 +172,7 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
173
172
|
image will be (on the screen) when a given media query is true. CSS dimensions can be given in
|
174
173
|
`px`, `em`, or `vw`. To be used along with a width-based srcset.
|
175
174
|
|
176
|
-
Provide these in order of most restrictive to least restrictive. The browser will choose the
|
175
|
+
Provide these in order of most restrictive to least restrictive. The browser will choose the
|
177
176
|
first one with an applicable media query.
|
178
177
|
|
179
178
|
You don't have to provide a sizes attribute at all. If you don't, the browser will assume the
|
@@ -181,17 +180,17 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
181
180
|
|
182
181
|
* **Size**
|
183
182
|
|
184
|
-
|
183
|
+
_Format:_ `size: (CSS Dimension)`
|
185
184
|
|
186
|
-
|
185
|
+
_Example:_ `size: 80vw`
|
187
186
|
|
188
187
|
Unconditional `sizes` setting, to be supplied either alone or after all conditional sizes.
|
189
188
|
|
190
189
|
* **Pixel Ratios**
|
191
190
|
|
192
|
-
|
191
|
+
_Format:_ `pixel_ratios: [number, number, number (...)]`
|
193
192
|
|
194
|
-
|
193
|
+
_Example:_ `pixel_ratios: [1, 1.5, 2]`
|
195
194
|
|
196
195
|
Array of images to construct, given in multiples of the base width. If you set this, you must also
|
197
196
|
give a `base_width`.
|
@@ -200,26 +199,79 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
200
199
|
|
201
200
|
* **Base Width**
|
202
201
|
|
203
|
-
|
202
|
+
_Format:_ `base_width: integer`
|
204
203
|
|
205
|
-
|
204
|
+
_Example:_ `base_width: 100`
|
206
205
|
|
207
206
|
When using pixel ratios, you must supply a base width. This sets how wide the 1x image should be.
|
208
207
|
|
208
|
+
* **Crop & Media Crop**
|
209
|
+
|
210
|
+
_Format:_
|
211
|
+
|
212
|
+
```yml
|
213
|
+
crop: (geometery)
|
214
|
+
media_crop:
|
215
|
+
(media_preset): (geometry)
|
216
|
+
(media_preset): (geometry)
|
217
|
+
(...)
|
218
|
+
```
|
219
|
+
|
220
|
+
_Example:_
|
221
|
+
|
222
|
+
```yml
|
223
|
+
crop: 16:9
|
224
|
+
media_crop:
|
225
|
+
tablet: 3:2
|
226
|
+
mobile: 1:1
|
227
|
+
```
|
228
|
+
|
229
|
+
**Check the [ installation guide ](installation) before using this feature.**
|
230
|
+
|
231
|
+
Crop geometry, given either generally or for specific media presets. The hierarchy is:
|
232
|
+
`tag argument` > `media_crop:` > `crop:`.
|
233
|
+
|
234
|
+
This setting accepts the same arguments as the `crop geometry` [tag parameter](usage).
|
235
|
+
|
236
|
+
|
237
|
+
* **Gravity & Media_gravity**
|
238
|
+
|
239
|
+
```yml
|
240
|
+
crop: (gravity)
|
241
|
+
media_crop:
|
242
|
+
(media_preset): (gravity)
|
243
|
+
(media_preset): (gravity)
|
244
|
+
(...)
|
245
|
+
```
|
246
|
+
|
247
|
+
_Example:_
|
248
|
+
|
249
|
+
```yml
|
250
|
+
crop: north
|
251
|
+
media_crop:
|
252
|
+
tablet: east
|
253
|
+
mobile: southwest
|
254
|
+
```
|
255
|
+
|
256
|
+
Crop gravity, given either generally or for specific media presets. The hierarchy is:
|
257
|
+
`tag argument` > `media_crop:` > `crop:` > `center` (default).
|
258
|
+
|
259
|
+
This setting accepts the same arguments as the `crop gravity` [tag parameter](usage).
|
260
|
+
|
209
261
|
* **Quality**
|
210
262
|
|
211
|
-
|
263
|
+
_Format:_ `quality: 0 <= integer <= 100`
|
212
264
|
|
213
|
-
|
265
|
+
_Example:_ `quality: 80`
|
214
266
|
|
215
|
-
|
267
|
+
_Default:_ `75`
|
216
268
|
|
217
269
|
This allows you to specify an image compression level for all image formats (where it makes sense,
|
218
270
|
anyway). The next option allows you to set them per format.
|
219
271
|
|
220
272
|
* **Format Quality**
|
221
273
|
|
222
|
-
|
274
|
+
_Format:_
|
223
275
|
|
224
276
|
```yml
|
225
277
|
format_quality:
|
@@ -227,7 +279,7 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
227
279
|
(...)
|
228
280
|
```
|
229
281
|
|
230
|
-
|
282
|
+
_Example:_
|
231
283
|
|
232
284
|
```
|
233
285
|
format_quality:
|
@@ -236,16 +288,16 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
236
288
|
webp: 55
|
237
289
|
```
|
238
290
|
|
239
|
-
|
291
|
+
_Default:_ quality setting (above)
|
240
292
|
|
241
293
|
This allows you to specify quality settings for various image formats, allowing you to take
|
242
294
|
advantage of webp's better compression algorithm without trashing your jpg images (for example).
|
243
295
|
If you don't give a setting for a particular format it'll fall back to the `quality` setting
|
244
|
-
above, and if you don't set
|
296
|
+
above, and if you don't set _that_ it'll default to 75.
|
245
297
|
|
246
298
|
* **HTML Attributes**
|
247
299
|
|
248
|
-
|
300
|
+
_Format:_
|
249
301
|
|
250
302
|
```yml
|
251
303
|
attributes:
|
@@ -253,7 +305,7 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
253
305
|
(...)
|
254
306
|
```
|
255
307
|
|
256
|
-
|
308
|
+
_Example:_
|
257
309
|
|
258
310
|
```yml
|
259
311
|
attributes:
|
@@ -261,49 +313,49 @@ width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratio
|
|
261
313
|
picture: 'class="even-cooler"'
|
262
314
|
```
|
263
315
|
|
264
|
-
HTML attributes you would like to add.
|
316
|
+
HTML attributes you would like to add. The same arguments are available here as in the liquid
|
265
317
|
tag: HTML element names, `alt:`, `link:`, and `parent:`. Unescaped double quotes cause problems
|
266
318
|
with yml, so it's recommended to surround them with single quotes.
|
267
319
|
|
268
320
|
* **Fallback Width**
|
269
321
|
|
270
|
-
|
322
|
+
_Format:_ `fallback_width: (integer)`
|
271
323
|
|
272
|
-
|
324
|
+
_Example:_ `fallback_width: 800`
|
273
325
|
|
274
|
-
|
326
|
+
_Default_: `800`
|
275
327
|
|
276
328
|
Width of the fallback image.
|
277
329
|
|
278
330
|
* **Fallback Format**
|
279
331
|
|
280
|
-
|
332
|
+
_Format:_ `fallback_format: (format)`
|
281
333
|
|
282
|
-
|
334
|
+
_Example:_ `fallback_format: jpg`
|
283
335
|
|
284
|
-
|
336
|
+
_Default_: `original`
|
285
337
|
|
286
338
|
Format of the fallback image
|
287
339
|
|
288
340
|
* **Source Image Link**
|
289
341
|
|
290
|
-
|
342
|
+
_Format:_ `link_source: (true|false)`
|
291
343
|
|
292
|
-
|
344
|
+
_Example:_ `link_source: true`
|
293
345
|
|
294
|
-
|
346
|
+
_Default:_ `false`
|
295
347
|
|
296
348
|
Surround image with a link to the original source file. Your source image directory must be
|
297
349
|
published as part of the compiled site. If you run into weird issues with the output, see
|
298
350
|
the [notes]({{ site.baseurl }}/notes).
|
299
351
|
|
300
352
|
* **Nomarkdown override**
|
301
|
-
|
302
|
-
*Format:* `nomarkdown: (true|false)`
|
303
353
|
|
304
|
-
|
354
|
+
_Format:_ `nomarkdown: (true|false)`
|
355
|
+
|
356
|
+
_Example:_ `nomarkdown: false`
|
305
357
|
|
306
|
-
|
358
|
+
_Default:_ `nil`
|
307
359
|
|
308
360
|
Hard setting for `{::nomarkdown}` tags, overrides both autodetection and the global setting in
|
309
|
-
`_config.yml`. See the [notes]({{ site.baseurl }}/notes) for a detailed explanation.
|
361
|
+
`_config.yml`. See the [notes]({{ site.baseurl }}/notes) for a detailed explanation.
|