jekyll-srcset-hook 0.1.0 → 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/.rubocop.yml +4 -1
- data/Gemfile +0 -4
- data/README.md +4 -4
- data/lib/jekyll-srcset-hook/version.rb +1 -1
- data/lib/jekyll-srcset-hook.rb +41 -44
- metadata +4 -5
- data/Rakefile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 116d2a291fb3fe38c63a646ddfbfb436d224b5ffa7e57fff2db1ec1ae07b5a8b
|
4
|
+
data.tar.gz: ac685f20b098231ae56458eaba29c6fb4b636938f7c47cd221c425e6e1fe785e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: babbfbae146435d55949aaa08faf033bb3fa38170764936c1debaaed9e4f0eec34533ca856926d60d5184a720b305980eecbdc6110222c49b909a47227061b68
|
7
|
+
data.tar.gz: 24df37d9b70d0d1a67cd0549542179293fcd7c3df97b792b765d17368960878932e987de6b1c72304deb57bfd2dbf38dad5381f60717d15b8d0a716c81435b34
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,7 @@ And change them to (based on the config in `_config.yml`):
|
|
23
23
|
|
24
24
|
## Installation
|
25
25
|
|
26
|
-
|
26
|
+
Using Bundler, add `gem 'jekyll-srcset-hook'` to the `jekyll_plugins` group in your `Gemfile`:
|
27
27
|
|
28
28
|
```
|
29
29
|
source 'https://rubygems.org'
|
@@ -77,12 +77,12 @@ jekyll-srcset-hook:
|
|
77
77
|
|
78
78
|
## Usage
|
79
79
|
|
80
|
-
`jekyll-srcset-hook` will not modify images
|
81
|
-
it can be used with local images or images from other sources.
|
80
|
+
`jekyll-srcset-hook` will not modify images where the `src` attribute does not begin with the `url_endpoint` value so
|
81
|
+
it can be used along with existing local images or images from other sources.
|
82
82
|
|
83
83
|
## Contributing
|
84
84
|
|
85
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/juicy-g/jekyll-srcset-hook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jekyll-srcset-hook/blob/main/CODE_OF_CONDUCT.md).
|
86
86
|
|
87
87
|
## License
|
88
88
|
|
data/lib/jekyll-srcset-hook.rb
CHANGED
@@ -2,32 +2,27 @@
|
|
2
2
|
|
3
3
|
require "nokogiri"
|
4
4
|
|
5
|
-
module
|
6
|
-
|
5
|
+
module Srcset
|
6
|
+
@config = {}
|
7
7
|
|
8
8
|
def set_config
|
9
9
|
proc do |site|
|
10
|
-
|
10
|
+
@config = site.config["jekyll-srcset-hook"]
|
11
11
|
|
12
|
-
if
|
12
|
+
if @config.nil?
|
13
13
|
Jekyll.logger.warn(
|
14
|
-
"WARNING: jekyll-srcset
|
14
|
+
"WARNING: jekyll-srcset configuration is not present in _config.yml"
|
15
15
|
)
|
16
16
|
next
|
17
17
|
end
|
18
18
|
|
19
|
-
unless
|
19
|
+
unless @config["transformations_widths"].nil? && @config["sizes"].nil?
|
20
20
|
Jekyll::Hooks.register(:posts, :post_render, &modify_post_output)
|
21
21
|
Jekyll::Hooks.register(:pages, :post_render, &modify_page_output)
|
22
22
|
end
|
23
23
|
|
24
|
-
unless
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
unless @@config["pages"].nil?
|
29
|
-
Jekyll::Hooks.register(:pages, :post_render, &modify_page_output)
|
30
|
-
end
|
24
|
+
Jekyll::Hooks.register(:posts, :post_render, &modify_post_output) unless @config["posts"].nil?
|
25
|
+
Jekyll::Hooks.register(:pages, :post_render, &modify_page_output) unless @config["pages"].nil?
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
@@ -38,22 +33,22 @@ module JekyllSrcsetHook
|
|
38
33
|
fragment
|
39
34
|
.xpath(".//img")
|
40
35
|
.each do |image|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
36
|
+
next unless image[:src].start_with?(
|
37
|
+
@config["url_endpoint"] || @config["posts"]["url_endpoint"]
|
38
|
+
)
|
39
|
+
|
40
|
+
original_image = image
|
41
|
+
original_image = original_image.to_s.gsub!(">", " />")
|
42
|
+
|
43
|
+
image =
|
44
|
+
process_image(
|
45
|
+
image,
|
46
|
+
@config["transformations_widths"] ||
|
47
|
+
@config["posts"]["transformations_widths"],
|
48
|
+
@config["sizes"] || @config["posts"]["sizes"]
|
49
|
+
)
|
50
|
+
|
51
|
+
post.output.gsub!(original_image, image)
|
57
52
|
end
|
58
53
|
end
|
59
54
|
end
|
@@ -66,29 +61,31 @@ module JekyllSrcsetHook
|
|
66
61
|
elements.pop
|
67
62
|
|
68
63
|
elements.each do |image|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
original_image = image
|
73
|
-
original_image = original_image.to_s.gsub!(">", " />")
|
64
|
+
next unless image[:src].start_with?(
|
65
|
+
@config["url_endpoint"] || @config["pages"]["url_endpoint"]
|
66
|
+
)
|
74
67
|
|
75
|
-
|
76
|
-
|
77
|
-
image,
|
78
|
-
@@config["transformations_widths"] ||
|
79
|
-
@@config["pages"]["transformations_widths"],
|
80
|
-
@@config["sizes"] || @@config["pages"]["sizes"],
|
81
|
-
)
|
68
|
+
original_image = image
|
69
|
+
original_image = original_image.to_s.gsub!(">", " />")
|
82
70
|
|
83
|
-
|
84
|
-
|
71
|
+
image =
|
72
|
+
process_image(
|
73
|
+
image,
|
74
|
+
@config["transformations_widths"] ||
|
75
|
+
@config["pages"]["transformations_widths"],
|
76
|
+
@config["sizes"] || @config["pages"]["sizes"]
|
77
|
+
)
|
78
|
+
|
79
|
+
page.output.gsub!(original_image, image)
|
85
80
|
end
|
86
81
|
end
|
87
82
|
end
|
88
83
|
|
89
84
|
def process_image(image, transformations, sizes)
|
90
85
|
srcset_value = ""
|
91
|
-
transformations.each
|
86
|
+
transformations.each do |t_w|
|
87
|
+
srcset_value += "#{image[:src]}#{t_w}, "
|
88
|
+
end
|
92
89
|
# remove the extra ", " at the end of srcset_value
|
93
90
|
srcset_value.chomp!(", ")
|
94
91
|
# add the attributes to the image
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-srcset-hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jocelyn Gaudette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -44,7 +44,6 @@ files:
|
|
44
44
|
- Gemfile
|
45
45
|
- LICENSE
|
46
46
|
- README.md
|
47
|
-
- Rakefile
|
48
47
|
- lib/jekyll-srcset-hook.rb
|
49
48
|
- lib/jekyll-srcset-hook/version.rb
|
50
49
|
homepage: https://github.com/juicy-g/jekyll-srcset-hook
|
@@ -72,6 +71,6 @@ requirements: []
|
|
72
71
|
rubygems_version: 3.3.5
|
73
72
|
signing_key:
|
74
73
|
specification_version: 4
|
75
|
-
summary: A Jekyll plugin to add srcset and sizes attributes to images without
|
76
|
-
tags.
|
74
|
+
summary: A Jekyll plugin to add srcset and sizes attributes to images without using
|
75
|
+
Liquid tags.
|
77
76
|
test_files: []
|