Skip to content

Commit

Permalink
feat(talks): Add links to slide urls
Browse files Browse the repository at this point in the history
  • Loading branch information
bebraw committed May 7, 2018
1 parent 110b0c7 commit 2a5b36f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
51 changes: 49 additions & 2 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const talks = require("./talks");
const schedules = require("./schedules");
const talks = resolveSlideUrls(require("./talks"), schedules);
const people = resolveSocialLinks(require("./people"));
const enums = require("./enums");

Expand Down Expand Up @@ -44,7 +45,7 @@ module.exports = {
silverSponsors,
bronzeSponsors,
presentations,
schedules: require("./schedules"),
schedules,
speakers: associate(speakers, [
{
field: "keynotes",
Expand Down Expand Up @@ -135,3 +136,49 @@ function resolveSocialLinks(data) {
social: resolve(o.social, o),
}));
}

function resolveSlideUrls(talks, schedules) {
const talksArray = Object.values(talks);
const sessions = resolveSessions(schedules).filter(s => talksArray.indexOf(s) >= 0);

return Object.keys(talks).map((slug) => {
const talk = talks[slug];
const index = sessions.findIndex(t => t === talk);

return {
urls: {
slides: resolveSlideUrl(index + 1, slug)
},
...talk
}
});
}

function resolveSessions(schedules) {
return flatten(schedules.map(({ intervals }) => {
return flatten(intervals.map(({ sessions }) => sessions));
}));
}

// https://gist.github.com/Integralist/749153aa53fea7168e7e
function flatten(list) {
return list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
};

function resolveSlideUrl(index, slug) {
return `http://slides.react-finland.fi/2018/${leftFill({ amount: 2, character: 0, input: index })}-${slug}.pdf`
}

function leftFill({ amount, character, input }) {
const realAmount = amount - (input.toString()).length;

if (realAmount < 1) {
return input;
}

const characters = new Array(realAmount).fill(character).join('');

return characters + input;
}
2 changes: 1 addition & 1 deletion src/talks/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = Object.values(require('require-dir')());
module.exports = require('require-dir')();

8 changes: 7 additions & 1 deletion src/type-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ module.exports = `
speakers: [Contact],
tickets: [Ticket],
keywords: [String],
location: Contact
location: Contact,
urls: SessionUrls
}
type SessionUrls {
slides: String,
video: String
}
type Page {
Expand Down
14 changes: 14 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ assert.equal(
).title
);

assert.equal(
content.presentations.find(
o => o.title === "Declarative state and side effects"
).urls.slides,
'http://slides.react-finland.fi/2018/02-christian-alfoni.pdf'
);

assert.equal(
content.keynotes.find(
o => o.title === "How React changed everything"
).urls.slides,
'http://slides.react-finland.fi/2018/13-ken-wheeler.pdf'
);

assert.equal(
content.speakers.find(o => o.name === "Christian Alfoni").presentations[0]
.title,
Expand Down

0 comments on commit 2a5b36f

Please sign in to comment.