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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b52a336938ddae6efa289e04f2f1aca361bb474cefe3f2d4fffd2dad80a467e8
4
- data.tar.gz: 0b86f4f49f920d1b6f2768c97ea5097549ef166da3cabccb6ed1873d1b5b973a
3
+ metadata.gz: e0b5fb6a41c6816d7b8f9a6b469b6217a422acbb8dc17d3acdbdb9a8ef287600
4
+ data.tar.gz: b067266b0151ccdf4c759c856acf754abd3536c8e8c1d67acb90c8d660bbbfae
5
5
  SHA512:
6
- metadata.gz: 741975e760fc74b014ac1398f31d3840a811720c10c1264716db7332a103ca0fbd6cd8f821b379f9b9caf1e23e78c20e82885c73d641d74e4d63035353aa7c5e
7
- data.tar.gz: 6a0e1f8fe4a400357cb002a41a2ab7e86a6a427d156da1f86ca951ba1729e030fef972ade27107d778693965e920d2e99de12aac952f8ff87c8db279d17e5f33
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 directly
10
- (read: _blockingly_) load the resource.
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 it, be awesome and
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
@@ -6,7 +6,8 @@ require "nokogiri"
6
6
  module Jekyll
7
7
  class LoadingLazy
8
8
  def self.process(content)
9
- content.output = process_image_tags(content.output)
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.process_image_tags(html)
18
- content = Nokogiri::HTML::DocumentFragment.parse(html)
19
- anchors = content.css("img[src], iframe[src]")
20
- anchors.each { |item| item["loading"] = "lazy" unless item["loading"] }
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 :process_image_tags
29
+ private_class_method :process_tags
30
+ private_class_method :process_tags?
25
31
  end
26
32
  end
27
33
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  class LoadingLazy
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2020-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll