diff --git a/src/content.js b/src/content.js index e8116e4..4875c34 100644 --- a/src/content.js +++ b/src/content.js @@ -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"); @@ -44,7 +45,7 @@ module.exports = { silverSponsors, bronzeSponsors, presentations, - schedules: require("./schedules"), + schedules, speakers: associate(speakers, [ { field: "keynotes", @@ -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; +} diff --git a/src/talks/index.js b/src/talks/index.js index 1df753d..4386e19 100644 --- a/src/talks/index.js +++ b/src/talks/index.js @@ -1,2 +1,2 @@ -module.exports = Object.values(require('require-dir')()); +module.exports = require('require-dir')(); diff --git a/src/type-defs.js b/src/type-defs.js index 8c6b23c..4ff266a 100644 --- a/src/type-defs.js +++ b/src/type-defs.js @@ -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 { diff --git a/tests.js b/tests.js index d276d70..bc0aa2a 100644 --- a/tests.js +++ b/tests.js @@ -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,