Skip to content

Instantly share code, notes, and snippets.

@danielgrippi
Created August 31, 2012 22:46
Show Gist options
  • Save danielgrippi/3560391 to your computer and use it in GitHub Desktop.
Save danielgrippi/3560391 to your computer and use it in GitHub Desktop.
grab json representation of a site's OG tags
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