anti_image_reflow 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/lib/anti_image_reflow/version.rb +1 -1
- data/lib/anti_image_reflow.rb +38 -40
- 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: 866a8a309fffb2d9e7b3b72d232cebf094ce2cf52bdd9e1d4ea1bd1e6ddea2d1
|
4
|
+
data.tar.gz: a3ca9fc75e290ff8c1c2454bfa821b37c7e7e3b77986977ab3e7d0ee3a5c2f83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0105d7930937c65c4246ea9fdfc0d2478af1ee5885f325f313a360900b761c4f00c1ebe19fb70bcb69b96d96fe0f2402695ed9612c83035546fd735526559ac9
|
7
|
+
data.tar.gz: c117487d6bba3a53764084fa40fb9b3de45088cce3b3adfe5659479fa32dea28a4ce98c63aa965f186ba21148b4be9ed52006ee436b9fb2f0cac9998a55712d9
|
data/lib/anti_image_reflow.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zachary Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|