Created
August 31, 2012 22:46
-
-
Save danielgrippi/3560391 to your computer and use it in GitHub Desktop.
grab json representation of a site's OG tags
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
function ogTags(nodes, nodeList) { | |
for(idx in nodeList) | |
if(validTag(nodeList[idx])) | |
nodes.push(nodeList[idx]) | |
return nodes | |
} | |
function validTag(node) { | |
var attrs = node.attributes | |
return attrs && attrs.property && attrs.property.value.search(/og:*/) != -1 | |
} | |
function nodeFields(nodeAttrs) { | |
return [ | |
nodeAttrs.property.value.slice(3), | |
nodeAttrs.content.value | |
] | |
} | |
function ogTagJson(obj, nodeList) { | |
ogTags([], nodeList).forEach(function(node){ | |
var fields = nodeFields(node.attributes) | |
obj[fields[0]] = fields[1] | |
}) | |
return obj | |
} | |
ogTagJson({}, window.document.getElementsByTagName("meta")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment