Last active
December 21, 2015 04:09
-
-
Save stuarthannig/6247443 to your computer and use it in GitHub Desktop.
Check for canonical URLs from a submitted link.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment