|
1 | 1 | const talks = require("./talks"); |
2 | | -const speakers = resolveSocialLinks(require("./speakers")); |
3 | | -const organizers = resolveSocialLinks(require("./organizers")); |
| 2 | +const people = resolveSocialLinks(require("./people")); |
| 3 | +const enums = require("./enums"); |
| 4 | + |
| 5 | +const speakers = people.filter(({ type }) => type.some(equals(enums.SPEAKER))); |
| 6 | +const organizers = people.filter(({ type }) => |
| 7 | + type.some(equals(enums.ORGANIZER)) |
| 8 | +); |
| 9 | + |
4 | 10 | const sponsors = resolveSocialLinks(require("./sponsors")); |
5 | 11 | const workshops = require("./workshops"); |
6 | | -const enums = require("./enums"); |
7 | 12 |
|
8 | 13 | const keynotes = talks.filter(({ type }) => type === enums.KEYNOTE); |
9 | 14 | const lightningTalks = talks.filter( |
10 | | - ({ type }) => type === enums.LIGHTNING_TALK |
| 15 | + ({ type }) => type === enums.LIGHTNING_TALK |
11 | 16 | ); |
12 | 17 | const presentations = talks.filter(({ type }) => type === enums.PRESENTATION); |
13 | | -const partners = sponsors.filter(({ type }) => type === enums.PARTNER); |
14 | | -const goldSponsors = sponsors.filter(({ type }) => type === enums.GOLD_SPONSOR); |
15 | | -const silverSponsors = sponsors.filter( |
16 | | - ({ type }) => type === enums.SILVER_SPONSOR |
| 18 | +const partners = sponsors.filter(({ type }) => |
| 19 | + type.some(equals(enums.PARTNER)) |
| 20 | +); |
| 21 | +const goldSponsors = sponsors.filter(({ type }) => |
| 22 | + type.some(equals(enums.GOLD_SPONSOR)) |
17 | 23 | ); |
18 | | -const bronzeSponsors = sponsors.filter( |
19 | | - ({ type }) => type === enums.BRONZE_SPONSOR |
| 24 | +const silverSponsors = sponsors.filter(({ type }) => |
| 25 | + type.some(equals(enums.SILVER_SPONSOR)) |
| 26 | +); |
| 27 | +const bronzeSponsors = sponsors.filter(({ type }) => |
| 28 | + type.some(equals(enums.BRONZE_SPONSOR)) |
20 | 29 | ); |
21 | 30 |
|
22 | 31 | module.exports = { |
23 | | - breakfasts: require("./breakfasts"), |
24 | | - coffeeBreaks: require("./coffee-breaks"), |
25 | | - locations: resolveSocialLinks(require('./locations')), |
26 | | - keynotes, |
27 | | - lightningTalks, |
28 | | - lunches: require("./lunches"), |
29 | | - organizers, |
30 | | - panels: require("./panels"), |
31 | | - pages: require("./pages"), |
32 | | - sponsors, |
33 | | - partners, |
34 | | - goldSponsors, |
35 | | - silverSponsors, |
36 | | - bronzeSponsors, |
37 | | - presentations, |
38 | | - schedules: require("./schedules"), |
39 | | - speakers: associate(speakers, [ |
40 | | - { |
41 | | - field: "keynotes", |
42 | | - sourceData: keynotes, |
43 | | - condition: speakersContainSpeakerByName, |
44 | | - }, |
45 | | - { |
46 | | - field: "lightningTalks", |
47 | | - sourceData: lightningTalks, |
48 | | - condition: speakersContainSpeakerByName, |
49 | | - }, |
50 | | - { |
51 | | - field: "presentations", |
52 | | - sourceData: presentations, |
53 | | - condition: speakersContainSpeakerByName, |
54 | | - }, |
55 | | - { |
56 | | - field: "talks", |
57 | | - sourceData: talks, |
58 | | - condition: speakersContainSpeakerByName, |
59 | | - }, |
60 | | - { |
61 | | - field: "workshops", |
62 | | - sourceData: workshops, |
63 | | - condition: speakersContainSpeakerByName, |
64 | | - }, |
65 | | - ]), |
66 | | - talks, |
67 | | - tickets: require("./tickets"), |
68 | | - workshops, |
| 32 | + breakfasts: require("./breakfasts"), |
| 33 | + coffeeBreaks: require("./coffee-breaks"), |
| 34 | + locations: resolveSocialLinks(require("./locations")), |
| 35 | + keynotes, |
| 36 | + lightningTalks, |
| 37 | + lunches: require("./lunches"), |
| 38 | + organizers, |
| 39 | + panels: require("./panels"), |
| 40 | + pages: require("./pages"), |
| 41 | + sponsors, |
| 42 | + partners, |
| 43 | + goldSponsors, |
| 44 | + silverSponsors, |
| 45 | + bronzeSponsors, |
| 46 | + presentations, |
| 47 | + schedules: require("./schedules"), |
| 48 | + speakers: associate(speakers, [ |
| 49 | + { |
| 50 | + field: "keynotes", |
| 51 | + sourceData: keynotes, |
| 52 | + condition: speakersContainSpeakerByName, |
| 53 | + }, |
| 54 | + { |
| 55 | + field: "lightningTalks", |
| 56 | + sourceData: lightningTalks, |
| 57 | + condition: speakersContainSpeakerByName, |
| 58 | + }, |
| 59 | + { |
| 60 | + field: "presentations", |
| 61 | + sourceData: presentations, |
| 62 | + condition: speakersContainSpeakerByName, |
| 63 | + }, |
| 64 | + { |
| 65 | + field: "talks", |
| 66 | + sourceData: talks, |
| 67 | + condition: speakersContainSpeakerByName, |
| 68 | + }, |
| 69 | + { |
| 70 | + field: "workshops", |
| 71 | + sourceData: workshops, |
| 72 | + condition: speakersContainSpeakerByName, |
| 73 | + }, |
| 74 | + ]), |
| 75 | + talks, |
| 76 | + tickets: require("./tickets"), |
| 77 | + workshops, |
69 | 78 | }; |
70 | 79 |
|
71 | 80 | function associate(data, rules) { |
72 | | - return data.map(target => { |
73 | | - const associations = {}; |
74 | | - |
75 | | - rules.forEach(({ field, sourceData, condition }) => { |
76 | | - sourceData.forEach(source => { |
77 | | - if (condition({ source, target })) { |
78 | | - if (!associations[field]) { |
79 | | - associations[field] = []; |
80 | | - } |
| 81 | + return data.map(target => { |
| 82 | + const associations = {}; |
81 | 83 |
|
82 | | - associations[field].push(source); |
83 | | - } |
84 | | - }); |
85 | | - }); |
| 84 | + rules.forEach(({ field, sourceData, condition }) => { |
| 85 | + sourceData.forEach(source => { |
| 86 | + if (condition({ source, target })) { |
| 87 | + if (!associations[field]) { |
| 88 | + associations[field] = []; |
| 89 | + } |
86 | 90 |
|
87 | | - return Object.assign({}, target, associations); |
| 91 | + associations[field].push(source); |
| 92 | + } |
| 93 | + }); |
88 | 94 | }); |
| 95 | + |
| 96 | + return Object.assign({}, target, associations); |
| 97 | + }); |
| 98 | +} |
| 99 | + |
| 100 | +function equals(expected) { |
| 101 | + return value => value === expected; |
89 | 102 | } |
90 | 103 |
|
91 | 104 | function speakersContainSpeakerByName({ |
92 | | - source: { speakers }, |
93 | | - target: { name }, |
| 105 | + source: { speakers }, |
| 106 | + target: { name }, |
94 | 107 | }) { |
95 | | - return speakers.map(({ name }) => name).indexOf(name) >= 0; |
| 108 | + return speakers.map(({ name }) => name).indexOf(name) >= 0; |
96 | 109 | } |
97 | 110 |
|
98 | 111 | function resolveSocialLinks(data) { |
99 | | - function resolve(social, o) { |
100 | | - const rules = { |
101 | | - homepage: social.homepage, |
102 | | - facebook: `https://facebook.com/${social.facebook}`, |
103 | | - github: `https://github.com/${social.github}`, |
104 | | - linkedin: `https://linkedin.com/${social.linkedin}`, |
105 | | - medium: `https://medium.com/${social.medium}`, |
106 | | - instagram: `https://instagram.com/${social.instagram}`, |
107 | | - twitter: `https://twitter.com/${social.twitter}`, |
108 | | - youtube: `https://www.youtube.com/${social.youtube}`, |
109 | | - vk: `https://vk.com/${social.vk}`, |
110 | | - }; |
111 | | - const ret = {}; |
| 112 | + function resolve(social, o) { |
| 113 | + const rules = { |
| 114 | + homepage: social.homepage, |
| 115 | + facebook: `https://facebook.com/${social.facebook}`, |
| 116 | + github: `https://github.com/${social.github}`, |
| 117 | + linkedin: `https://linkedin.com/${social.linkedin}`, |
| 118 | + medium: `https://medium.com/${social.medium}`, |
| 119 | + instagram: `https://instagram.com/${social.instagram}`, |
| 120 | + twitter: `https://twitter.com/${social.twitter}`, |
| 121 | + youtube: `https://www.youtube.com/${social.youtube}`, |
| 122 | + vk: `https://vk.com/${social.vk}`, |
| 123 | + }; |
| 124 | + const ret = {}; |
112 | 125 |
|
113 | | - Object.keys(social).forEach(media => { |
114 | | - ret[media] = rules[media]; |
115 | | - }); |
| 126 | + Object.keys(social).forEach(media => { |
| 127 | + ret[media] = rules[media]; |
| 128 | + }); |
116 | 129 |
|
117 | | - return ret; |
118 | | - } |
| 130 | + return ret; |
| 131 | + } |
119 | 132 |
|
120 | | - return data.map(o => ({ |
121 | | - ...o, |
122 | | - social: resolve(o.social, o), |
123 | | - })); |
| 133 | + return data.map(o => ({ |
| 134 | + ...o, |
| 135 | + social: resolve(o.social, o), |
| 136 | + })); |
124 | 137 | } |
0 commit comments