Skip to content

Commit 3cb96b6

Browse files
committed
fixed #3
1 parent 7209863 commit 3cb96b6

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ ogp.type('website')
1818
ogp.description('description')
1919
ogp.site_name('site_name')
2020
ogp.url('http://ogp-meta.npm')
21-
// ogp.image('http://image url')
21+
ogp.image('http://image url')
22+
// reset
23+
ogp.image(null)
2224
ogp.image({
2325
url: 'http://image url',
2426
width: 400,
2527
height: 400
2628
})
27-
// ogp.video('http://video url')
29+
ogp.video('http://video url')
30+
// reset
31+
ogp.video(null)
2832
ogp.video({
2933
url: 'http://video url',
3034
width: 1024,

lib/ogp-meta.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ OpenGraph.prototype.setObject = function (type, obj) {
5050
* @param {string} image.height
5151
*/
5252
OpenGraph.prototype.image = function (image) {
53+
// reset
54+
if (!image) {
55+
return delete this.meta['og:image']
56+
}
57+
5358
// for kakaotalk
5459
if (image.url) {
5560
this.setObject('image', image.url)
@@ -67,6 +72,10 @@ OpenGraph.prototype.image = function (image) {
6772
* @param {string} video.height
6873
*/
6974
OpenGraph.prototype.video = function (video) {
75+
// reset
76+
if (!video) {
77+
return delete this.meta['og:video']
78+
}
7079
this.setObject('video', video)
7180
}
7281

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ogp-meta",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"author": {
55
"name": "egg",
66
"email": "[email protected]"

test/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ ogp.type('website')
77
ogp.description('description')
88
ogp.site_name('site_name')
99
ogp.url('http://ogp-meta.npm')
10-
// ogp.image('http://image url')
10+
ogp.image('http://image url')
11+
// reset
12+
ogp.image(null)
1113
ogp.image({
1214
url: 'http://image url',
1315
width: 400,
1416
height: 400
1517
})
16-
// ogp.video('http://video url')
18+
ogp.video('http://video url')
19+
// reset
20+
ogp.video(null)
1721
ogp.video({
1822
url: 'http://video url',
1923
width: 1024,

0 commit comments

Comments
 (0)