Module: Jekyll::JbFilters
- Included in:
- JbBox
- Defined in:
- lib/jekyll-bits/picture.rb
Overview
All our custom filters
Instance Method Summary collapse
Instance Method Details
#jb_picture_body(page) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jekyll-bits/picture.rb', line 61 def jb_picture_body(page) uri = uri(page) return '' if uri.empty? yaml = page['jb_picture'] 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'] html += " height='#{yaml['height']}'" \ if yaml.is_a?(Hash) && yaml['height'] html += '/>' html = "<a href='#{CGI.escapeHTML(yaml['href'])}'>#{html}</a>" \ if yaml.is_a?(Hash) && yaml['href'] html = "<figure class='jb_picture'>" + html if yaml.is_a?(Hash) && yaml['caption'] html += "<figcaption id='#{md5}'>" \ "#{CGI.escapeHTML(yaml['caption'])}</figcaption>" end html + '</figure>' end |
#jb_picture_head(page) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jekyll-bits/picture.rb', line 34 def jb_picture_head(page) uri = uri(page) return '' if uri.empty? html = "<meta name='og:image' content='#{CGI.escapeElement(uri)}'/>" html += "<meta name='twitter:image' content='#{CGI.escapeElement(uri)}'/>" path = uri path = File.join(Dir.pwd, path) unless \ %w(http https).include?(URI.parse(uri).scheme) width, height = FastImage.size(path) if width html += "<meta name='og:image:width' content='#{width}'/> <meta name='twitter:image:width' content='#{width}'/>" end if height html += "<meta name='og:image:height' content='#{height}'/> <meta name='twitter:image:height' content='#{height}'/>" end if width && width >= 640 && height && height >= 480 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 |