Skip to content

Instantly share code, notes, and snippets.

@stuarthannig
Last active December 21, 2015 04:09
Show Gist options
  • Select an option

  • Save stuarthannig/6247443 to your computer and use it in GitHub Desktop.

Select an option

Save stuarthannig/6247443 to your computer and use it in GitHub Desktop.

Revisions

  1. stuarthannig renamed this gist Aug 16, 2013. 1 changed file with 0 additions and 0 deletions.
  2. stuarthannig created this gist Aug 16, 2013.
    12 changes: 12 additions & 0 deletions Submitted link Canonical URL Checker
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # http://kellishaver.tumblr.com/post/54922678930/quick-tip-canonical-urls
    # Building a site that handles link submissions? Check submitted links for a canonical URL tag to avoid duplicates.
    # Similarly, if you’re a content creator and you’re not using the canonical URL tag, you should be!

    def canonical(url)
    begin
    page = Nokogiri::HTML(open(url))
    page.css("link[rel=canonical]")[0]["href"]
    rescue
    url
    end
    end