Skip to content

Commit

Permalink
feat: Option to add tags as keywords (#2)
Browse files Browse the repository at this point in the history
* feat: Option to add tags as keywords

* correct test message
  • Loading branch information
bcbclifford authored Mar 12, 2019
1 parent 692b8ed commit 36ecb36
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Accepts `{id}`, `{referenceId}`, `{playerId}`, `{embedId}` and `{accountId}` as

Defaults to `https://players.brightcove.net/{accountId}/{playerId}_{embedId}/index.html?videoId={id}`

`keywords` - if `true`, include tags as keywords. Default is `false`.

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

## Install

Add [as a plugin to a player in Video Cloud Studio][plugins]:
Expand Down
18 changes: 17 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import duration8601 from './duration';

// Default options for the plugin.
const defaults = {
schemaId: 'https://players.brightcove.net/{accountId}/{playerId}_{embedId}/index.html?videoId={id}'
schemaId: 'https://players.brightcove.net/{accountId}/{playerId}_{embedId}/index.html?videoId={id}',
keywords: false,
excludeTags: []
};

/**
Expand Down Expand Up @@ -64,6 +66,20 @@ const schema = function(options) {
ld.embedUrl = parser.querySelector('iframe').src;
}

if (options.keywords) {
const keywords = [];

this.mediainfo.tags.forEach(tag => {
if (options.excludeTags.indexOf(tag) === -1) {
keywords.push(tag);
}
});

if (keywords.length > 0) {
ld.keywords = keywords.join(',');
}
}

this.schemaEl_.textContent = JSON.stringify(ld);
});

Expand Down
19 changes: 18 additions & 1 deletion test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ QUnit.module('videojs-schema', {
description: 'DESCRIPTION',
duration: 3661,
publishedAt: '2019-02-12T09:07:44',
poster: 'https://loremflickr.com/1280/720'
poster: 'https://loremflickr.com/1280/720',
tags: ['one', 'two', 'three']
};
},

Expand Down Expand Up @@ -173,3 +174,19 @@ QUnit.test('does not add embed if disabled in social', function(assert) {
'embed url not added'
);
});

QUnit.test('includes tags if requested', function(assert) {

this.player.schema({
keywords: true,
excludeTags: ['two']
});
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.keywords, 'one,three', 'add tags except exclusions');
});

0 comments on commit 36ecb36

Please sign in to comment.