jekyll_picture_tag 1.2.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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +24 -0
  6. data/Rakefile +1 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +7 -0
  9. data/examples/_config.yml +4 -0
  10. data/examples/_data/picture.yml +85 -0
  11. data/examples/post.md +18 -0
  12. data/jekyll_picture_tag.gemspec +39 -0
  13. data/lib/jekyll_picture_tag.rb +67 -0
  14. data/lib/jekyll_picture_tag/defaults/global.yml +10 -0
  15. data/lib/jekyll_picture_tag/defaults/presets.yml +7 -0
  16. data/lib/jekyll_picture_tag/generated_image.rb +66 -0
  17. data/lib/jekyll_picture_tag/instructions.rb +105 -0
  18. data/lib/jekyll_picture_tag/instructions/configuration.rb +82 -0
  19. data/lib/jekyll_picture_tag/instructions/html_attributes.rb +59 -0
  20. data/lib/jekyll_picture_tag/instructions/preset.rb +61 -0
  21. data/lib/jekyll_picture_tag/instructions/tag_parser.rb +48 -0
  22. data/lib/jekyll_picture_tag/output_formats.rb +9 -0
  23. data/lib/jekyll_picture_tag/output_formats/auto.rb +15 -0
  24. data/lib/jekyll_picture_tag/output_formats/basics.rb +105 -0
  25. data/lib/jekyll_picture_tag/output_formats/data_attributes.rb +44 -0
  26. data/lib/jekyll_picture_tag/output_formats/data_auto.rb +14 -0
  27. data/lib/jekyll_picture_tag/output_formats/data_img.rb +8 -0
  28. data/lib/jekyll_picture_tag/output_formats/data_picture.rb +8 -0
  29. data/lib/jekyll_picture_tag/output_formats/direct_url.rb +13 -0
  30. data/lib/jekyll_picture_tag/output_formats/img.rb +24 -0
  31. data/lib/jekyll_picture_tag/output_formats/picture.rb +66 -0
  32. data/lib/jekyll_picture_tag/source_image.rb +62 -0
  33. data/lib/jekyll_picture_tag/srcsets.rb +3 -0
  34. data/lib/jekyll_picture_tag/srcsets/basics.rb +88 -0
  35. data/lib/jekyll_picture_tag/srcsets/pixel_ratio.rb +32 -0
  36. data/lib/jekyll_picture_tag/srcsets/width.rb +45 -0
  37. data/lib/jekyll_picture_tag/utils.rb +67 -0
  38. data/lib/jekyll_picture_tag/version.rb +3 -0
  39. data/migration.md +178 -0
  40. data/readme.md +787 -0
  41. metadata +191 -0
@@ -0,0 +1,787 @@
1
+ # Jekyll Picture Tag
2
+
3
+ **Easy responsive images for Jekyll.**
4
+
5
+ It's easy to throw an image on a webpage and call it a day. Doing justice to your users by serving it
6
+ efficiently on all screen sizes is tedious and tricky. Tedious, tricky things should be automated.
7
+
8
+ Jekyll Picture Tag is a liquid tag that adds responsive images to your
9
+ [Jekyll](http://jekyllrb.com) static site. It automatically creates resized,
10
+ reformatted source images, is fully configurable, implements sensible defaults,
11
+ and solves both the art direction and resolution switching problems, with a
12
+ little YAML configuration and a simple template tag. It can be configured to
13
+ work with JavaScript libraries such as
14
+ [LazyLoad](https://github.com/verlok/lazyload).
15
+
16
+ ## Why use Jekyll Picture Tag?
17
+
18
+ **Performance:** The fastest sites are static sites. If we're not using responsive images we're
19
+ throwing those performance gains away by serving kilobytes of pixels a user will never see.
20
+
21
+ **Design:** Your desktop image may not work well on mobile, regardless of its resolution. We often
22
+ want to do more than just resize images for different screen sizes.
23
+
24
+ **Developer Sanity:** Image downloading starts before the browser has parsed your CSS and
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:
27
+
28
+ - Generate, name, and organize the required images (formats \* resolutions, for each source image)
29
+ - Inform the browser about the image itself-- format, size, URI, and the screen sizes where it
30
+ should be used.
31
+ - Inform the browser how large the space for that image on the page will be (which also probably has associated media
32
+ queries).
33
+
34
+ It's a lot. It's tedious and complicated. Jekyll Picture Tag automates it.
35
+
36
+ ## Features
37
+
38
+ * Automatic generation of resized, converted image files.
39
+ * Automatic generation of complex markup in one of several different formats.
40
+ * No configuration required, extensive configuration available.
41
+ * Auto-select between `<picture>` or lone `<img>` as necessary.
42
+ * Support for both width based and pixel ratio based srcsets.
43
+ * Webp conversion.
44
+ * `sizes` attribute assistance.
45
+ * named media queries so you don't have to remember them.
46
+ * Optional `<noscript>` tag with a basic fallback image, so you can lazy load without excluding your
47
+ javascript-impaired users.
48
+ * Optionally, automatically link to the source image. Or manually link to anywhere else, with just a
49
+ tag parameter!
50
+
51
+ # Required Knowledge
52
+
53
+ Jekyll Picture tag is basically a programmatic implementation of the [MDN Responsive Images
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.
58
+
59
+ # Table of Contents
60
+
61
+ * [Installation](#installation)
62
+ * [Usage](#usage)
63
+ * [Configuration](#configuration)
64
+ * [Global](#global-configuration)
65
+ * [Presets](#preset-configuration)
66
+ * [Other notes](#miscellaneous-tidbits)
67
+ * [Contribute](#contribute)
68
+ * [Release History](#release-history)
69
+ * [License](#license)
70
+
71
+ # Quick start / Demo
72
+
73
+ **All configuration is optional.** Here's the simplest possible use case:
74
+
75
+ Add j-p-t to your gemfile:
76
+
77
+ ```ruby
78
+ group :jekyll_plugins do
79
+ gem 'jekyll-picture-tag', git: 'https://github.com/robwierzbowski/jekyll-picture-tag/'
80
+ end
81
+ ```
82
+
83
+ Write this:
84
+
85
+ `{% picture test.jpg %}`
86
+
87
+ Get this:
88
+
89
+ ```html
90
+ <!-- Line breaks added for readability, the actual markup will not have them. -->
91
+ <img
92
+ src="http://localhost:4000/generated/test-800by450-195f7d.jpg"
93
+ srcset="
94
+ http://localhost:4000/generated/test-400by225-195f7d.jpg 400w,
95
+ http://localhost:4000/generated/test-600by338-195f7d.jpg 600w,
96
+ http://localhost:4000/generated/test-800by450-195f7d.jpg 800w,
97
+ http://localhost:4000/generated/test-1000by563-195f7d.jpg 1000w"
98
+ >
99
+ ```
100
+
101
+ **Here's a more complete example:**
102
+
103
+ With this configuration:
104
+
105
+ ```yml
106
+
107
+ # _data/picture.yml
108
+
109
+ media_presets:
110
+ mobile: 'max-width: 600px'
111
+
112
+ markup_presets:
113
+ default:
114
+ widths: [600, 900, 1200]
115
+ formats: [webp, original]
116
+ sizes:
117
+ mobile: 80vw
118
+ size: 500px
119
+
120
+ ```
121
+
122
+ Write this:
123
+
124
+ `{% picture test.jpg mobile: test2.jpg --alt Alternate Text %}`
125
+
126
+ Get this:
127
+
128
+ ```html
129
+
130
+ <!-- Formatted for readability -->
131
+ <picture>
132
+ <source
133
+ sizes="(max-width: 600px) 80vw, 500px"
134
+ media="(max-width: 600px)"
135
+ type="image/webp"
136
+ srcset="http://localhost:4000/generated/test2-600by338-21bb6f.webp 600w,
137
+ http://localhost:4000/generated/test2-900by506-21bb6f.webp 900w,
138
+ http://localhost:4000/generated/test2-1200by675-21bb6f.webp 1200w">
139
+
140
+ <source
141
+ sizes="(max-width: 600px) 80vw, 500px"
142
+ type="image/webp"
143
+ srcset="http://localhost:4000/generated/test-600by338-195f7d.webp 600w,
144
+ http://localhost:4000/generated/test-900by506-195f7d.webp 900w,
145
+ http://localhost:4000/generated/test-1200by675-195f7d.webp 1200w">
146
+
147
+ <source
148
+ sizes="(max-width: 600px) 80vw, 500px"
149
+ media="(max-width: 600px)"
150
+ type="image/jpeg"
151
+ srcset="http://localhost:4000/generated/test2-600by338-21bb6f.jpg 600w,
152
+ http://localhost:4000/generated/test2-900by506-21bb6f.jpg 900w,
153
+ http://localhost:4000/generated/test2-1200by675-21bb6f.jpg 1200w">
154
+
155
+ <source
156
+ sizes="(max-width: 600px) 80vw, 500px"
157
+ type="image/jpeg"
158
+ srcset="http://localhost:4000/generated/test-600by338-195f7d.jpg 600w,
159
+ http://localhost:4000/generated/test-900by506-195f7d.jpg 900w,
160
+ http://localhost:4000/generated/test-1200by675-195f7d.jpg 1200w">
161
+
162
+ <img
163
+ src="http://localhost:4000/generated/test-800by450-195f7d.jpg"
164
+ alt="Alternate Text">
165
+ </picture>
166
+ ```
167
+
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
+ Jekyll Picture Tag ultimately relies on [ImageMagick](https://www.imagemagick.org/script/index.php)
183
+ for image conversions, so it must be installed on your system. There's a very good chance you
184
+ already have it. If you want to build webp images, you will need to install a webp delegate for it
185
+ as well.
186
+
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
+ # Contribute
761
+
762
+ Report bugs and feature proposals in the
763
+ [Github issue tracker](https://github.com/robwierzbowski/jekyll-picture-tag/issues).
764
+
765
+ Pull requests are encouraged. With a few exceptions, this plugin is written to follow the Rubocop
766
+ default settings (except the frozen string literal comment).
767
+
768
+ If you add a new setting, it is helpful to add a default value (look under `lib/defaults/`) and
769
+ relevant documentation to the readme. Don't let that stop you from submitting a pull request,
770
+ though! Just allow modifications and I'll take care of it.
771
+
772
+ # Release History
773
+
774
+ * 1.2.0 Feb 9, 2019: Add nomarkdown fix, noscript option, relative url option, anchor tag wrappers
775
+ * 1.1.0 Jan 22, 2019: Add direct_url markup format, auto-orient images before stripping metadata.
776
+ * 1.0.2 Jan 18, 2019: Fix ruby version specification
777
+ * 1.0.1 Jan 13, 2019: Added ruby version checking for more helpful error messages when running old versions of ruby.
778
+ * **1.0.0** Nov 27, 2018: Rewrite from the ground up. See [migration.md](/migration.md).
779
+ * 0.2.2 Aug 2, 2013: Bugfixes.
780
+ * 0.2.1 Jul 17, 2013: Refactor again, add Liquid parsing.
781
+ * 0.2.0 Jul 14, 2013: Rewrite code base, bring in line with Jekyll Image Tag.
782
+ * 0.1.1 Jul 5, 2013: Quick round of code improvements.
783
+ * 0.1.0 Jul 5, 2013: Initial release.
784
+
785
+ # License
786
+
787
+ [BSD-NEW](http://en.wikipedia.org/wiki/BSD_License)