jekyll-loading-lazy 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/jekyll-loading-lazy.rb +12 -6
- data/lib/jekyll-loading-lazy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0b5fb6a41c6816d7b8f9a6b469b6217a422acbb8dc17d3acdbdb9a8ef287600
|
4
|
+
data.tar.gz: b067266b0151ccdf4c759c856acf754abd3536c8e8c1d67acb90c8d660bbbfae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 888388cfe390370ef2450d3aa6209e10969ac0c5160e04303139b86da2804caf9e025d4e1706481395375c38321f9fbfa7a585633f5dd77fc302553595088427
|
7
|
+
data.tar.gz: f13fe6341cf8bec48e2f2f445e6ae878945150408b590427135be7f30141e775e04b72d474d3b62efd59b106a6e0d820ea8feaeb9e782c993fa9781378f5c099
|
data/README.md
CHANGED
@@ -6,17 +6,17 @@ If a `loading` attribute is already present nothing is changed.
|
|
6
6
|
|
7
7
|
`loading="lazy"` causes images and iframes to load lazily without any JavaScript.
|
8
8
|
[Browser support](https://caniuse.com/#feat=loading-lazy-attr) is growing.
|
9
|
-
If a browser does not support the `loading` attribute, it will
|
10
|
-
|
9
|
+
If a browser does not support the `loading` attribute, it will load the resource
|
10
|
+
just like it would normally.
|
11
11
|
|
12
|
-
If you like
|
12
|
+
If you like this plugin, be awesome and
|
13
13
|
[_buy me a coffee_ ☕️](https://www.buymeacoffee.com/gildesmarais). Thank you!
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
17
|
1. Add the following to your site's `Gemfile`:
|
18
18
|
|
19
|
-
```
|
19
|
+
```ruby
|
20
20
|
gem 'jekyll-loading-lazy'
|
21
21
|
```
|
22
22
|
|
@@ -52,7 +52,7 @@ to their tags.
|
|
52
52
|
## Contributing
|
53
53
|
|
54
54
|
1. [Fork this repository](https://github.com/gildesmarais/jekyll-loading-lazy/fork)
|
55
|
-
2. Create your branch (`git checkout -b feat/my-new-feature)
|
55
|
+
2. Create your branch (`git checkout -b feat/my-new-feature`)
|
56
56
|
3. Commit your changes (`git commit -m 'Add cool feature'`)
|
57
57
|
4. Push to the branch (git push origin feat/my-new-feature)
|
58
58
|
5. Create a new Pull Request
|
data/lib/jekyll-loading-lazy.rb
CHANGED
@@ -6,7 +6,8 @@ require "nokogiri"
|
|
6
6
|
module Jekyll
|
7
7
|
class LoadingLazy
|
8
8
|
def self.process(content)
|
9
|
-
|
9
|
+
html = content.output
|
10
|
+
content.output = process_tags(html) if process_tags?(html)
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.process?(doc)
|
@@ -14,14 +15,19 @@ module Jekyll
|
|
14
15
|
doc.permalink&.end_with?("/")
|
15
16
|
end
|
16
17
|
|
17
|
-
def self.
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def self.process_tags?(html)
|
19
|
+
html.include?("<img") || html.include?("<iframe")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.process_tags(html)
|
23
|
+
content = Nokogiri.HTML(html)
|
24
|
+
tags = content.css("img[src], iframe[src]")
|
25
|
+
tags.each { |tag| tag["loading"] = "lazy" unless tag["loading"] }
|
21
26
|
content.to_html
|
22
27
|
end
|
23
28
|
|
24
|
-
private_class_method :
|
29
|
+
private_class_method :process_tags
|
30
|
+
private_class_method :process_tags?
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-loading-lazy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gil Desmarais
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|