Skip to content

Commit 54404d5

Browse files
Add tests for og:updated_time in open_graph helper, & add ability to turn it off
1 parent 569856e commit 54404d5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/plugins/helper/open_graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function openGraphHelper(options) {
3737
var url = options.url || this.url;
3838
var siteName = options.site_name || config.title;
3939
var twitterCard = options.twitter_card || 'summary';
40-
var updated = options.updated || page.updated;
40+
var updated = options.updated !== false ? (options.updated || page.updated) : false;
4141
var result = '';
4242

4343
if (!Array.isArray(images)) images = [images];

test/scripts/helpers/open_graph.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var moment = require('moment');
34
var should = require('chai').should(); // eslint-disable-line
45

56
describe('open_graph', function() {
@@ -371,4 +372,35 @@ describe('open_graph', function() {
371372

372373
result.should.contain(meta({property: 'fb:app_id', content: '123456789'}));
373374
});
375+
376+
it('updated - options', function() {
377+
var result = openGraph.call({
378+
page: { updated: moment('2016-05-23T21:20:21.372Z') },
379+
config: {},
380+
is_post: isPost
381+
}, { });
382+
383+
result.should.contain(meta({property: 'og:updated_time', content: '2016-05-23T21:20:21.372Z'}));
384+
});
385+
386+
it('updated - options - allow overriding og:updated_time', function() {
387+
var result = openGraph.call({
388+
page: { updated: moment('2016-05-23T21:20:21.372Z') },
389+
config: {},
390+
is_post: isPost
391+
}, { updated: moment('2015-04-22T20:19:20.371Z') });
392+
393+
result.should.contain(meta({property: 'og:updated_time', content: '2015-04-22T20:19:20.371Z'}));
394+
});
395+
396+
it('updated - options - allow disabling og:updated_time', function() {
397+
var result = openGraph.call({
398+
page: { updated: moment('2016-05-23T21:20:21.372Z') },
399+
config: {},
400+
is_post: isPost
401+
}, { updated: false });
402+
403+
result.should.not.contain(meta({property: 'og:updated_time', content: '2016-05-23T21:20:21.372Z'}));
404+
});
405+
374406
});

0 commit comments

Comments
 (0)