jekyll-loading-lazy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b52a336938ddae6efa289e04f2f1aca361bb474cefe3f2d4fffd2dad80a467e8
4
+ data.tar.gz: 0b86f4f49f920d1b6f2768c97ea5097549ef166da3cabccb6ed1873d1b5b973a
5
+ SHA512:
6
+ metadata.gz: 741975e760fc74b014ac1398f31d3840a811720c10c1264716db7332a103ca0fbd6cd8f821b379f9b9caf1e23e78c20e82885c73d641d74e4d63035353aa7c5e
7
+ data.tar.gz: 6a0e1f8fe4a400357cb002a41a2ab7e86a6a427d156da1f86ca951ba1729e030fef972ade27107d778693965e920d2e99de12aac952f8ff87c8db279d17e5f33
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Gil Desmarais <jekyll-loading-lazy@desmarais.de> and approved contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ # jekyll-loading-lazy
2
+
3
+ This plugin adds `loading="lazy"` to all `img` and `iframe` tags on
4
+ your [Jekyll site](https://jekyllrb.com/). No configuration needed.
5
+ If a `loading` attribute is already present nothing is changed.
6
+
7
+ `loading="lazy"` causes images and iframes to load lazily without any JavaScript.
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.
11
+
12
+ If you like it, be awesome and
13
+ [_buy me a coffee_ ☕️](https://www.buymeacoffee.com/gildesmarais). Thank you!
14
+
15
+ ## Installation
16
+
17
+ 1. Add the following to your site's `Gemfile`:
18
+
19
+ ```
20
+ gem 'jekyll-loading-lazy'
21
+ ```
22
+
23
+ 2. add the following to your site's `_config.yml`:
24
+
25
+ ```yml
26
+ plugins:
27
+ - jekyll-loading-lazy
28
+ ```
29
+
30
+ **Note**: if `jekyll --version` is less than `3.5` use:
31
+
32
+ ```yml
33
+ gems:
34
+ - jekyll-loading-lazy
35
+ ```
36
+
37
+ 3. In your terminal, execute:
38
+
39
+ ```bash
40
+ bundle
41
+ ```
42
+ 4. (re)start your Jekyll server with:
43
+
44
+ ```bash
45
+ jekyll serve
46
+ ```
47
+
48
+ That's basically all there is.
49
+ In case you want to eager load some images/iframes, add `loading="eager"`
50
+ to their tags.
51
+
52
+ ## Contributing
53
+
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)
56
+ 3. Commit your changes (`git commit -m 'Add cool feature'`)
57
+ 4. Push to the branch (git push origin feat/my-new-feature)
58
+ 5. Create a new Pull Request
59
+
60
+ ### Testing
61
+
62
+ ```bash
63
+ rake
64
+ ```
65
+
66
+ ## Credits
67
+
68
+ Thanks to @keithmifsud's
69
+ [`jekyll-target-blank`](https://github.com/keithmifsud/jekyll-target-blank)
70
+ whereon this Jekyll plugin largely bases.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "nokogiri"
5
+
6
+ module Jekyll
7
+ class LoadingLazy
8
+ def self.process(content)
9
+ content.output = process_image_tags(content.output)
10
+ end
11
+
12
+ def self.process?(doc)
13
+ (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" ||
14
+ doc.permalink&.end_with?("/")
15
+ end
16
+
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"] }
21
+ content.to_html
22
+ end
23
+
24
+ private_class_method :process_image_tags
25
+ end
26
+ end
27
+
28
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
29
+ Jekyll::LoadingLazy.process(doc) if Jekyll::LoadingLazy.process?(doc)
30
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class LoadingLazy
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-loading-lazy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gil Desmarais
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: nokogiri
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '1.10'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '12.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '12.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rubocop
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "<"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rubocop-jekyll
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "<"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.0'
123
+ description: 'Loading Lazy automatically adds loading="lazy" to <img> and <iframe>
124
+ tags on your Jekyll site.
125
+
126
+ '
127
+ email:
128
+ - jekyll-loading-lazy@desmarais.de
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - LICENSE.md
134
+ - README.md
135
+ - lib/jekyll-loading-lazy.rb
136
+ - lib/jekyll-loading-lazy/version.rb
137
+ homepage: https://github.com/gildesmarais/jekyll-loading-lazy
138
+ licenses:
139
+ - MIT
140
+ metadata:
141
+ bug_tracker_uri: https://github.com/gildesmarais/jekyll-loading-lazy/issues
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 2.5.8
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.7.6.2
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Automatically adds loading="lazy" to <img> and <iframe> tags.
162
+ test_files: []