lib/onebox/helpers.rb in onebox-2.2.16 vs lib/onebox/helpers.rb in onebox-2.2.17

- old
+ new

@@ -24,26 +24,10 @@ html.gsub(/<[^>]+>/, ' ').gsub(/\n/, '') end def self.fetch_html_doc(url, headers = nil, body_cacher = nil) response = (fetch_response(url, headers: headers, body_cacher: body_cacher) rescue nil) - doc = Nokogiri::HTML(response) - uri = Addressable::URI.parse(url) - - ignore_canonical_tag = doc.at('meta[property="og:ignore_canonical"]') - should_ignore_canonical = IGNORE_CANONICAL_DOMAINS.map { |hostname| uri.hostname.match?(hostname) }.any? - - unless (ignore_canonical_tag && ignore_canonical_tag['content'].to_s == 'true') || should_ignore_canonical - # prefer canonical link - canonical_link = doc.at('//link[@rel="canonical"]/@href') - canonical_uri = Addressable::URI.parse(canonical_link) - if canonical_link && "#{canonical_uri.host}#{canonical_uri.path}" != "#{uri.host}#{uri.path}" - response = (fetch_response(canonical_uri.to_s, headers: headers, body_cacher: body_cacher) rescue nil) - doc = Nokogiri::HTML(response) if response - end - end - - doc + Nokogiri::HTML(response) end def self.fetch_response(location, redirect_limit: 5, domain: nil, headers: nil, body_cacher: nil) redirect_limit = Onebox.options.redirect_limit if redirect_limit > Onebox.options.redirect_limit