Skip to content

Commit

Permalink
feat: allow static values to be set on object (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcbclifford authored Mar 12, 2019
1 parent 3a9dc87 commit de7b15b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ Defaults to `https://players.brightcove.net/{accountId}/{playerId}_{embedId}/ind

`excludeTags` - array of tags to not include as keywords, e.g. `["youtubesync"]`

`baseObject` - an option object of properties onto which to build the video specific metadata. For example this could be used to include a publisher object:

```json
"baseObject": {
"publisher": {
"@type": "Organization",
"name": "Publisher name",
"logo": {
"@type": "ImageObject",
"url": "https://example.com/logo.jpg",
"width": 600,
"height": 60
}
}
}
```

## Install

Add [as a plugin to a player in Video Cloud Studio][plugins]:
Expand Down
7 changes: 4 additions & 3 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import duration8601 from './duration';
const defaults = {
schemaId: 'https://players.brightcove.net/{accountId}/{playerId}_{embedId}/index.html?videoId={id}',
keywords: false,
excludeTags: []
excludeTags: [],
baseObject: {}
};

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ const schema = function(options) {
return;
}

const ld = {
const ld = videojs.mergeOptions(options.baseObject, {
'@context': 'http://schema.org/',
'@type': 'VideoObject',
'name': this.mediainfo.name,
Expand All @@ -51,7 +52,7 @@ const schema = function(options) {
.replace('{playerId}', this.bcinfo.playerId)
.replace('{embedId}', this.bcinfo.embedId)
.replace('{accountId}', this.bcinfo.accountId)
};
});

const formattedDuration = duration8601(this.mediainfo.duration);

Expand Down
17 changes: 17 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,20 @@ QUnit.test('includes tags if requested', function(assert) {

assert.strictEqual(generatedSchema.keywords, 'one,three', 'add tags except exclusions');
});

QUnit.test('merges onto base options', function(assert) {

this.player.schema({
baseObject: {
param1: 'abc'
}
});
this.player.trigger('error');

// Tick the clock forward enough to trigger the player to be "ready".
this.clock.tick(1);

const generatedSchema = JSON.parse(this.player.schemaEl_.textContent);

assert.strictEqual(generatedSchema.param1, 'abc', 'merged onto base options');
});

0 comments on commit de7b15b

Please sign in to comment.