Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
node_modules
build
*.node
components
components
/.idea
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ client.description # returns the meta description, or the first long pa
client.image # Most relevant image, if defined with og:image
client.images # array of strings, with every img found on the page as an absolute URL
client.feeds # Get rss or atom links in meta data fields as array
client.ogTitle # opengraph title
client.ogDescription # opengraph description
client.ogTitle # Open Graph title
client.ogDescription # Open Graph description
client.ogType # Open Graph Object Type
client.ogUpdatedTime # Open Graph Updated Time
client.ogLocale # Open Graph Locale - for languages
client.ogUrl # Open Graph URL
```

### Options
Expand Down
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ MetaInspector.prototype.getOgLocale = function()
return this;
}

MetaInspector.prototype.getOgUrl = function()
{
debug("Parsing page url based on the Open Graph url");

if(!this.ogUrl)
{
this.ogUrl = this.parsedDocument("meta[property='og:url']").attr("content");
}

return this;
}

MetaInspector.prototype.getLinks = function()
{
debug("Parsing page links");
Expand Down Expand Up @@ -291,7 +303,8 @@ MetaInspector.prototype.initAllProperties = function()
.getOgDescription()
.getOgType()
.getOgUpdatedTime()
.getOgLocale();
.getOgLocale()
.getOgUrl();
}

MetaInspector.prototype.getAbsolutePath = function(href){
Expand Down
20 changes: 11 additions & 9 deletions test/fixtures/simple.com.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<HTML>
<head>
<title>This is my title!</title>
<meta property="og:title" content="I am an Open Graph title">
<meta property="og:image" content="http://placehold.it/350x150">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Author Name">
<meta charset="UTF-8">
<link rel="alternate" type="application/rss+xml" title="CNN.com: Top Stories" href="http://rss.cnn.com/rss/cnn_topstories.rss">
<link rel="alternate" type="application/rss+xml" title="CNN.com: World" href="http://rss.cnn.com/rss/cnn_world.rss">
<title>This is my title!</title>
<meta property="og:title" content="I am an Open Graph title">
<meta property="og:image" content="http://placehold.it/350x150">
<meta property="og:url" content="http://www.cnn.com">
<meta property="og:type" content="website">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Author Name">
<meta charset="UTF-8">
<link rel="alternate" type="application/rss+xml" title="CNN.com: Top Stories" href="http://rss.cnn.com/rss/cnn_topstories.rss">
<link rel="alternate" type="application/rss+xml" title="CNN.com: World" href="http://rss.cnn.com/rss/cnn_world.rss">
</head>
<BODY BGCOLOR="FFFFFF">
<center><img src="clouds.jpg" ALIGN="BOTTOM"> </center>
Expand All @@ -16,7 +18,7 @@
<h1>This is a Header</h1>
<h2>This is a Medium Header</h2>
Send me mail at <a href="mailto:support@yourcompany.com">
support@yourcompany.com</a>.
support@yourcompany.com</a>.
<p>This is a new paragraph! This paragraph should be very long so we can grab it as the secondary description. What do you think of that?</p>
<p>This is a new paragraph!</p>
<br> <b><i>This is a new sentence without a paragraph break, in bold italics.</i></b>
Expand Down
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,28 @@ describe('metainspector', function(){

client.fetch();
});

it('should return the open graph url if defined', function(done){
client = new MetaInspector("http://www.simple.com", {});

client.once("fetch", function(){
client.ogUrl.should.exist;
client.ogUrl.should.equal("http://www.cnn.com");
done();
});

client.fetch();
});

it('should return undefined if there is no og:url', function(done){
client = new MetaInspector("http://www.google.com", {});

client.once("fetch", function(){
should.not.exist(client.ogUrl);
done();
});

client.fetch();
});
});
});