lib/onebox/engine/standard_embed.rb in onebox-1.8.26 vs lib/onebox/engine/standard_embed.rb in onebox-1.8.27
- old
+ new
@@ -42,10 +42,13 @@
og.each { |k, v| @raw[k] ||= v unless Onebox::Helpers::blank?(v) }
twitter.each { |k, v| @raw[k] ||= v unless Onebox::Helpers::blank?(v) }
oembed.each { |k, v| @raw[k] ||= v unless Onebox::Helpers::blank?(v) }
+ favicon = get_favicon
+ @raw["favicon".to_sym] = favicon unless Onebox::Helpers::blank?(favicon)
+
@raw
end
protected
@@ -108,9 +111,23 @@
twitter[$1.tr('-:' , '_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
end
end
twitter
+ end
+
+ def get_favicon
+ return nil unless html_doc
+
+ favicon = html_doc.css('link[rel="shortcut icon"], link[rel="icon shortcut"], link[rel="shortcut"], link[rel="icon"]').first
+ favicon = favicon.nil? ? nil : favicon['href']&.strip
+
+ if favicon && favicon.match(/^https?:\/\//i).nil?
+ uri = URI(url)
+ favicon = uri.scheme + "://" + uri.host.sub(/\/$/,"") + "/" + favicon.sub(/^\//,"")
+ end
+
+ favicon
end
end
end
end