Skip to content

Commit

Permalink
feat(schema): Attach type information to people
Browse files Browse the repository at this point in the history
Now organizers and speakers are behind the same directory. No need to
separate as that's more complex. Enum is enough.
  • Loading branch information
bebraw committed Apr 29, 2018
1 parent 0f6e567 commit ccd892b
Show file tree
Hide file tree
Showing 89 changed files with 316 additions and 219 deletions.
203 changes: 108 additions & 95 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,124 +1,137 @@
const talks = require("./talks");
const speakers = resolveSocialLinks(require("./speakers"));
const organizers = resolveSocialLinks(require("./organizers"));
const people = resolveSocialLinks(require("./people"));
const enums = require("./enums");

const speakers = people.filter(({ type }) => type.some(equals(enums.SPEAKER)));
const organizers = people.filter(({ type }) =>
type.some(equals(enums.ORGANIZER))
);

const sponsors = resolveSocialLinks(require("./sponsors"));
const workshops = require("./workshops");
const enums = require("./enums");

const keynotes = talks.filter(({ type }) => type === enums.KEYNOTE);
const lightningTalks = talks.filter(
({ type }) => type === enums.LIGHTNING_TALK
({ type }) => type === enums.LIGHTNING_TALK
);
const presentations = talks.filter(({ type }) => type === enums.PRESENTATION);
const partners = sponsors.filter(({ type }) => type === enums.PARTNER);
const goldSponsors = sponsors.filter(({ type }) => type === enums.GOLD_SPONSOR);
const silverSponsors = sponsors.filter(
({ type }) => type === enums.SILVER_SPONSOR
const partners = sponsors.filter(({ type }) =>
type.some(equals(enums.PARTNER))
);
const goldSponsors = sponsors.filter(({ type }) =>
type.some(equals(enums.GOLD_SPONSOR))
);
const bronzeSponsors = sponsors.filter(
({ type }) => type === enums.BRONZE_SPONSOR
const silverSponsors = sponsors.filter(({ type }) =>
type.some(equals(enums.SILVER_SPONSOR))
);
const bronzeSponsors = sponsors.filter(({ type }) =>
type.some(equals(enums.BRONZE_SPONSOR))
);

module.exports = {
breakfasts: require("./breakfasts"),
coffeeBreaks: require("./coffee-breaks"),
locations: resolveSocialLinks(require('./locations')),
keynotes,
lightningTalks,
lunches: require("./lunches"),
organizers,
panels: require("./panels"),
pages: require("./pages"),
sponsors,
partners,
goldSponsors,
silverSponsors,
bronzeSponsors,
presentations,
schedules: require("./schedules"),
speakers: associate(speakers, [
{
field: "keynotes",
sourceData: keynotes,
condition: speakersContainSpeakerByName,
},
{
field: "lightningTalks",
sourceData: lightningTalks,
condition: speakersContainSpeakerByName,
},
{
field: "presentations",
sourceData: presentations,
condition: speakersContainSpeakerByName,
},
{
field: "talks",
sourceData: talks,
condition: speakersContainSpeakerByName,
},
{
field: "workshops",
sourceData: workshops,
condition: speakersContainSpeakerByName,
},
]),
talks,
tickets: require("./tickets"),
workshops,
breakfasts: require("./breakfasts"),
coffeeBreaks: require("./coffee-breaks"),
locations: resolveSocialLinks(require("./locations")),
keynotes,
lightningTalks,
lunches: require("./lunches"),
organizers,
panels: require("./panels"),
pages: require("./pages"),
sponsors,
partners,
goldSponsors,
silverSponsors,
bronzeSponsors,
presentations,
schedules: require("./schedules"),
speakers: associate(speakers, [
{
field: "keynotes",
sourceData: keynotes,
condition: speakersContainSpeakerByName,
},
{
field: "lightningTalks",
sourceData: lightningTalks,
condition: speakersContainSpeakerByName,
},
{
field: "presentations",
sourceData: presentations,
condition: speakersContainSpeakerByName,
},
{
field: "talks",
sourceData: talks,
condition: speakersContainSpeakerByName,
},
{
field: "workshops",
sourceData: workshops,
condition: speakersContainSpeakerByName,
},
]),
talks,
tickets: require("./tickets"),
workshops,
};

function associate(data, rules) {
return data.map(target => {
const associations = {};

rules.forEach(({ field, sourceData, condition }) => {
sourceData.forEach(source => {
if (condition({ source, target })) {
if (!associations[field]) {
associations[field] = [];
}
return data.map(target => {
const associations = {};

associations[field].push(source);
}
});
});
rules.forEach(({ field, sourceData, condition }) => {
sourceData.forEach(source => {
if (condition({ source, target })) {
if (!associations[field]) {
associations[field] = [];
}

return Object.assign({}, target, associations);
associations[field].push(source);
}
});
});

return Object.assign({}, target, associations);
});
}

function equals(expected) {
return value => value === expected;
}

function speakersContainSpeakerByName({
source: { speakers },
target: { name },
source: { speakers },
target: { name },
}) {
return speakers.map(({ name }) => name).indexOf(name) >= 0;
return speakers.map(({ name }) => name).indexOf(name) >= 0;
}

function resolveSocialLinks(data) {
function resolve(social, o) {
const rules = {
homepage: social.homepage,
facebook: `https://facebook.com/${social.facebook}`,
github: `https://github.com/${social.github}`,
linkedin: `https://linkedin.com/${social.linkedin}`,
medium: `https://medium.com/${social.medium}`,
instagram: `https://instagram.com/${social.instagram}`,
twitter: `https://twitter.com/${social.twitter}`,
youtube: `https://www.youtube.com/${social.youtube}`,
vk: `https://vk.com/${social.vk}`,
};
const ret = {};
function resolve(social, o) {
const rules = {
homepage: social.homepage,
facebook: `https://facebook.com/${social.facebook}`,
github: `https://github.com/${social.github}`,
linkedin: `https://linkedin.com/${social.linkedin}`,
medium: `https://medium.com/${social.medium}`,
instagram: `https://instagram.com/${social.instagram}`,
twitter: `https://twitter.com/${social.twitter}`,
youtube: `https://www.youtube.com/${social.youtube}`,
vk: `https://vk.com/${social.vk}`,
};
const ret = {};

Object.keys(social).forEach(media => {
ret[media] = rules[media];
});
Object.keys(social).forEach(media => {
ret[media] = rules[media];
});

return ret;
}
return ret;
}

return data.map(o => ({
...o,
social: resolve(o.social, o),
}));
return data.map(o => ({
...o,
social: resolve(o.social, o),
}));
}
2 changes: 2 additions & 0 deletions src/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module.exports = {
GOLD_SPONSOR: "goldSponsor",
KEYNOTE: "keynote",
LIGHTNING_TALK: "lightningTalk",
ORGANIZER: "organizer",
PARTNER: "partner",
PRESENTATION: "presentation",
SILVER_SPONSOR: "silverSponsor",
SPEAKER: "speaker",
};
9 changes: 0 additions & 9 deletions src/organizers/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/organizers/juho-vepsalainen.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/speakers/_template.js → src/people/_template.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
Expand All @@ -22,4 +23,5 @@ module.exports = {
city: "", // TODO: City name
},
keywords: [keywords.REACT], // TODO: check keywords for more
type: [enums.SPEAKER],
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const enums = require("../enums");

module.exports = {
name: "Aarni Koskela",
about: "Aarni works on the site and the app. Specializes in terrible puns.",
Expand All @@ -15,4 +17,5 @@ module.exports = {
},
},
keywords: [],
type: [enums.ORGANIZER],
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const enums = require("../enums");

module.exports = {
name: "Aleksi Pousar",
about:
Expand All @@ -16,4 +18,5 @@ module.exports = {
},
},
keywords: [],
type: [enums.ORGANIZER],
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
Expand All @@ -23,4 +24,5 @@ module.exports = {
keywords.STYLE_GUIDES,
keywords.TOOLING,
],
type: [enums.SPEAKER],
};
2 changes: 2 additions & 0 deletions src/speakers/artem-sapegin.js → src/people/artem-sapegin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
Expand Down Expand Up @@ -25,4 +26,5 @@ module.exports = {
keywords.STYLE_GUIDES,
keywords.TOOLING,
],
type: [enums.SPEAKER],
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
Expand All @@ -18,4 +19,5 @@ module.exports = {
city: "Trondheim",
},
keywords: [keywords.CEREBRAL, keywords.REACT, keywords.STATE_MANAGEMENT],
type: [enums.SPEAKER],
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
Expand All @@ -19,4 +20,5 @@ module.exports = {
city: "Orlando",
},
keywords: [keywords.REACT, keywords.STATE_MANAGEMENT],
type: [enums.SPEAKER],
};
23 changes: 23 additions & 0 deletions src/people/eemeli-aro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
name: "Eemeli Aro",
about:
"Eemeli has been falling down the rabbit hole of JavaScript localization for about six years now, and keeps wondering at what the next level might be. For work he makes complicated systems seem simple, for fun he writes open-source libraries, and in his spare time he organises science fiction conventions.",
image: "speakers/eemeli.jpg",
social: {
homepage: "",
twitter: "eemeli_aro",
github: "eemeli",
},
location: {
country: {
name: "Finland",
code: "FI",
},
city: "Helsinki",
},
keywords: [keywords.TOOLING, keywords.REACT],
type: [enums.SPEAKER],
};
2 changes: 2 additions & 0 deletions src/speakers/gant-laborde.js → src/people/gant-laborde.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const enums = require("../enums");
const keywords = require("../keywords");

module.exports = {
Expand All @@ -19,4 +20,5 @@ module.exports = {
city: "New Orleans",
},
keywords: [keywords.REACT, keywords.REACT_NATIVE],
type: [enums.SPEAKER],
};
3 changes: 3 additions & 0 deletions src/organizers/harri-maatta.js → src/people/harri-maatta.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const enums = require("../enums");

module.exports = {
name: "Harri Määttä",
about:
Expand All @@ -16,4 +18,5 @@ module.exports = {
},
},
keywords: [],
type: [enums.ORGANIZER],
};
Loading

0 comments on commit ccd892b

Please sign in to comment.