jekyll-picture-tag-ng 0.3.1 → 0.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/README.md +84 -1
- data/lib/jekyll-picture-tag-ng/version.rb +1 -1
- data/lib/jekyll-picture-tag-ng.rb +50 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd5f67823462661b93520b765668c3da82794480e4e58a7fb6657b41920c893
|
4
|
+
data.tar.gz: f76fc204106a3dc79fa40dbbb371ac988dcf6f2043a3089d2ab79b24cc6d94c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ea82a06e9626494f78b35a962733ff979f4c9b9c956e56a120290cc9c24930c10b7db29d409c0ec73741100341e5fce63be1d92b86fa54907847975dc4b0f0a
|
7
|
+
data.tar.gz: d967db3c36973c4eb29cca8c45a39b16c8cb9ece0003663c3ac2c11dd24435421d3b87248c15eca243a6cd333b820c7c591ec077e1c3de365efed46e2dd427f5
|
data/README.md
CHANGED
@@ -72,10 +72,93 @@ picture_tag_ng:
|
|
72
72
|
The example above is equivalent to the defaults.
|
73
73
|
|
74
74
|
- `background_color` is the color used to replace transparency when converting from `webp` to `jpeg`
|
75
|
-
- `picture_versions` maps version names to target widths in pixels. The default configuration above produces output files 700px wide in `img/m/` and 400px wide in `img/s/`.
|
75
|
+
- `picture_versions` in the simplest form, maps version names to target widths in pixels. The default configuration above produces output files 700px wide in `img/m/` and 400px wide in `img/s/`. See below for more complex forms.
|
76
76
|
- `parallel` is a boolean indicating if you want to generate the output files in parallel threads. With a website that has a lot of large pictures, I get ~30% speed improvements when generating the site locally.
|
77
77
|
- `threads` is the number of concurrent threads for generating the website (only used if `parallel` is `true`)
|
78
78
|
|
79
|
+
#### `picture_versions` option
|
80
|
+
|
81
|
+
The `picture_versions` option must be a map. The keys are the version identifiers, and the values control the output for each version. The values can be defined in one of the following formats :
|
82
|
+
|
83
|
+
```yaml
|
84
|
+
picture_tag_ng:
|
85
|
+
picture_versions:
|
86
|
+
s: 400
|
87
|
+
```
|
88
|
+
|
89
|
+
When the version consists only of an integer, the value is used for both the output width and the corresponding `max-width` media attribute.
|
90
|
+
|
91
|
+
```yaml
|
92
|
+
picture_tag_ng:
|
93
|
+
picture_versions:
|
94
|
+
s:
|
95
|
+
out_size: 400
|
96
|
+
```
|
97
|
+
|
98
|
+
Each version can be defined as a map, with the `out_size` key being required (must be an integer). This value controls the output width for the version. If `out_size` is the only defined key, it is also used for the corresponding `max-with` media attribute.
|
99
|
+
|
100
|
+
```yaml
|
101
|
+
picture_tag_ng:
|
102
|
+
picture_versions:
|
103
|
+
m:
|
104
|
+
out_size: 700
|
105
|
+
media: 1200
|
106
|
+
```
|
107
|
+
|
108
|
+
Each version that is a map can define the `media` key. If the value is an integer, produces `(max-width: #{media_integer_from_conf}px)` for the associated media attribute.
|
109
|
+
|
110
|
+
```yaml
|
111
|
+
picture_tag_ng:
|
112
|
+
picture_versions:
|
113
|
+
m:
|
114
|
+
out_size: 700
|
115
|
+
media: "screen and (max-width: 1200px)"
|
116
|
+
```
|
117
|
+
|
118
|
+
If `media` is a string, its value is used as-is for the corresponding media attribute.
|
119
|
+
|
120
|
+
Additionally, you can add the `default: true` property to any version to remove the corresponding media attribute from HTML `source` elements, and use this version as the `src` for the default HTML `img` element. If no version is explicitly set as the default, the largest one will me used.
|
121
|
+
|
122
|
+
The following configuration shows one version for each allowed format :
|
123
|
+
|
124
|
+
```yaml
|
125
|
+
picture_tag_ng:
|
126
|
+
picture_versions:
|
127
|
+
s:
|
128
|
+
out_size: 400
|
129
|
+
m:
|
130
|
+
out_size: 700
|
131
|
+
media: 1200
|
132
|
+
l:
|
133
|
+
out_size: 1200
|
134
|
+
media: "screen and (max-width: 1200px)"
|
135
|
+
xl:
|
136
|
+
out_size: 2000
|
137
|
+
default: true
|
138
|
+
```
|
139
|
+
|
140
|
+
When using the above configuration, the plugin will convert
|
141
|
+
|
142
|
+
```md
|
143
|
+

|
144
|
+
```
|
145
|
+
|
146
|
+
to the following HTML :
|
147
|
+
|
148
|
+
```html
|
149
|
+
<picture>
|
150
|
+
<source media="(max-width: 400px)" srcset="/img/s/path/to/img/orig.webp" type="image/webp">
|
151
|
+
<source media="(max-width: 400px)" srcset="/img/s/path/to/img/orig.jpg" type="image/jpeg">
|
152
|
+
<source media="(max-width: 1200px)" srcset="/img/m/path/to/img/orig.webp" type="image/webp">
|
153
|
+
<source media="(max-width: 1200px)" srcset="/img/m/path/to/img/orig.jpg" type="image/jpeg">
|
154
|
+
<source media="screen and (max-width: 1200px)" srcset="/img/l/path/to/img/orig.webp" type="image/webp">
|
155
|
+
<source media="screen and (max-width: 1200px)" srcset="/img/l/path/to/img/orig.jpg" type="image/jpeg">
|
156
|
+
<source srcset="/img/xl/path/to/img/orig.webp" type="image/webp">
|
157
|
+
<source srcset="/img/xl/path/to/img/orig.jpg" type="image/jpeg">
|
158
|
+
<img src="/img/xl/path/to/img/orig.jpg" alt="Alt text" loading="lazy">
|
159
|
+
</picture>
|
160
|
+
```
|
161
|
+
|
79
162
|
## Development
|
80
163
|
|
81
164
|
After cloning the repo, you can run the following commands in a local Jekyll website's folder to start hacking on the code of `jekyll-picture-tag-ng` (you'll need to replace the path in the second command) :
|
@@ -26,7 +26,11 @@ module Jekyll
|
|
26
26
|
def initialize(site, orig_static_file, version, pictype)
|
27
27
|
super(site, site.source, orig_static_file.dir, orig_static_file.name)
|
28
28
|
@version = version
|
29
|
-
@picture_dim = picture_versions[@version]
|
29
|
+
@picture_dim = if picture_versions[@version].is_a?(Hash)
|
30
|
+
picture_versions[@version]["out_size"]
|
31
|
+
else
|
32
|
+
picture_versions[@version]
|
33
|
+
end
|
30
34
|
@pictype = pictype
|
31
35
|
@collection = nil
|
32
36
|
end
|
@@ -197,13 +201,55 @@ module Kramdown
|
|
197
201
|
site_config["picture_versions"]
|
198
202
|
end
|
199
203
|
|
204
|
+
def _get_default_pic_version
|
205
|
+
largest_version = ""
|
206
|
+
largest_size = 0
|
207
|
+
picture_versions.each do |version, geometry|
|
208
|
+
size = if geometry.is_a?(Integer)
|
209
|
+
geometry
|
210
|
+
elsif geometry["default"]
|
211
|
+
999_999_999
|
212
|
+
else
|
213
|
+
geometry["out_size"]
|
214
|
+
end
|
215
|
+
if size > largest_size
|
216
|
+
largest_version = version
|
217
|
+
largest_size = size
|
218
|
+
end
|
219
|
+
end
|
220
|
+
largest_version
|
221
|
+
end
|
222
|
+
|
223
|
+
def default_pic_version
|
224
|
+
@default_pic_version ||= _get_default_pic_version
|
225
|
+
end
|
226
|
+
|
227
|
+
def media_attribute(version)
|
228
|
+
if version == default_pic_version
|
229
|
+
""
|
230
|
+
else
|
231
|
+
geometry = picture_versions[version]
|
232
|
+
if geometry.is_a?(Hash)
|
233
|
+
if geometry["media"].is_a?(String)
|
234
|
+
"media=\"#{geometry["media"]}\""
|
235
|
+
elsif geometry["media"].is_a?(Integer)
|
236
|
+
"media=\"(max-width: #{geometry["media"]}px)\""
|
237
|
+
else
|
238
|
+
"media=\"(max-width: #{geometry["out_size"]}px)\""
|
239
|
+
end
|
240
|
+
else
|
241
|
+
"media=\"(max-width: #{geometry}px)\""
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
200
246
|
def convert_img(el, _indent)
|
201
247
|
require "cgi"
|
202
248
|
res = "<picture>"
|
203
249
|
new_src = el.attr["src"]
|
204
250
|
if File.extname(el.attr["src"]) =~ /(\.jpg|\.jpeg|\.webp)$/i &&
|
205
251
|
el.attr["src"] !~ %r{^https?://}
|
206
|
-
picture_versions.
|
252
|
+
picture_versions.each do |version, _geometry|
|
207
253
|
src_base = File.join(
|
208
254
|
"/img",
|
209
255
|
version,
|
@@ -212,12 +258,8 @@ module Kramdown
|
|
212
258
|
end.join("/"),
|
213
259
|
File.basename(el.attr["src"], File.extname(el.attr["src"])).gsub(" ", "%20")
|
214
260
|
)
|
215
|
-
|
216
|
-
|
217
|
-
new_src = "#{src_base}.jpg"
|
218
|
-
else
|
219
|
-
media = "media=\"(max-width: #{geometry}px)\""
|
220
|
-
end
|
261
|
+
media = media_attribute(version)
|
262
|
+
new_src = "#{src_base}.jpg" if version == default_pic_version
|
221
263
|
res += "<source #{media} srcset=\"#{src_base}.webp\" type=\"image/webp\">"
|
222
264
|
res += "<source #{media} srcset=\"#{src_base}.jpg\" type=\"image/jpeg\">"
|
223
265
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-picture-tag-ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pcouy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -76,6 +76,7 @@ licenses:
|
|
76
76
|
metadata:
|
77
77
|
allowed_push_host: https://rubygems.org
|
78
78
|
homepage_uri: https://pierre-couy.dev/projects/jekyll-picture-tag-ng.html
|
79
|
+
documentation_uri: https://pierre-couy.dev/projects/jekyll-picture-tag-ng.html
|
79
80
|
source_code_uri: https://github.com/pcouy/jekyll-picture-tag-ng
|
80
81
|
post_install_message:
|
81
82
|
rdoc_options: []
|