anti_image_reflow 0.1.0 → 0.1.2

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: f44d39bbd484acb93d0a7b81c95aba1487dee78ffbc2becb445f91f6c07a140b
4
- data.tar.gz: fb3e9c5e592c8069c076c2cf0d3d78fa5fea013b1e65fdcc34b43119310c2d27
3
+ metadata.gz: 67b9298dfb8a7fa25139754f4d54829d120610bd2320976e8d04a34c8f5b9fd3
4
+ data.tar.gz: c4feccce130d543aa25f2dcaf44a93cde86270ecb6d397be81285ea669c71593
5
5
  SHA512:
6
- metadata.gz: 30d7b71050eb05e4d0c7441f257e07ce48bd991a65ab27852c88a308e0ca60a6b3ee8ad2423a80ec50acba1a3aa7e9fa06f9ca2c43e598040df492df40867137
7
- data.tar.gz: 4d4ce5945808868b276739100f06828915673a2a07dd980b172c4654f640707fbd70c5a3953cecd92625f25e0493ddfa101ae0c3e29aa871eec6714b830c8a90
6
+ metadata.gz: 7a7e0b3922f43ceed48ebd03e29d8ad688a4d9dd677f90a3931e098b14b311d761bc29f7b9affe57d9e73e4a29acefe48358e0dbf373a8b03cfb800eb65448e0
7
+ data.tar.gz: f4935acdc2014ac7b9b56432556df2936b195b957dc9573ece0ebd317f2c8ab0f1d0b27ecf5caf126d0f97ebdc06bb4bfd89bdfa488e7739f39a149bac6fe2ed
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2023-01-16
4
+
5
+ - Updated dependencies
6
+
7
+ ## [0.1.1] - 2023-01-16
8
+
9
+ - Added catch for invalid paths
10
+
3
11
  ## [0.1.0] - 2022-11-27
4
12
 
5
13
  - Initial release
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.platform = Gem::Platform::RUBY
25
25
  spec.add_runtime_dependency "jekyll", "~> 4.3"
26
- spec.add_runtime_dependency "nokogiri", '~> 1.12'
27
- spec.add_runtime_dependency "fastimage", '~> 2.2'
26
+ spec.add_runtime_dependency "nokogiri", '~> 1.14'
27
+ spec.add_runtime_dependency "fastimage", '~> 2.2.6'
28
28
 
29
29
  # For more information and examples about making a new gem, check out our
30
30
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AntiImageReflow
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -6,48 +6,46 @@ require "jekyll"
6
6
  require "nokogiri"
7
7
  require "fastimage"
8
8
 
9
- #module AntiImageReflow
10
- # class Error < StandardError; end
11
- # # Your code goes here...
12
- #end
13
-
14
9
  module Jekyll
15
- class AntiImageReflow
16
- def self.process(content)
17
- html = content.output
18
- content.output = process_tags(html) if process_tags?(html)
19
- end
20
-
21
- def self.process?(doc)
22
- (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || doc.permalink&.end_with?("/")
23
- end
24
-
25
- def self.process_tags?(html)
26
- html.include?("<img") || html.include?("<iframe")
27
- end
28
-
29
- def self.process_tags(html)
30
- content = Nokogiri.HTML(html)
31
- tags = content.css("img[src]")
32
-
33
- tags.each do |tag|
34
- # add height and width attributes
35
- if tag.name == "img"
36
- size = FastImage.size(File.join(Dir.pwd, tag["src"]))
37
- tag["width"] = size[0] unless tag["width"] || size.nil?
38
- tag["height"] = size[1] unless tag["height"] || size.nil?
39
- tag["loading"] = "lazy" unless tag["loading"]
40
- end
41
- end
42
-
43
- content.to_html
44
- end
45
-
46
- private_class_method :process_tags
47
- private_class_method :process_tags?
48
- end
10
+ class AntiImageReflow
11
+ def self.process(content)
12
+ html = content.output
13
+ content.output = process_tags(html) if process_tags?(html)
14
+ end
15
+
16
+ def self.process?(doc)
17
+ (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || doc.permalink&.end_with?("/")
18
+ end
19
+
20
+ def self.process_tags?(html)
21
+ html.include?("<img") || html.include?("<iframe")
22
+ end
23
+
24
+ def self.process_tags(html)
25
+ content = Nokogiri.HTML(html)
26
+ tags = content.css("img[src]")
27
+
28
+ tags.each do |tag|
29
+ # add height and width attributes
30
+ if tag.name == "img"
31
+ path = File.join(Dir.pwd, tag["src"])
32
+ # check if file exists
33
+ if File.exist?(path)
34
+ size = FastImage.size(path)
35
+ tag["width"] = size[0] unless tag["width"] || size.nil?
36
+ tag["height"] = size[1] unless tag["height"] || size.nil?
37
+ tag["loading"] = "lazy" unless tag["loading"]
38
+ end
39
+ end
40
+ end
41
+ content.to_html
42
+ end
43
+
44
+ private_class_method :process_tags
45
+ private_class_method :process_tags?
46
+ end
49
47
  end
50
48
 
51
49
  Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
52
- Jekyll::AntiImageReflow.process(doc) if Jekyll::AntiImageReflow.process?(doc)
50
+ Jekyll::AntiImageReflow.process(doc) if Jekyll::AntiImageReflow.process?(doc)
53
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anti_image_reflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '1.14'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: '1.14'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fastimage
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.2'
47
+ version: 2.2.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.2'
54
+ version: 2.2.6
55
55
  description:
56
56
  email:
57
57
  - zachsmith.dev@gmail.com