lib/jekyll-bits/picture.rb in jekyll-bits-0.11.1 vs lib/jekyll-bits/picture.rb in jekyll-bits-0.12
- old
+ new
@@ -46,24 +46,26 @@
end
if height
html += "<meta name='og:image:height' content='#{height}'/>
<meta name='twitter:image:height' content='#{height}'/>"
end
+ if width && width >= 1024 && height && height >= 768
+ html += "<meta name='twitter:card' content='summary_large_image'/>"
+ else
+ html += "<meta name='twitter:card' content='summary'/>"
+ end
+ html += "<meta name='twitter:image:alt' \
+content='#{CGI.escapeHTML(alt(page))}'/>"
html
end
def jb_picture_body(page)
uri = uri(page)
return '' if uri.empty?
yaml = page['jb_picture']
- html = "<img itemprop='image' alt='"
- if yaml && yaml.is_a?(Hash) && yaml['alt']
- html += CGI.escapeHTML(yaml['alt'])
- else
- html += 'front image'
- end
- html += "' src='#{CGI.escapeElement(uri)}'"
+ html = "<img itemprop='image' alt='#{CGI.escapeHTML(alt(page))}'"
+ html += " src='#{CGI.escapeElement(uri)}'"
md5 = Digest::MD5.new.hexdigest(uri)[0, 8]
html += " longdesc='##{md5}'" \
if yaml.is_a?(Hash) && yaml['caption']
html += " width='#{yaml['width']}'" \
if yaml.is_a?(Hash) && yaml['width']
@@ -110,9 +112,23 @@
else
@@home.gsub!(%r{/$}, '')
end
end
@@home
+ end
+
+ def alt(page)
+ alt = ''
+ yaml = page['jb_picture']
+ if yaml && yaml.is_a?(Hash)
+ if yaml['alt']
+ alt = yaml['alt']
+ elsif yaml['caption']
+ alt = yaml['caption']
+ end
+ end
+ alt = 'Main picture' if alt.empty?
+ alt
end
end
# Box for testing and calling static methods.
class JbBox