jekyll-img-srcset 0.1.3 → 0.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.
- checksums.yaml +4 -4
- data/lib/jekyll-img-srcset.rb +64 -54
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cba8bc40ca676dbd4b2889516261954dd9ccefcc6a8d020faa49df285e4004b
|
4
|
+
data.tar.gz: e234e70640cba4b30dc472d1a78954066be34b2630277d1627668f88b46a1bf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4520a7fbef0148dcebb03a6943fa53114aaae6217dc522aec7e41e43f397be3e230c5738e4ab8bb09ae61e6ed7b3537ce350f3d12ef838a6507cf790f1afd068
|
7
|
+
data.tar.gz: dea03820cebd35ed1b0147ecb2e90e94562dfb188c712c56f60082904303d0b9fe712858c489d1bc4c8b5a9f5d98807fe7de33212048dc8853807f05b1e361df
|
data/lib/jekyll-img-srcset.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mini_magick'
|
2
|
+
require 'parallel'
|
2
3
|
|
3
4
|
# Resizes an image to provide different versions for multiple
|
4
5
|
# display resolutions
|
@@ -14,17 +15,28 @@ require 'mini_magick'
|
|
14
15
|
# the generated widths and the original iamge width
|
15
16
|
def resize_image(url, widths, dest, base_image_path, cache)
|
16
17
|
src_path = File.join(base_image_path, url)
|
17
|
-
|
18
|
+
src_mtime = File.new(src_path).mtime
|
19
|
+
if cache.key? src_path
|
20
|
+
_, _, modified_time = cache[src_path]
|
21
|
+
if src_mtime > modified_time
|
22
|
+
cache.delete src_path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# resize images if they aren't already in the cache
|
26
|
+
new_widths, w, modified_time = cache.getset(src_path) do
|
27
|
+
modified_time = File.new(src_path).mtime
|
18
28
|
image = MiniMagick::Image.open(src_path)
|
19
29
|
w = image.dimensions[0]
|
20
30
|
aspect = image.dimensions[1].to_f / w
|
21
31
|
[w, aspect]
|
22
32
|
new_widths = widths.select {|x| x <= w}
|
23
|
-
new_widths.map do |width|
|
33
|
+
width_to_create = new_widths.map do |width|
|
24
34
|
[width, File.join(dest, base_image_path, "#{width}", url)]
|
25
|
-
end
|
26
|
-
|
27
|
-
|
35
|
+
end
|
36
|
+
.select do |width, target|
|
37
|
+
(not File.exists? target) or (File.new(target).mtime < src_mtime)
|
38
|
+
end
|
39
|
+
Parallel.each(width_to_create) do |width, target|
|
28
40
|
image = MiniMagick::Image.open(src_path)
|
29
41
|
image.resize "#{width}x#{width*aspect}"
|
30
42
|
if not Dir.exists? File.dirname(target)
|
@@ -32,8 +44,9 @@ def resize_image(url, widths, dest, base_image_path, cache)
|
|
32
44
|
end
|
33
45
|
image.write target
|
34
46
|
end
|
35
|
-
[new_widths, w]
|
47
|
+
[new_widths, w, modified_time]
|
36
48
|
end
|
49
|
+
|
37
50
|
return new_widths, w
|
38
51
|
end
|
39
52
|
|
@@ -120,50 +133,50 @@ def format_svg_image(url, ident, title, baseurl, base_image_path)
|
|
120
133
|
content += "/>"
|
121
134
|
end
|
122
135
|
|
123
|
-
def process_page(document, payload)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
136
|
+
# def process_page(document, payload)
|
137
|
+
# # see https://gist.github.com/mmistakes/77c68fbb07731a456805a7b473f47841
|
138
|
+
# doc_ext = document.extname.tr('.', '')
|
139
|
+
# cache = Jekyll::Cache.new("jekyll-img-srcset")
|
140
|
+
# if payload['site']['markdown_ext'].include? doc_ext
|
141
|
+
# content = document.content
|
142
|
+
# base_image_path = document.site.config["base_image_path"] || "assets/images"
|
143
|
+
# image_regex = /!\[(?<caption>.*?)?\]\((?<url>\S+?)(?<title> .+?)?\)(?<identifier>\{.+?\})?/
|
144
|
+
# content = content.gsub(image_regex) do | img |
|
145
|
+
# img = image_regex.match img
|
146
|
+
# if (/\.(jpe?g|png)$/i =~ img["url"]).nil?
|
147
|
+
# "#{base_image_path}/#{img[0]}"
|
148
|
+
# elsif img["url"].start_with? "http"
|
149
|
+
# img[0]
|
150
|
+
# elsif img["url"].end_with? ".svg"
|
151
|
+
# ident = parse_identifier img[:identifier]
|
152
|
+
# format_svg_image(img["url"], ident, img["title"],
|
153
|
+
# document.site.baseurl)
|
154
|
+
# else
|
155
|
+
# if File.exists?(File.join base_image_path, img['url'])
|
156
|
+
# widths, original_width = resize_image(img['url'],
|
157
|
+
# document.site.config["widths"],
|
158
|
+
# document.site.config["destination"],
|
159
|
+
# base_image_path, cache)
|
160
|
+
# document.site.keep_files.concat(widths.map do |w|
|
161
|
+
# File.join(base_image_path, "#{w}", img['url'])
|
162
|
+
# end)
|
163
|
+
# ident = parse_identifier img[:identifier]
|
164
|
+
# format_image(ident, widths, original_width,
|
165
|
+
# img["url"], img["caption"], img["title"],
|
166
|
+
# document.site.baseurl, base_image_path)
|
167
|
+
# else
|
168
|
+
# img[0]
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
# end
|
172
|
+
# # puts content
|
173
|
+
# document.content = content
|
174
|
+
# end
|
175
|
+
# end
|
163
176
|
|
164
|
-
Jekyll::Hooks.register [:pages, :posts, :documents], :pre_render do |document, payload|
|
165
|
-
|
166
|
-
end
|
177
|
+
# Jekyll::Hooks.register [:pages, :posts, :documents], :pre_render do |document, payload|
|
178
|
+
# process_page(document, payload)
|
179
|
+
# end
|
167
180
|
|
168
181
|
def check_in_context(context, path)
|
169
182
|
parts = path.split(".")
|
@@ -182,7 +195,7 @@ module Jekyll
|
|
182
195
|
class ImgSrcsetTag < Liquid::Tag
|
183
196
|
|
184
197
|
def cache
|
185
|
-
@@cache ||= Jekyll::Cache.new("
|
198
|
+
@@cache ||= Jekyll::Cache.new("Jekyll::ImgSrcset")
|
186
199
|
end
|
187
200
|
|
188
201
|
def initialize(tag_name, text, tokens)
|
@@ -235,7 +248,4 @@ module Jekyll
|
|
235
248
|
end
|
236
249
|
end
|
237
250
|
|
238
|
-
Liquid::Template.register_tag('imgsrcset', Jekyll::ImgSrcsetTag)
|
239
|
-
|
240
|
-
|
241
|
-
# /![(?<caption>.*?)?]\((?<url>[^\s]+?)(?<title> .+?)?\)(?<identifier>{.+?})?/
|
251
|
+
Liquid::Template.register_tag('imgsrcset', Jekyll::ImgSrcsetTag)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-img-srcset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan-Philipp Stauffert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: parallel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.19'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.19'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|