jekyll-bits 0.11.1 → 0.12
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/jekyll-bits.gemspec +1 -1
- data/lib/jekyll-bits/picture.rb +23 -7
- data/test/test_picture.rb +18 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34fe40d6e304fc584ff0f2db5ff4c88336602445
|
4
|
+
data.tar.gz: 6e649c35a6a6b96b472471c39766d0dcbfe3eec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb398b0031a4f67dbe613684e3a08d5464ce884bbdaa143ac9b6524ac26adf79035c5debcba153b7f620043d99cec8c5ba8ca9b40c8da51e1347eaa70abdcd15
|
7
|
+
data.tar.gz: 65b08af323e00082cb6a9a5725721c7e63627cc96fe628102eb37fde049de7bd512efa7071520354305659664b6f99b90213b248cd28814829cf8fde8904493f
|
data/jekyll-bits.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.rubygems_version = '2.2.2'
|
9
9
|
s.required_ruby_version = '>= 1.9.3'
|
10
10
|
s.name = 'jekyll-bits'
|
11
|
-
s.version = '0.
|
11
|
+
s.version = '0.12'
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.summary = 'Jekyll Bits'
|
14
14
|
s.description = 'Useful and very simple Jekyll plugins'
|
data/lib/jekyll-bits/picture.rb
CHANGED
@@ -48,6 +48,13 @@ module Jekyll
|
|
48
48
|
html += "<meta name='og:image:height' content='#{height}'/>
|
49
49
|
<meta name='twitter:image:height' content='#{height}'/>"
|
50
50
|
end
|
51
|
+
if width && width >= 1024 && height && height >= 768
|
52
|
+
html += "<meta name='twitter:card' content='summary_large_image'/>"
|
53
|
+
else
|
54
|
+
html += "<meta name='twitter:card' content='summary'/>"
|
55
|
+
end
|
56
|
+
html += "<meta name='twitter:image:alt' \
|
57
|
+
content='#{CGI.escapeHTML(alt(page))}'/>"
|
51
58
|
html
|
52
59
|
end
|
53
60
|
|
@@ -55,13 +62,8 @@ module Jekyll
|
|
55
62
|
uri = uri(page)
|
56
63
|
return '' if uri.empty?
|
57
64
|
yaml = page['jb_picture']
|
58
|
-
html = "<img itemprop='image' alt='"
|
59
|
-
|
60
|
-
html += CGI.escapeHTML(yaml['alt'])
|
61
|
-
else
|
62
|
-
html += 'front image'
|
63
|
-
end
|
64
|
-
html += "' src='#{CGI.escapeElement(uri)}'"
|
65
|
+
html = "<img itemprop='image' alt='#{CGI.escapeHTML(alt(page))}'"
|
66
|
+
html += " src='#{CGI.escapeElement(uri)}'"
|
65
67
|
md5 = Digest::MD5.new.hexdigest(uri)[0, 8]
|
66
68
|
html += " longdesc='##{md5}'" \
|
67
69
|
if yaml.is_a?(Hash) && yaml['caption']
|
@@ -113,6 +115,20 @@ module Jekyll
|
|
113
115
|
end
|
114
116
|
@@home
|
115
117
|
end
|
118
|
+
|
119
|
+
def alt(page)
|
120
|
+
alt = ''
|
121
|
+
yaml = page['jb_picture']
|
122
|
+
if yaml && yaml.is_a?(Hash)
|
123
|
+
if yaml['alt']
|
124
|
+
alt = yaml['alt']
|
125
|
+
elsif yaml['caption']
|
126
|
+
alt = yaml['caption']
|
127
|
+
end
|
128
|
+
end
|
129
|
+
alt = 'Main picture' if alt.empty?
|
130
|
+
alt
|
131
|
+
end
|
116
132
|
end
|
117
133
|
|
118
134
|
# Box for testing and calling static methods.
|
data/test/test_picture.rb
CHANGED
@@ -34,6 +34,11 @@ module Jekyll
|
|
34
34
|
def test_generates_html_simple_head
|
35
35
|
html = JbBox.new.jb_picture_head('jb_picture' => '/img.png')
|
36
36
|
assert_match(/meta/, html)
|
37
|
+
assert_contains("<meta name='twitter:card' content='summary'/>", html)
|
38
|
+
assert_contains(
|
39
|
+
"<meta name='twitter:image:alt' content='Main picture'/>",
|
40
|
+
html
|
41
|
+
)
|
37
42
|
assert_match(/img\.png/, html)
|
38
43
|
end
|
39
44
|
|
@@ -45,17 +50,23 @@ module Jekyll
|
|
45
50
|
def test_generates_html_complex_head
|
46
51
|
html = JbBox.new.jb_picture_head(
|
47
52
|
'jb_picture' => {
|
48
|
-
'src' => '/img2.png'
|
53
|
+
'src' => '/img2.png',
|
54
|
+
'caption' => 'I love this image'
|
49
55
|
}
|
50
56
|
)
|
51
57
|
assert_match(/meta/, html)
|
52
58
|
assert_match(/img2\.png/, html)
|
59
|
+
assert_contains(
|
60
|
+
"<meta name='twitter:image:alt' content='I love this image'/>",
|
61
|
+
html
|
62
|
+
)
|
53
63
|
end
|
54
64
|
|
55
65
|
def test_calculates_image_size
|
56
66
|
html = JbBox.new.jb_picture_head(
|
57
67
|
'jb_picture' => {
|
58
|
-
'src' => 'http://www.yegor256.com/images/2017/02/the-deer-hunter.jpg'
|
68
|
+
'src' => 'http://www.yegor256.com/images/2017/02/the-deer-hunter.jpg',
|
69
|
+
'alt' => 'The Deer Hunter'
|
59
70
|
}
|
60
71
|
)
|
61
72
|
assert_match(/meta/, html)
|
@@ -63,6 +74,9 @@ module Jekyll
|
|
63
74
|
assert_contains("<meta name='og:image:height' content='543'/>", html)
|
64
75
|
assert_contains("<meta name='twitter:image:width' content='1280'/>", html)
|
65
76
|
assert_contains("<meta name='twitter:image:height' content='543'/>", html)
|
77
|
+
assert_contains(
|
78
|
+
"<meta name='twitter:image:alt' content='The Deer Hunter'/>", html
|
79
|
+
)
|
66
80
|
end
|
67
81
|
|
68
82
|
def test_generates_html_simple_body
|
@@ -90,8 +104,8 @@ module Jekyll
|
|
90
104
|
|
91
105
|
private
|
92
106
|
|
93
|
-
def assert_contains(substring, string
|
94
|
-
assert(string.include?(substring),
|
107
|
+
def assert_contains(substring, string)
|
108
|
+
assert(string.include?(substring), string)
|
95
109
|
end
|
96
110
|
end
|
97
111
|
end
|