jekyll-imgwh 1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-imgwh/version.rb +1 -1
- data/lib/jekyll-imgwh.rb +38 -17
- 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: 9d6e9502b9771b8cde54d20f222edbe9a3cd3882d275dda10b75c9d208e9fe7a
|
4
|
+
data.tar.gz: 7faf66b11788dacee656ce7ba690e303b2abf72117e5b13b39d11a2323907cf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a442ba4d09a91ab85d776e7b64820eeb46de0dfbc8415c7f3617db6cf7b9f4871496549825abed99c385a1a5867f820216fc1ef25063d52df6961ffd881e51ca
|
7
|
+
data.tar.gz: 1b5c3871cd747afa49319b50f85ddf3eb16615b9b08e69c54208bc51cc2a9391ef3e0452a906bd94fff7f35734a216895bf4d01301010d10fca5bbcda40bdca2
|
data/lib/jekyll-imgwh/version.rb
CHANGED
data/lib/jekyll-imgwh.rb
CHANGED
@@ -4,6 +4,7 @@ require "cgi"
|
|
4
4
|
require "fastimage"
|
5
5
|
require "jekyll"
|
6
6
|
require "jekyll-imgwh/version"
|
7
|
+
require "uri"
|
7
8
|
|
8
9
|
module Jekyll
|
9
10
|
module Imgwh
|
@@ -31,32 +32,52 @@ module Jekyll
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def render(context)
|
34
|
-
|
35
|
-
debug "content: '#{@content}'"
|
36
|
-
debug "src: '#{@src}'"
|
37
|
-
debug "rest: '#{@rest}'"
|
35
|
+
["---", "content: '#{@content}'", "src: '#{@src}'", "rest: '#{@rest}'"].map { |x| debug x }
|
38
36
|
|
39
37
|
src = Liquid::Template.parse(@src).render(context)
|
40
38
|
debug "src rendered: '#{src}'"
|
41
|
-
img = "<img src=#{
|
42
|
-
|
43
|
-
path = resolve_path(src, context)
|
44
|
-
size = FastImage.size(path)
|
45
|
-
raise LoadError, "#{NAME}: could not get size of image '#{path}'" unless size
|
39
|
+
img = "<img src=#{quoted src}"
|
46
40
|
|
41
|
+
size = image_size(src, context)
|
47
42
|
debug "image size: #{size}"
|
48
|
-
img << " width=#{
|
43
|
+
img << " width=#{quoted size[0]} height=#{quoted size[1]}" << render_rest(context) << ">"
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def quoted(value)
|
49
|
+
"#{@quote}#{value}#{@quote}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def image_size(src, context)
|
53
|
+
uri = URI(src)
|
53
54
|
|
54
|
-
|
55
|
+
if uri.scheme.nil?
|
56
|
+
path = resolve_path(CGI.unescape(uri.path), context)
|
57
|
+
FastImage.size(path) or raise LoadError, "#{NAME}: could not get size of image '#{path}'"
|
58
|
+
else
|
59
|
+
raise ArgumentError, "#{NAME}: URIs with '#{uri.scheme}' scheme are not allowed"
|
60
|
+
end
|
55
61
|
end
|
56
62
|
|
57
|
-
def
|
58
|
-
|
63
|
+
def render_rest(context)
|
64
|
+
rest = +""
|
65
|
+
|
66
|
+
extra_rest = context.registers[:site].config.dig(NAME, "extra_rest")
|
67
|
+
unless extra_rest.nil?
|
68
|
+
extra_rest = Liquid::Template.parse(extra_rest).render(context)
|
69
|
+
debug "extra_rest rendered: '#{extra_rest}'"
|
70
|
+
rest << " #{extra_rest}" unless extra_rest.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
tag_rest = Liquid::Template.parse(@rest).render(context)
|
74
|
+
debug "rest rendered: '#{tag_rest}'"
|
75
|
+
rest << " #{tag_rest}" unless tag_rest.empty?
|
76
|
+
|
77
|
+
rest
|
78
|
+
end
|
59
79
|
|
80
|
+
def resolve_path(path, context)
|
60
81
|
local_path = resolve_local_path(path, context)
|
61
82
|
return local_path if File.file?(local_path)
|
62
83
|
|
@@ -83,7 +104,7 @@ module Jekyll
|
|
83
104
|
themed_path
|
84
105
|
end
|
85
106
|
|
86
|
-
Liquid::Template.register_tag
|
107
|
+
Liquid::Template.register_tag "imgwh", self
|
87
108
|
end
|
88
109
|
end
|
89
110
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-imgwh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikalai Ananenka
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: fastimage
|