Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated og:image parsing to handle og:image:url as well #2

Open
wants to merge 1 commit into
base: patched
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ MetaInspector.prototype.getImage = function()
this.image = this.getAbsolutePath(img);
}
}
if (!this.image ) {
img = this.parsedDocument("meta[property='og:image:url']").attr("content");
if (img){
this.image = this.getAbsolutePath(img);
}
}

return this;
}
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ fakeweb.registerUri({uri: 'http://www.google.com:80/', file: path.join(__dirname
fakeweb.registerUri({uri: 'http://www.simple.com:80/', file: path.join(__dirname, 'simple.com.html')});
fakeweb.registerUri({uri: 'http://www.fastandfurious7-film.com:80/', file: path.join(__dirname, 'fastandfurious7-film.com.html')});
fakeweb.registerUri({uri: 'http://www.techsuplex.com:80/', file: path.join(__dirname, 'techsuplex.com.html')});
fakeweb.registerUri({uri: 'http://www.ogimageurl.com:80/', file: path.join(__dirname, 'ogimageurl.html')});
fakeweb.registerUri({uri: 'http://www.ogimage.com:80/', file: path.join(__dirname, 'ogimageurl.html')});

fakeweb.ignoreUri({uri: 'http://www.google-404.com:80/'});
fakeweb.ignoreUri({uri: 'http://www.google-404.com:80/'});
29 changes: 29 additions & 0 deletions test/fixtures/ogimage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<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">
</head>
<BODY BGCOLOR="FFFFFF">
<center><img src="clouds.jpg" ALIGN="BOTTOM"> </center>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<h1>This is a Header</h1>
<h2>This is a Medium Header</h2>
Send me mail at <a href="mailto:[email protected]">
[email protected]</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>
<img src="/image/relative.gif" alt="I am a relative image"/>
<img src="/image/relative2.gif" alt="I am another relative image"/>
<img src="http://placehold.it/350x150" alt="This is an absolute image">
<img src="https://placehold.it/350x65" alt="this is ssl absolute image">
<img src="//placehold.it/350x65" alt="this is another absolute image without a protocol">
</body>
</HTML>
29 changes: 29 additions & 0 deletions test/fixtures/ogimageurl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<HTML>
<head>
<title>This is my title!</title>
<meta property="og:title" content="I am an Open Graph title">
<meta property="og:image:url" 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">
</head>
<BODY BGCOLOR="FFFFFF">
<center><img src="clouds.jpg" ALIGN="BOTTOM"> </center>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<h1>This is a Header</h1>
<h2>This is a Medium Header</h2>
Send me mail at <a href="mailto:[email protected]">
[email protected]</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>
<img src="/image/relative.gif" alt="I am a relative image"/>
<img src="/image/relative2.gif" alt="I am another relative image"/>
<img src="http://placehold.it/350x150" alt="This is an absolute image">
<img src="https://placehold.it/350x65" alt="this is ssl absolute image">
<img src="//placehold.it/350x65" alt="this is another absolute image without a protocol">
</body>
</HTML>
Loading