1 | const data = require('./data');
|
2 |
|
3 | const pair = ([ taxonomy, name, id ]) => {
|
4 | return { id, name, taxonomy };
|
5 | };
|
6 |
|
7 | module.exports.uniqueTags = function () {
|
8 | const unique = new Map();
|
9 |
|
10 | Object.keys(data).forEach((show) => {
|
11 | data[show].tags.forEach((tag) => {
|
12 | const tagId = tag[2];
|
13 |
|
14 | if (!unique.has(tagId)) {
|
15 | unique.set(tagId, tag);
|
16 | }
|
17 | });
|
18 | });
|
19 |
|
20 | return Array.from(unique.values()).map(pair);
|
21 | };
|
22 |
|
23 | module.exports.primaryTags = function () {
|
24 | const primaryTags = [];
|
25 |
|
26 | Object.keys(data).forEach((show) => {
|
27 | data[show].tags.forEach((tag) => {
|
28 | const taxonomy = tag[0];
|
29 |
|
30 | if (taxonomy === 'primarySection') {
|
31 | primaryTags.push(tag);
|
32 | }
|
33 | })
|
34 | });
|
35 |
|
36 | return primaryTags.map(pair);
|
37 | };
|
38 |
|
39 | module.exports.metadataFor = function (show) {
|
40 | if (!data.hasOwnProperty(show)) {
|
41 | return [];
|
42 | }
|
43 |
|
44 | return data[show].tags.map(pair);
|
45 | };
|
46 |
|
47 | module.exports.annotationsFor = function (show) {
|
48 | if (!data.hasOwnProperty(show)) {
|
49 | return [];
|
50 | }
|
51 |
|
52 | return data[show].annotations;
|
53 | };
|
54 |
|
55 | module.exports.linksFor = function (show) {
|
56 | if (!data.hasOwnProperty(show)) {
|
57 | return [];
|
58 | }
|
59 |
|
60 | return data[show].links;
|
61 | };
|
62 |
|
63 | module.exports.isThisTagAPodcast = function (tagId) {
|
64 | const podcastTags = this.primaryTags();
|
65 | return podcastTags.some((tag) => tag.id === tagId);
|
66 | };
|