class Jekyll::Linkpreview::OpenGraphPropertiesFactory
Public Instance Methods
from_hash(hash)
click to toggle source
# File lib/jekyll-linkpreview.rb, line 58 def from_hash(hash) OpenGraphProperties.new( hash['title'], hash['url'], hash['image'], hash['description'], hash['domain']) end
from_page(page)
click to toggle source
# File lib/jekyll-linkpreview.rb, line 47 def from_page(page) og_properties = page.meta_tags['property'] image_url = get_og_property(og_properties, 'og:image') title = get_og_property(og_properties, 'og:title') url = get_og_property(og_properties, 'og:url') image = convert_to_absolute_url(image_url, page.root_url) description = get_og_property(og_properties, 'og:description') domain = page.host OpenGraphProperties.new(title, url, image, description, domain) end
Private Instance Methods
convert_to_absolute_url(url, domain)
click to toggle source
# File lib/jekyll-linkpreview.rb, line 72 def convert_to_absolute_url(url, domain) if url.nil? then return nil end # root relative url if url[0] == '/' then return URI.join(domain, url).to_s end url end
get_og_property(properties, key)
click to toggle source
# File lib/jekyll-linkpreview.rb, line 64 def get_og_property(properties, key) if !properties.key? key then return nil end properties[key].first end