jekyll_picture_tag 1.10.1 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +2 -0
  3. data/.github/workflows/code-checks.yml +43 -0
  4. data/.gitignore +3 -0
  5. data/.rubocop.yml +30 -0
  6. data/.ruby-version +1 -1
  7. data/docs/.envrc +2 -0
  8. data/docs/Gemfile +4 -2
  9. data/docs/Gemfile.lock +14 -12
  10. data/docs/_config.yml +6 -10
  11. data/docs/devs/contributing/code.md +46 -0
  12. data/docs/devs/contributing/docs.md +31 -0
  13. data/docs/devs/contributing/index.md +15 -0
  14. data/docs/devs/contributing/setup.md +33 -0
  15. data/docs/devs/contributing/testing.md +34 -0
  16. data/docs/devs/index.md +7 -0
  17. data/docs/{releases.md → devs/releases.md} +44 -15
  18. data/docs/index.md +42 -26
  19. data/docs/users/configuration/directories.md +34 -0
  20. data/docs/users/configuration/disable.md +24 -0
  21. data/docs/users/configuration/fast_build.md +28 -0
  22. data/docs/users/configuration/ignore_missing.md +23 -0
  23. data/docs/users/configuration/index.md +29 -0
  24. data/docs/users/configuration/kramdown_fix.md +20 -0
  25. data/docs/users/configuration/suppress_warnings.md +16 -0
  26. data/docs/users/configuration/urls.md +69 -0
  27. data/docs/users/index.md +7 -0
  28. data/docs/users/installation.md +52 -0
  29. data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
  30. data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
  31. data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
  32. data/docs/users/liquid_tag/argument_reference/crop.md +48 -0
  33. data/docs/users/liquid_tag/argument_reference/link.md +16 -0
  34. data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
  35. data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
  36. data/docs/users/liquid_tag/examples.md +93 -0
  37. data/docs/users/liquid_tag/index.md +31 -0
  38. data/docs/users/notes/git_lfs.md +7 -0
  39. data/docs/users/notes/github_pages.md +5 -0
  40. data/docs/users/notes/html_attributes.md +5 -0
  41. data/docs/users/notes/index.md +6 -0
  42. data/docs/users/notes/input_checking.md +6 -0
  43. data/docs/users/notes/kramdown_bug.md +41 -0
  44. data/docs/users/notes/managing_images.md +21 -0
  45. data/docs/{migration.md → users/notes/migration.md} +0 -0
  46. data/docs/users/presets/cropping.md +61 -0
  47. data/docs/users/presets/default.md +24 -0
  48. data/docs/users/presets/examples.md +79 -0
  49. data/docs/users/presets/fallback_image.md +28 -0
  50. data/docs/users/presets/html_attributes.md +26 -0
  51. data/docs/users/presets/image_formats.md +21 -0
  52. data/docs/users/presets/image_quality.md +105 -0
  53. data/docs/users/presets/index.md +101 -0
  54. data/docs/users/presets/link_source.md +16 -0
  55. data/docs/users/presets/markup_formats/fragments.md +48 -0
  56. data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
  57. data/docs/users/presets/markup_formats/readme.md +43 -0
  58. data/docs/users/presets/markup_formats/standard_html.md +25 -0
  59. data/docs/users/presets/media_queries.md +36 -0
  60. data/docs/users/presets/nomarkdown_override.md +17 -0
  61. data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
  62. data/docs/users/presets/quality_width_graph.png +0 -0
  63. data/docs/users/presets/strip_metadata.md +13 -0
  64. data/docs/users/presets/width_height_attributes.md +34 -0
  65. data/docs/users/presets/width_srcsets.md +85 -0
  66. data/install_imagemagick.sh +23 -0
  67. data/jekyll_picture_tag.gemspec +10 -6
  68. data/lib/jekyll_picture_tag.rb +5 -5
  69. data/lib/jekyll_picture_tag/cache.rb +3 -0
  70. data/lib/jekyll_picture_tag/cache/base.rb +61 -0
  71. data/lib/jekyll_picture_tag/cache/generated.rb +20 -0
  72. data/lib/jekyll_picture_tag/cache/source.rb +19 -0
  73. data/lib/jekyll_picture_tag/defaults/global.yml +2 -0
  74. data/lib/jekyll_picture_tag/defaults/presets.yml +2 -0
  75. data/lib/jekyll_picture_tag/images.rb +3 -0
  76. data/lib/jekyll_picture_tag/images/generated_image.rb +130 -0
  77. data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +4 -1
  78. data/lib/jekyll_picture_tag/images/source_image.rb +103 -0
  79. data/lib/jekyll_picture_tag/instructions/arg_splitter.rb +3 -2
  80. data/lib/jekyll_picture_tag/instructions/preset.rb +24 -4
  81. data/lib/jekyll_picture_tag/instructions/set.rb +5 -1
  82. data/lib/jekyll_picture_tag/output_formats/basic.rb +16 -14
  83. data/lib/jekyll_picture_tag/output_formats/img.rb +11 -0
  84. data/lib/jekyll_picture_tag/output_formats/picture.rb +22 -0
  85. data/lib/jekyll_picture_tag/router.rb +3 -2
  86. data/lib/jekyll_picture_tag/srcsets/basic.rb +10 -1
  87. data/lib/jekyll_picture_tag/utils.rb +14 -0
  88. data/lib/jekyll_picture_tag/version.rb +1 -1
  89. data/readme.md +13 -10
  90. metadata +139 -46
  91. data/.travis.yml +0 -8
  92. data/docs/_layouts/directory.html +0 -32
  93. data/docs/assets/style.css +0 -31
  94. data/docs/contributing.md +0 -109
  95. data/docs/example_presets.md +0 -116
  96. data/docs/global_configuration.md +0 -173
  97. data/docs/installation.md +0 -45
  98. data/docs/notes.md +0 -91
  99. data/docs/output.md +0 -63
  100. data/docs/presets.md +0 -361
  101. data/docs/usage.md +0 -143
  102. data/lib/jekyll_picture_tag/generated_image.rb +0 -161
  103. data/lib/jekyll_picture_tag/source_image.rb +0 -87
@@ -0,0 +1,18 @@
1
+ ---
2
+ sort: 4
3
+ ---
4
+
5
+ # Alternate images
6
+
7
+ _Format:_ `(media_query): (filename) [crop] [gravity] (...)`
8
+
9
+ _Example:_ `tablet: img_cropped.jpg mobile: img_cropped_more.jpg`
10
+
11
+ Optionally specify any number of alternate base images for given
12
+ [media_queries]({{ site.baseurl }}/users/presets/media_queries). This is called
13
+ [art direction](http://usecases.responsiveimages.org/#art-direction), and is one
14
+ of JPT's strongest features.
15
+
16
+ Give your images in order of ascending specificity (The first image is the
17
+ most general). They will be provided to the browser in reverse order, and it
18
+ will select the first one with an applicable media query.
@@ -0,0 +1,42 @@
1
+ ---
2
+ sort: 6
3
+ ---
4
+
5
+ # Attributes
6
+
7
+ Optionally specify any number of HTML attributes. These will be combined with
8
+ any which you've set in a preset.
9
+
10
+ All arguments which begin with `--` (including `--link`) must be at the end of
11
+ the liquid tag, but they can be given in any order.
12
+
13
+ - **`--alt`**
14
+
15
+ _Format:_ `--alt (alt text)`
16
+
17
+ _Example:_ `--alt Here is my alt text!`
18
+
19
+ Convenience shortcut for `--img alt="..."`
20
+
21
+ - **`--(element)`**
22
+
23
+ _Format:_ `--(picture|img|source|a|parent) (Standard HTML attributes)`
24
+
25
+ _Example:_ `--img class="awesome-fade-in" id="coolio" --a data-awesomeness="11"`
26
+
27
+ Apply attributes to a given HTML element. Your options are:
28
+
29
+ - `--picture`
30
+ - `--img`
31
+ - `--source`
32
+ - `--a` (anchor tag)
33
+ - `--parent`
34
+
35
+ `--parent` will be applied to the `<picture>` if present, otherwise the
36
+ `<img>`; useful when using an `auto` output format.
37
+
38
+ ```note
39
+ Attributes that are set here for elements which don't occur in the selected
40
+ markup format will be ignored (e.g. adding `--picture class="cool-css"` with a
41
+ preset that does not use a `<picture>` tag).
42
+ ```
@@ -0,0 +1,12 @@
1
+ ---
2
+ sort: 2
3
+ ---
4
+
5
+ # Base Image (Required)
6
+
7
+ Can be any raster image (as long as you have the required ImageMagick delegate).
8
+ Relative to Jekyll's root directory, or the `source` [setting]({{ site.baseurl
9
+ }}/users/configuration/directories) if you've configured it.
10
+
11
+ For filenames with spaces, either use double quotes (`"my image.jpg"`) or a
12
+ backslash (`my\ image.jpg`).
@@ -0,0 +1,48 @@
1
+ ---
2
+ sort: 3
3
+ ---
4
+
5
+ # Crop
6
+
7
+ ```warning
8
+ Ensure that both your development and production build environments have
9
+ ImageMagick 7+ installed before using this feature. Anything based on Ubuntu
10
+ likely does not. The installation guide has more information.
11
+ ```
12
+
13
+ Crop an image to a given aspect ratio or size. This argument is given as a
14
+ `geometry` and (optionally) a `gravity`, which can appear in either order and
15
+ are thin wrappers around ImageMagick's
16
+ [geometry](http://www.imagemagick.org/script/command-line-processing.php#geometry)
17
+ and
18
+ [gravity](http://www.imagemagick.org/script/command-line-options.php#gravity)
19
+ settings. The values given here will override the preset settings (if present),
20
+ can be given after every image, and apply only to the preceding image.
21
+
22
+ Geometry can take many forms, but most likely you'll want to set an aspect
23
+ ratio-- given in the standard `width:height` ratio such as `3:2`. Gravity sets
24
+ which portion of the image to keep, and is given in compass directions (`north`,
25
+ `southeast`, etc) or `center` (default). Cropping happens before resizing; the
26
+ preset `widths` setting is a post-crop value.
27
+
28
+ If you'd like more fine-grained control, this can be offset by appending `+|-x`
29
+ and (optionally) `y` pixel values to the _geometry_ (not the gravity!). Example:
30
+ `1:1+400 west` means "Crop to a 1:1 aspect ratio, starting 400 pixels from the
31
+ left side.", and `north 3:2+0+100` means "Crop to 3:2, starting 100 pixels from
32
+ the top." These can get a bit persnickety; there's nothing to stop you from
33
+ running off the side of the image. Pay attention.
34
+
35
+ For detailed documentation, see ImageMagick's
36
+ [crop](http://www.imagemagick.org/script/command-line-options.php#crop) tool.
37
+
38
+ ## Examples
39
+
40
+ - `16:9`
41
+ - `1:1 west`
42
+ - `3:2+20+50 northeast`
43
+
44
+ ```note
45
+ If you do a lot of trial and error with these, it's a good idea to manually
46
+ delete your generated images folder more often as each change will build a new
47
+ set of images without removing the old ones.
48
+ ```
@@ -0,0 +1,16 @@
1
+ ---
2
+ sort: 5
3
+ ---
4
+
5
+ # Link
6
+
7
+ _Format:_ `--link (some url)`
8
+
9
+ _Examples_: `--link https://example.com`, `--link /blog/some_post/`
10
+
11
+ Wrap the image in an anchor tag, with the `href` attribute set to whatever
12
+ value you give it. This will override automatic source image linking, if you
13
+ have enabled it.
14
+
15
+ **Note**: If you get either mangled HTML or extra {::nomarkdown} tags when
16
+ using this, read [here]({{ site.baseurl }}/users/notes/kramdown_bug).
@@ -0,0 +1,17 @@
1
+ ---
2
+ sort: 1
3
+ ---
4
+
5
+ # Preset
6
+
7
+ Select a [preset]({{ site.baseurl }}/users/presets), or omit to
8
+ use the `default` preset. A preset is a collection of settings which determines
9
+ nearly everything about JPT's output, from the image formats used to the exact
10
+ format your final HTML will take. Think of it like a recipe or a blueprint; JPT
11
+ will take the information provided in the liquid tag, combine it with the
12
+ settings written in the preset, and use it to craft your images and markup.
13
+
14
+ If the `preset` is omitted then default settings will be used, in the simplest
15
+ case resulting in an `<img>` tag containing a srcset pointing to your newly
16
+ generated images. You are free to override the `default` preset and define
17
+ your own settings, giving full flexibility in what JPT will create.
@@ -0,0 +1,9 @@
1
+ ---
2
+ sort: 3
3
+ ---
4
+
5
+ # Argument Reference
6
+
7
+ Given in order:
8
+
9
+ {% include list.liquid %}
@@ -0,0 +1,93 @@
1
+ ---
2
+ ---
3
+ # Examples
4
+
5
+ {% raw %}
6
+
7
+ * Basic form, will use the preset named 'default':
8
+ ```
9
+ {% picture example.jpg %}
10
+ ```
11
+
12
+ * Include alt text:
13
+ ```
14
+ {% picture example.jpg --alt Alt Text %}
15
+ ```
16
+
17
+ * Select a `preset` (defined in `_data/picture.yml`:
18
+ ```
19
+ {% picture my_preset example.jpg %}
20
+ ```
21
+
22
+ * Show different images on different devices. (Note that `mobile` must be set
23
+ to some media query under `media_queries:` in `_data/picture.yml`.
24
+ ```
25
+ {% picture example.jpg mobile: example_cropped.jpg %}
26
+ ```
27
+
28
+ * Use liquid variables:
29
+ ```
30
+ {% picture {{ page.some_liquid_variable }} %}
31
+ ```
32
+
33
+ * Select the blog_index preset, use liquid variables, and wrap the image in an
34
+ anchor tag (link):
35
+ ```
36
+ {% picture blog_index {{ post.image }} --link {{ post.url }} %}
37
+ ```
38
+ N.B. If the image path is coming from a liquid variable then you have two problems to guard against.
39
+ * __Spaces__: you need to wrap the inner tag in "" to stop a path with spaces being interpretted as two or more arguments:
40
+ ```
41
+ {% picture blog_index "{{ post.image }}" %}
42
+ ```
43
+ * __Nulls & Blanks__: you need to wrap whole tag in a logic block to stop an uncaught Liquid exception:
44
+ ```
45
+ {% if post.image && post.image != "" %}
46
+ {% picture blog_index "{{ post.image }}" %}
47
+ {% endif %}
48
+ ```
49
+
50
+
51
+ * Add arbitrary HTML attributes:
52
+ ```
53
+ {% picture example.jpg --picture class="some classes" --img id="example" %}
54
+ ```
55
+
56
+ ```warning
57
+ Read the whole installation guide before using the crop feature.
58
+ ```
59
+
60
+ * Crop to a 16:9 aspect ratio, keeping the top:
61
+ ```
62
+ {% picture example.jpg 16:9 north %}
63
+ ```
64
+
65
+ * Crop to a 1:1 aspect ratio, keeping the middle, with alt text:
66
+ ```
67
+ {% picture thumbnail example.jpg 1:1 --alt Example Image %}
68
+ ```
69
+
70
+ * Crop the same image multiple times:
71
+ ```
72
+ {% picture example.jpg 16:9 tablet: example.jpg 4:3 mobile: example.jpg 1:1 %}
73
+ ```
74
+
75
+ * Use filenames with spaces:
76
+ ```
77
+ {% picture "some example.jpg" mobile: other\ example.jpg %}
78
+ ```
79
+
80
+ * Use line breaks to make a complicated tag manageable:
81
+ ```
82
+ {%
83
+ picture
84
+ hero
85
+ example.jpg 16:9 east
86
+ tablet: example2.jpg 3:2 east
87
+ mobile: example3.jpg 1:1-50+0 east
88
+ --alt Happy Puppy
89
+ --picture class="hero"
90
+ --link /
91
+ %}
92
+ ```
93
+ {% endraw %}
@@ -0,0 +1,31 @@
1
+ ---
2
+ sort: 2
3
+ ---
4
+
5
+ # Tag Usage
6
+
7
+ This section describes how to use JPT's liquid tag ({% raw %} `{% picture (...)
8
+ %}` {% endraw %}); what options it takes and what kind of information you can pass
9
+ through it to influence the the final HTML and generated images.
10
+
11
+ ## Format
12
+
13
+ {% raw %}
14
+ `{% picture [preset] (image) [crop] [alternate images & crops] [attributes] %}`
15
+ {% endraw %}
16
+
17
+ The only required argument is the base image. Line breaks and extra spaces are
18
+ fine, and you can use liquid variables anywhere.
19
+
20
+ * `preset` - Select a recipe/blueprint from the ones you have defined in
21
+ `presets`. Will use `default` if not specified.
22
+
23
+ * `(image)` - required.
24
+
25
+ * `crop` - Geometry and gravity arguments, passed to imagemagick.
26
+
27
+ * `alternate images & crops` - Art Direction; show different images on different
28
+ devices. Give in order of ascending specificity.
29
+
30
+ * `attributes` - Add css classes, data-attributes, or wrap the whole thing in an
31
+ anchor tag.
@@ -0,0 +1,7 @@
1
+ # Git LFS
2
+
3
+ I'm Putting this here because it bit me: If you want to use git LFS, make sure that your hosting
4
+ provider makes those images available during the build process. Netlify, for example, does not.
5
+ You won't find this out until you have gone through the entire migration process and try to deploy
6
+ for the first time.
7
+
@@ -0,0 +1,5 @@
1
+ # Github Pages?
2
+
3
+ Github Pages only allows a very short whitelist of plugins, which sadly does not include JPT. You
4
+ can either run it locally, then commit and push the generated files (rather than the source
5
+ files), or just host it some other way. I recommend Netlify.
@@ -0,0 +1,5 @@
1
+ # HTML attributes
2
+
3
+ Jekyll Picture Tag has comprehensive attribute support for all generated HTML. You can add
4
+ attributes both through the [liquid tag]({{ site.baseurl }}/usage), and the [preset]({{
5
+ site.baseurl }}/presets) (scroll down a bit).
@@ -0,0 +1,6 @@
1
+ ---
2
+ sort: 5
3
+ ---
4
+ # Notes and FAQ
5
+
6
+ {% include list.liquid %}
@@ -0,0 +1,6 @@
1
+ # Getting cryptic build errors?
2
+
3
+ Jekyll Picture Tag is very trusting. It doesn't do much checking of your inputs, and it does not
4
+ fail gracefully if you for example pass it a string when it expects an array. It's on the to-do
5
+ list, but for now if you get cryptic errors then double-check your settings and tag arguments.
6
+
@@ -0,0 +1,41 @@
1
+ # Extra {::nomarkdown} tags or mangled HTML?
2
+
3
+ ## TLDR up front
4
+
5
+ There's a bug involving `<picture>` tags wrapped in `<a>` tags which is not in
6
+ my power to fix.
7
+
8
+ * If you're getting extra `{::nomarkdown}` tags floating around your images, add `nomarkdown:
9
+ false` to either the relevant preset or under `picture` in `_config.yml`.
10
+
11
+ * If you're getting mangled HTML when trying to wrap images with anchor tags, add `nomarkdown:
12
+ true` to the preset.
13
+
14
+ ## What's going on here:
15
+
16
+ Kramdown is Jekyll's default markdown parser. Kramdown gets grumpy when you give it a block level
17
+ element (such as a `<picture>`) surrounded by a span level element (such as an `<a>`), and horribly
18
+ mangles it. The fix for this is to tell Kramdown to chill with a `{::nomarkdown}..{:/nomarkdown}`
19
+ wrapper.
20
+
21
+ Jekyll Picture Tag can be called from many different places: a markdown file, an HTML file, an HTML
22
+ layout for a markdown file, and an HTML include, to name a few. JPT tries its best to determine
23
+ whether its output will be parsed by Kramdown or not, but Jekyll itself doesn't make this
24
+ particularly easy which results in some false positives. (The one I'm most aware of is when a
25
+ markdown file uses an HTML layout which includes a picture tag.)
26
+
27
+ Unfortunately, I don't see an easy way to fix this. We've gotten this far mostly by trial and error.
28
+ I'll continue to work on improving the autodetection, but you can override this behavior explicitly.
29
+
30
+ ## The fix:
31
+
32
+ By default, JPT will add a `{::nomarkdown}` tag if all of the following are true:
33
+ * It thinks it's called from a markdown page
34
+ * The image will be wrapped in an anchor tag (i.e. `link_source_image:` or a `--link` parameter)
35
+ * This behavior hasn't been explicitly disabled.
36
+
37
+ You can disable nomarkdown tags globally by setting `nomarkdown: false` under the `picture:` key in
38
+ `_config.yml`.
39
+
40
+ You can enable or disable markdown tags per preset by adding `nomarkdown: true|false` to them.
41
+ **This setting overrides everything else, both JPT autodetection and the global setting.**
@@ -0,0 +1,21 @@
1
+ # Managing Generated Images
2
+
3
+ Jekyll Picture Tag creates resized versions of your images when you build the
4
+ site. It uses a caching system to speed up site compilation, and re-uses images
5
+ as much as possible. Filenames take the following format:
6
+
7
+ `(original name without extension)-(width)-(id-string).(filetype)`
8
+
9
+ Try to use a base image that is larger than the largest resized image you need.
10
+ Jekyll Picture Tag will warn you if a base image is too small, and won't upscale
11
+ images.
12
+
13
+ By specifying a `source` directory that is ignored by Jekyll you can prevent
14
+ huge base images from being copied to the compiled site. For example, `source:
15
+ assets/images/_fullsize` and `output: generated` will result in a compiled site
16
+ that contains resized images but not the originals. Note that this will break
17
+ source image linking, if you wish to enable it. (Can't link to images that
18
+ aren't public!)
19
+
20
+ The `output` directory is never deleted by Jekyll. You may want to empty it once
21
+ in awhile, to clear out unused images.
@@ -0,0 +1,61 @@
1
+ ---
2
+ sort: 5
3
+ ---
4
+
5
+ # Cropping
6
+
7
+ **Check the warning in the
8
+ [installation guide]({{ site.baseurl }}/users/installation)
9
+ before using this feature.**
10
+
11
+ ## Crop & Media Crop
12
+
13
+ _Format:_
14
+
15
+ ```yaml
16
+ crop: (geometery)
17
+ media_crop:
18
+ (media_preset): (geometry)
19
+ (media_preset): (geometry)
20
+ (...)
21
+ ```
22
+
23
+ _Example:_
24
+
25
+ ```yaml
26
+ crop: '16:9'
27
+ media_crop:
28
+ tablet: '3:2'
29
+ mobile: '1:1'
30
+ ```
31
+
32
+ Crop geometry, given either generally or for specific media presets. The
33
+ hierarchy is: `tag argument` > `media_crop:` > `crop:`.
34
+
35
+ This setting accepts the same arguments as the `crop geometry`
36
+ [tag parameter]({{ site.baseurl }}/users/liquid_tag/argument_reference/crop).
37
+
38
+ ## Gravity & Media Gravity
39
+
40
+ ```yaml
41
+ gravity: (gravity)
42
+ media_gravity:
43
+ (media_preset): (gravity)
44
+ (media_preset): (gravity)
45
+ (...)
46
+ ```
47
+
48
+ _Example:_
49
+
50
+ ```yaml
51
+ gravity: north
52
+ media_gravity:
53
+ tablet: east
54
+ mobile: southwest
55
+ ```
56
+
57
+ Crop gravity, given either generally or for specific media presets. The hierarchy is:
58
+ `tag argument` > `media_gravity:` > `gravity:` > `center` (default).
59
+
60
+ This setting accepts the same arguments as the `crop gravity`
61
+ [tag parameter]({{ site.baseurl }}/users/liquid_tag/argument_reference/crop).