Permalink
Browse files

Support several OpenGraph tags with same property name (output them a…

…s array)
  • Loading branch information...
SpeCT committed Apr 6, 2012
1 parent afd8199 commit fae09f0ce8755139fc8b8ee278b09ac72efd624d
Showing with 14 additions and 3 deletions.
  1. +7 −1 README.md
  2. +6 −1 lib/ogp.js
  3. +1 −1 package.json
View
@@ -34,14 +34,20 @@ jsdom.env({ html: url, done: function(error, window) {
This will put next structure into stdout:
-```
+```javascript
{ url: 'http://www.imdb.com/title/tt0068646/',
title: 'The Godfather (1972)',
type: 'video.movie',
image: 'http://ia.media-imdb.com/images/M/MV5BMTIyMTIxNjI5NF5BMl5BanBnXkFtZTcwNzQzNDM5MQ@@._V1._SX97_SY140_.jpg',
site_name: 'IMDb' }
```
+In case if some of OpenGraph tags were presented multiple times (few image tags for example, output structure field related to that tag will be converted into array:
+
+```javascript
+{ image: ['image1.png', 'image2.png']}
+```
+
## Credits
Written and maintained by [Yury Proshchenko](mailto:spect.man@gmail.com).
View
@@ -23,7 +23,12 @@ exports.parse = function(window) {
var property = tag.attributes['property'].nodeValue.substring(ns.length+1),
content = tag.attributes['content'].nodeValue
- result[property] = content
+ if (!result[property])
+ result[property] = content
+ else if (result[property].push)
+ result[property].push(content)
+ else
+ result[property] = [result[property], content]
}
return result
View
@@ -1,7 +1,7 @@
{
"name": "ogp",
"description": "Parse Open Graph meta tags from jsdom generated DOM",
- "version": "0.0.1",
+ "version": "0.0.2",
"author": "Yury Proshchenko <spect.man@gmail.com>",
"contributors": [
{ "name": "Yury Proshchenko", "email": "spect.man@gmail.com" }

0 comments on commit fae09f0

Please sign in to comment.