jekyll-bits 0.11.1 → 0.12

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
  SHA1:
3
- metadata.gz: bcfb002ae25655d6e7c4fadb6c411d6c90853a79
4
- data.tar.gz: 10fe83344635175ed2bc45c16314acfc738753e5
3
+ metadata.gz: 34fe40d6e304fc584ff0f2db5ff4c88336602445
4
+ data.tar.gz: 6e649c35a6a6b96b472471c39766d0dcbfe3eec5
5
5
  SHA512:
6
- metadata.gz: d499957c8f8cf61fd135183c6b52fc1f1dbded175bca62fd913d2ba2914328f66a6af76d763e2e57cb9795bf992169ec22c2319fe3b5e899b0e7900f3c37eeec
7
- data.tar.gz: 1022ddc6f8b34eafd405eae8c666bd62ba2d6caddd49a2a3d0e12fac08d7be7b4a3ce989b0f50dbf7d977dfafe48e128b1404628a14bd43fe667b28e3c3900e5
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.1'
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'
@@ -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
- if yaml && yaml.is_a?(Hash) && yaml['alt']
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, *args)
94
- assert(string.include?(substring), *args)
107
+ def assert_contains(substring, string)
108
+ assert(string.include?(substring), string)
95
109
  end
96
110
  end
97
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-bits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko