Module: Pope

Defined in:
lib/pope.rb,
lib/pope/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.canonize(input_url, typhoeus_options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/pope.rb', line 7

def self.canonize input_url, typhoeus_options = {}
  typhoeus_options.reverse_merge! follow_redirects: true

  # Fetch document
  response = Typhoeus::Request.get input_url, typhoeus_options
  doc = Nokogiri::HTML(response.body)

  # Parse out canonical URL tag if present
  (meta = doc.css('[rel="canonical"]').first) && meta.attr('href')
end