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.
- checksums.yaml +4 -4
- data/.envrc +2 -0
- data/.github/workflows/code-checks.yml +43 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +30 -0
- data/.ruby-version +1 -1
- data/docs/.envrc +2 -0
- data/docs/Gemfile +4 -2
- data/docs/Gemfile.lock +14 -12
- data/docs/_config.yml +6 -10
- data/docs/devs/contributing/code.md +46 -0
- data/docs/devs/contributing/docs.md +31 -0
- data/docs/devs/contributing/index.md +15 -0
- data/docs/devs/contributing/setup.md +33 -0
- data/docs/devs/contributing/testing.md +34 -0
- data/docs/devs/index.md +7 -0
- data/docs/{releases.md → devs/releases.md} +44 -15
- data/docs/index.md +42 -26
- data/docs/users/configuration/directories.md +34 -0
- data/docs/users/configuration/disable.md +24 -0
- data/docs/users/configuration/fast_build.md +28 -0
- data/docs/users/configuration/ignore_missing.md +23 -0
- data/docs/users/configuration/index.md +29 -0
- data/docs/users/configuration/kramdown_fix.md +20 -0
- data/docs/users/configuration/suppress_warnings.md +16 -0
- data/docs/users/configuration/urls.md +69 -0
- data/docs/users/index.md +7 -0
- data/docs/users/installation.md +52 -0
- data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
- data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
- data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
- data/docs/users/liquid_tag/argument_reference/crop.md +48 -0
- data/docs/users/liquid_tag/argument_reference/link.md +16 -0
- data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
- data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
- data/docs/users/liquid_tag/examples.md +93 -0
- data/docs/users/liquid_tag/index.md +31 -0
- data/docs/users/notes/git_lfs.md +7 -0
- data/docs/users/notes/github_pages.md +5 -0
- data/docs/users/notes/html_attributes.md +5 -0
- data/docs/users/notes/index.md +6 -0
- data/docs/users/notes/input_checking.md +6 -0
- data/docs/users/notes/kramdown_bug.md +41 -0
- data/docs/users/notes/managing_images.md +21 -0
- data/docs/{migration.md → users/notes/migration.md} +0 -0
- data/docs/users/presets/cropping.md +61 -0
- data/docs/users/presets/default.md +24 -0
- data/docs/users/presets/examples.md +79 -0
- data/docs/users/presets/fallback_image.md +28 -0
- data/docs/users/presets/html_attributes.md +26 -0
- data/docs/users/presets/image_formats.md +21 -0
- data/docs/users/presets/image_quality.md +105 -0
- data/docs/users/presets/index.md +101 -0
- data/docs/users/presets/link_source.md +16 -0
- data/docs/users/presets/markup_formats/fragments.md +48 -0
- data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
- data/docs/users/presets/markup_formats/readme.md +43 -0
- data/docs/users/presets/markup_formats/standard_html.md +25 -0
- data/docs/users/presets/media_queries.md +36 -0
- data/docs/users/presets/nomarkdown_override.md +17 -0
- data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
- data/docs/users/presets/quality_width_graph.png +0 -0
- data/docs/users/presets/strip_metadata.md +13 -0
- data/docs/users/presets/width_height_attributes.md +34 -0
- data/docs/users/presets/width_srcsets.md +85 -0
- data/install_imagemagick.sh +23 -0
- data/jekyll_picture_tag.gemspec +10 -6
- data/lib/jekyll_picture_tag.rb +5 -5
- data/lib/jekyll_picture_tag/cache.rb +3 -0
- data/lib/jekyll_picture_tag/cache/base.rb +61 -0
- data/lib/jekyll_picture_tag/cache/generated.rb +20 -0
- data/lib/jekyll_picture_tag/cache/source.rb +19 -0
- data/lib/jekyll_picture_tag/defaults/global.yml +2 -0
- data/lib/jekyll_picture_tag/defaults/presets.yml +2 -0
- data/lib/jekyll_picture_tag/images.rb +3 -0
- data/lib/jekyll_picture_tag/images/generated_image.rb +130 -0
- data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +4 -1
- data/lib/jekyll_picture_tag/images/source_image.rb +103 -0
- data/lib/jekyll_picture_tag/instructions/arg_splitter.rb +3 -2
- data/lib/jekyll_picture_tag/instructions/preset.rb +24 -4
- data/lib/jekyll_picture_tag/instructions/set.rb +5 -1
- data/lib/jekyll_picture_tag/output_formats/basic.rb +16 -14
- data/lib/jekyll_picture_tag/output_formats/img.rb +11 -0
- data/lib/jekyll_picture_tag/output_formats/picture.rb +22 -0
- data/lib/jekyll_picture_tag/router.rb +3 -2
- data/lib/jekyll_picture_tag/srcsets/basic.rb +10 -1
- data/lib/jekyll_picture_tag/utils.rb +14 -0
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +13 -10
- metadata +139 -46
- data/.travis.yml +0 -8
- data/docs/_layouts/directory.html +0 -32
- data/docs/assets/style.css +0 -31
- data/docs/contributing.md +0 -109
- data/docs/example_presets.md +0 -116
- data/docs/global_configuration.md +0 -173
- data/docs/installation.md +0 -45
- data/docs/notes.md +0 -91
- data/docs/output.md +0 -63
- data/docs/presets.md +0 -361
- data/docs/usage.md +0 -143
- data/lib/jekyll_picture_tag/generated_image.rb +0 -161
- data/lib/jekyll_picture_tag/source_image.rb +0 -87
data/docs/usage.md
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
---
|
2
|
-
---
|
3
|
-
|
4
|
-
# How to use the Liquid Tag:
|
5
|
-
|
6
|
-
## Format:
|
7
|
-
|
8
|
-
{% raw %}
|
9
|
-
`{% picture [preset] (image) [crop] [alternate images & crops] [attributes] %}`
|
10
|
-
{% endraw %}
|
11
|
-
|
12
|
-
The only required argument is the base image. Line breaks and extra spaces are fine, and you can
|
13
|
-
use liquid variables anywhere.
|
14
|
-
|
15
|
-
## Examples:
|
16
|
-
|
17
|
-
{% raw %}
|
18
|
-
`{% picture example.jpg %}`
|
19
|
-
|
20
|
-
`{% picture thumbnail example.jpg 1:1 --alt Example Image %}`
|
21
|
-
|
22
|
-
`{% picture example.jpg 16:9 north --picture class="attribute-demo" %}`
|
23
|
-
|
24
|
-
`{% picture blog_index {{ post.image }} --link {{ post.url }} %}`
|
25
|
-
|
26
|
-
`{% picture "some example.jpg" mobile: other\ example.jpg %}`
|
27
|
-
|
28
|
-
```md
|
29
|
-
{% picture
|
30
|
-
hero
|
31
|
-
example.jpg 16:9 east
|
32
|
-
tablet: example_cropped.jpg 3:2 east
|
33
|
-
mobile: example_cropped_more.jpg 1:1-50+0 east
|
34
|
-
--alt Happy Puppy
|
35
|
-
--picture class="hero"
|
36
|
-
--link /
|
37
|
-
%}
|
38
|
-
```
|
39
|
-
|
40
|
-
{% endraw %}
|
41
|
-
|
42
|
-
## Argument reference
|
43
|
-
|
44
|
-
Given in order:
|
45
|
-
|
46
|
-
- **Preset**
|
47
|
-
|
48
|
-
Select a [markup preset]({{ site.baseurl }}/presets#markup-presets), or omit to use the `default` preset. Presets
|
49
|
-
are collections of settings that determine nearly everything about JPT's output, from the image
|
50
|
-
formats used to the exact format your markup will take.
|
51
|
-
|
52
|
-
- **Base Image** (Required)
|
53
|
-
|
54
|
-
Can be any raster image (as long as you have the required ImageMagick delegate). Relative to
|
55
|
-
jekyll's root directory, or the `source` [setting]({{ site.baseurl }}/global_configuration) if you've configured it.
|
56
|
-
|
57
|
-
For filenames with spaces, either use double quotes (`"my image.jpg"`) or a backslash (`my\ image.jpg`).
|
58
|
-
|
59
|
-
- **Crop**
|
60
|
-
|
61
|
-
**Check the [ installation guide ](installation) before using this feature.**
|
62
|
-
|
63
|
-
Crop an image to a given aspect ratio or size. This argument is given as a `geometry` and
|
64
|
-
(optionally) a `gravity`, which can appear in either order and are thin wrappers around
|
65
|
-
ImageMagick's [geometry](http://www.imagemagick.org/script/command-line-processing.php#geometry)
|
66
|
-
and [gravity](http://www.imagemagick.org/script/command-line-options.php#gravity) settings. The
|
67
|
-
values given here will override the preset settings (if present), can be given after every image,
|
68
|
-
and apply only to the preceding image.
|
69
|
-
|
70
|
-
Geometry can take many forms, but most likely you'll want to set an aspect ratio-- given in the
|
71
|
-
standard `width:height` ratio such as `3:2`. Gravity sets which portion of the image to keep, and
|
72
|
-
is given in compass directions (`north`, `southeast`, etc) or `center` (default). Cropping happens
|
73
|
-
before resizing; the preset `widths` setting is a post-crop value.
|
74
|
-
|
75
|
-
If you'd like more fine-grained control, this can be offset by appending `+|-x` and (optionally)
|
76
|
-
`y` pixel values to the _geometry_ (not the gravity!). Example: `1:1+400 west` means "Crop to a
|
77
|
-
1:1 aspect ratio, starting 400 pixels from the left side.", and `north 3:2+0+100` means "Crop to
|
78
|
-
3:2, starting 100 pixels from the top." These can get a bit persnickety; there's nothing to stop
|
79
|
-
you from running off the side of the image. Pay attention.
|
80
|
-
|
81
|
-
For detailed documentation, see ImageMagick's
|
82
|
-
[crop](http://www.imagemagick.org/script/command-line-options.php#crop) tool.
|
83
|
-
|
84
|
-
_Note:_ If you do a lot of trial and error with these, it's a good idea to manually delete your
|
85
|
-
generated images folder more often as each change will build a new set of images without removing
|
86
|
-
the old ones.
|
87
|
-
|
88
|
-
- **Alternate images**
|
89
|
-
|
90
|
-
_Format:_ `(media query preset): (filename) (...)`
|
91
|
-
|
92
|
-
_Example:_ `tablet: img_cropped.jpg mobile: img_cropped_more.jpg`
|
93
|
-
|
94
|
-
Optionally specify any number of alternate base images for given [screen
|
95
|
-
sizes]({{ site.baseurl }}/presets/#media-presets) (specified in `_data/picture.yml`). This is called [art
|
96
|
-
direction](http://usecases.responsiveimages.org/#art-direction), and is one of JPT's strongest
|
97
|
-
features.
|
98
|
-
|
99
|
-
Give your images in order of ascending specificity (The first image is the most general). They will
|
100
|
-
be provided to the browser in reverse order, and it will select the first one with an applicable
|
101
|
-
media query.
|
102
|
-
|
103
|
-
- **Attributes**
|
104
|
-
|
105
|
-
Optionally specify any number of HTML attributes, or an href target. These will be added to any
|
106
|
-
attributes you've set in a preset.
|
107
|
-
|
108
|
-
- **`--link`**
|
109
|
-
|
110
|
-
_Format:_ `--link (some url)`
|
111
|
-
|
112
|
-
_Examples_: `--link https://example.com`, `--link /blog/some_post/`
|
113
|
-
|
114
|
-
Wrap the image in an anchor tag, with the `href` attribute set to whatever value you give it.
|
115
|
-
This will override automatic source image linking, if you have enabled it.
|
116
|
-
|
117
|
-
**Note**: If you get either mangled HTML or extra {::nomarkdown} tags when using this, read
|
118
|
-
[here]({{ site.baseurl }}/notes).
|
119
|
-
|
120
|
-
- **`--alt`**
|
121
|
-
|
122
|
-
_Format:_ `--alt (alt text)`
|
123
|
-
|
124
|
-
_Example:_ `--alt Here is my alt text!`
|
125
|
-
|
126
|
-
Convenience shortcut for `--img alt="..."`
|
127
|
-
|
128
|
-
- **`--(element)`**
|
129
|
-
|
130
|
-
_Format:_ `--(picture|img|source|a|parent) (Standard HTML attributes)`
|
131
|
-
|
132
|
-
_Example:_ `--img class="awesome-fade-in" id="coolio" --a data-awesomeness="11"`
|
133
|
-
|
134
|
-
Apply attributes to a given HTML element. Your options are:
|
135
|
-
|
136
|
-
- `picture`
|
137
|
-
- `img`
|
138
|
-
- `source`
|
139
|
-
- `a` (anchor tag)
|
140
|
-
- `parent`
|
141
|
-
|
142
|
-
`--parent` will be applied to the `<picture>` if present, otherwise the `<img>`; useful when
|
143
|
-
using an `auto` output format.
|
@@ -1,161 +0,0 @@
|
|
1
|
-
require 'mini_magick'
|
2
|
-
require 'base32'
|
3
|
-
|
4
|
-
module PictureTag
|
5
|
-
# Represents a generated image file.
|
6
|
-
class GeneratedImage
|
7
|
-
attr_reader :width, :format
|
8
|
-
include MiniMagick
|
9
|
-
|
10
|
-
def initialize(source_file:, width:, format:, crop: nil, gravity: '')
|
11
|
-
@source = source_file
|
12
|
-
@width = width
|
13
|
-
@format = process_format format
|
14
|
-
@crop = crop
|
15
|
-
@gravity = gravity
|
16
|
-
end
|
17
|
-
|
18
|
-
def exists?
|
19
|
-
File.exist?(absolute_filename)
|
20
|
-
end
|
21
|
-
|
22
|
-
def generate
|
23
|
-
generate_image unless @source.missing || exists?
|
24
|
-
end
|
25
|
-
|
26
|
-
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
27
|
-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
28
|
-
def absolute_filename
|
29
|
-
@absolute_filename ||= File.join(PictureTag.dest_dir, name)
|
30
|
-
end
|
31
|
-
|
32
|
-
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
33
|
-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
34
|
-
def name
|
35
|
-
name_left + digest + name_right
|
36
|
-
end
|
37
|
-
|
38
|
-
# https://example.com/assets/images/myimage-100-123abc.jpg
|
39
|
-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
40
|
-
def uri
|
41
|
-
ImgURI.new(name).to_s
|
42
|
-
end
|
43
|
-
|
44
|
-
def cropped_source_width
|
45
|
-
image.width
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
51
|
-
# ^^^^^^^^^^^^^^^^^^^^^^^
|
52
|
-
def name_left
|
53
|
-
"#{@source.base_name}-#{@width}-"
|
54
|
-
end
|
55
|
-
|
56
|
-
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
57
|
-
# ^^^^^^
|
58
|
-
def digest
|
59
|
-
guess_digest if !@source.digest_guess && PictureTag.fast_build?
|
60
|
-
|
61
|
-
@source.digest
|
62
|
-
end
|
63
|
-
|
64
|
-
# /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
|
65
|
-
# ^^^^
|
66
|
-
def name_right
|
67
|
-
crop_code + '.' + @format
|
68
|
-
end
|
69
|
-
|
70
|
-
# Hash the crop settings, so we can detect when they change. We use a
|
71
|
-
# base32 encoding scheme to pack more information into fewer characters,
|
72
|
-
# without dealing with various filesystem naming limitations that would crop
|
73
|
-
# up using base64 (such as NTFS being case insensitive).
|
74
|
-
def crop_code
|
75
|
-
return '' unless @crop
|
76
|
-
|
77
|
-
Base32.encode(
|
78
|
-
Digest::MD5.hexdigest(@crop + @gravity)
|
79
|
-
)[0..2]
|
80
|
-
end
|
81
|
-
|
82
|
-
# Used for the fast build option: look for a file which matches everything
|
83
|
-
# we know about the destination file without calculating a digest on the
|
84
|
-
# source file, and if it exists we assume it's the right one.
|
85
|
-
def guess_digest
|
86
|
-
matches = dest_glob
|
87
|
-
return unless matches.length == 1
|
88
|
-
|
89
|
-
# Start and finish of the destination image's hash value
|
90
|
-
finish = -name_right.length
|
91
|
-
start = finish - 6
|
92
|
-
|
93
|
-
# The source image keeps track of this guess, so we hand it off:
|
94
|
-
@source.digest_guess = matches.first[start...finish]
|
95
|
-
end
|
96
|
-
|
97
|
-
# Returns a list of images which are probably correct.
|
98
|
-
def dest_glob
|
99
|
-
query = File.join(
|
100
|
-
PictureTag.dest_dir,
|
101
|
-
name_left + '?' * 6 + name_right
|
102
|
-
)
|
103
|
-
|
104
|
-
Dir.glob query
|
105
|
-
end
|
106
|
-
|
107
|
-
def generate_image
|
108
|
-
puts 'Generating new image file: ' + name
|
109
|
-
process_image
|
110
|
-
write_image
|
111
|
-
end
|
112
|
-
|
113
|
-
def image
|
114
|
-
@image ||= open_image
|
115
|
-
end
|
116
|
-
|
117
|
-
def open_image
|
118
|
-
image_base = Image.open(@source.name)
|
119
|
-
image_base.combine_options do |i|
|
120
|
-
i.auto_orient
|
121
|
-
if @crop
|
122
|
-
i.gravity @gravity
|
123
|
-
i.crop @crop
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
image_base
|
128
|
-
end
|
129
|
-
|
130
|
-
def process_image
|
131
|
-
image.combine_options do |i|
|
132
|
-
i.resize "#{@width}x"
|
133
|
-
i.strip
|
134
|
-
end
|
135
|
-
|
136
|
-
image.format @format
|
137
|
-
image.quality PictureTag.quality(@format)
|
138
|
-
end
|
139
|
-
|
140
|
-
def write_image
|
141
|
-
# Make sure destination directory exists:
|
142
|
-
FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
|
143
|
-
|
144
|
-
image.write absolute_filename
|
145
|
-
|
146
|
-
FileUtils.chmod(0o644, absolute_filename)
|
147
|
-
end
|
148
|
-
|
149
|
-
def dest_dir
|
150
|
-
File.dirname absolute_filename
|
151
|
-
end
|
152
|
-
|
153
|
-
def process_format(format)
|
154
|
-
if format.casecmp('original').zero?
|
155
|
-
@source.ext
|
156
|
-
else
|
157
|
-
format.downcase
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module PictureTag
|
2
|
-
# Handles a given source image file and its properties. Provides a speed
|
3
|
-
# advantage by storing expensive file reads and writes in instance variables,
|
4
|
-
# to be reused by many different generated images.
|
5
|
-
class SourceImage
|
6
|
-
attr_reader :name, :shortname, :missing, :media_preset
|
7
|
-
attr_accessor :digest_guess
|
8
|
-
include MiniMagick
|
9
|
-
|
10
|
-
def initialize(relative_filename, media_preset = nil)
|
11
|
-
@shortname = relative_filename
|
12
|
-
@name = grab_file relative_filename
|
13
|
-
@media_preset = media_preset
|
14
|
-
end
|
15
|
-
|
16
|
-
def width
|
17
|
-
@width ||= if @missing
|
18
|
-
999_999
|
19
|
-
else
|
20
|
-
image.width
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def digest
|
25
|
-
@digest ||= if @missing
|
26
|
-
'x' * 6
|
27
|
-
elsif PictureTag.fast_build? && @digest_guess
|
28
|
-
# Digest guess will be handed off to this class by the first
|
29
|
-
# generated image which needs it (via attr_accessor).
|
30
|
-
@digest_guess
|
31
|
-
else
|
32
|
-
Digest::MD5.hexdigest(File.read(@name))[0..5]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Includes path relative to default source folder and the original filename.
|
37
|
-
def base_name
|
38
|
-
@shortname.delete_suffix File.extname(@shortname)
|
39
|
-
end
|
40
|
-
|
41
|
-
# File exention
|
42
|
-
def ext
|
43
|
-
# [1..-1] will strip the leading period.
|
44
|
-
@ext ||= File.extname(@name)[1..-1].downcase
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def image
|
50
|
-
@image ||= Image.open(@name)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Turn a relative filename into an absolute one, and make sure it exists.
|
54
|
-
def grab_file(source_file)
|
55
|
-
source_name = File.join(PictureTag.source_dir, source_file)
|
56
|
-
|
57
|
-
if File.exist? source_name
|
58
|
-
@missing = false
|
59
|
-
|
60
|
-
elsif PictureTag.continue_on_missing?
|
61
|
-
@missing = true
|
62
|
-
Utils.warning missing_image_warning(source_name)
|
63
|
-
|
64
|
-
else
|
65
|
-
raise ArgumentError, missing_image_error(source_name)
|
66
|
-
end
|
67
|
-
|
68
|
-
source_name
|
69
|
-
end
|
70
|
-
|
71
|
-
def missing_image_warning(source_name)
|
72
|
-
<<~HEREDOC
|
73
|
-
Could not find #{source_name}. Your site will have broken images in it.
|
74
|
-
Continuing.
|
75
|
-
HEREDOC
|
76
|
-
end
|
77
|
-
|
78
|
-
def missing_image_error(source_name)
|
79
|
-
<<~HEREDOC
|
80
|
-
Jekyll Picture Tag could not find #{source_name}. You can force the
|
81
|
-
build to continue anyway by setting "picture: ignore_missing_images:
|
82
|
-
true" in "_config.yml". This setting can also accept a jekyll build
|
83
|
-
environment, or an array of environments.
|
84
|
-
HEREDOC
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|