diff --git a/client/gatsby-config.js b/client/gatsby-config.js index 94355d0ebb..f1f3f1ca1b 100644 --- a/client/gatsby-config.js +++ b/client/gatsby-config.js @@ -34,7 +34,7 @@ module.exports = { options: { name: 'challenges', source: buildChallenges, - onSourceChange: replaceChallengeNode, + onSourceChange: replaceChallengeNode(config.locale), curriculumPath: localeChallengesRootDir } }, diff --git a/client/utils/buildChallenges.js b/client/utils/buildChallenges.js index b1f9ae61bc..9c02ffcbc8 100644 --- a/client/utils/buildChallenges.js +++ b/client/utils/buildChallenges.js @@ -14,10 +14,10 @@ const arrToString = arr => exports.localeChallengesRootDir = getChallengesDirForLang(locale); -exports.replaceChallengeNode = async function replaceChallengeNode( - fullFilePath -) { - return prepareChallenge(await createChallenge(fullFilePath)); +exports.replaceChallengeNode = locale => { + return async function replaceChallengeNode(fullFilePath) { + return prepareChallenge(await createChallenge(fullFilePath, null, locale)); + }; }; exports.buildChallenges = async function buildChallenges() { diff --git a/curriculum/getChallenges.js b/curriculum/getChallenges.js index 41ca28d4ee..e7fa732bd2 100644 --- a/curriculum/getChallenges.js +++ b/curriculum/getChallenges.js @@ -28,7 +28,6 @@ exports.getMetaForBlock = getMetaForBlock; exports.getChallengesForLang = function getChallengesForLang(lang) { let curriculum = {}; - const validate = challengeSchemaValidator(lang); return new Promise(resolve => { let running = 1; function done() { @@ -39,13 +38,13 @@ exports.getChallengesForLang = function getChallengesForLang(lang) { readDirP({ root: getChallengesDirForLang(lang) }) .on('data', file => { running++; - buildCurriculum(file, curriculum, validate).then(done); + buildCurriculum(file, curriculum, lang).then(done); }) .on('end', done); }); }; -async function buildCurriculum(file, curriculum, validate) { +async function buildCurriculum(file, curriculum, lang) { const { name, depth, path: filePath, fullPath, stat } = file; if (depth === 1 && stat.isDirectory()) { // extract the superBlock info @@ -81,12 +80,12 @@ async function buildCurriculum(file, curriculum, validate) { } const { meta } = challengeBlock; - const challenge = await createChallenge(fullPath, meta, validate); + const challenge = await createChallenge(fullPath, meta, lang); challengeBlock.challenges = [...challengeBlock.challenges, challenge]; } -async function createChallenge(fullPath, maybeMeta, validate) { +async function createChallenge(fullPath, maybeMeta, lang) { let meta; if (maybeMeta) { meta = maybeMeta; @@ -99,7 +98,7 @@ async function createChallenge(fullPath, maybeMeta, validate) { } const { name: superBlock } = superBlockInfoFromFullPath(fullPath); const challenge = await parseMarkdown(fullPath); - const result = validate(challenge); + const result = challengeSchemaValidator(lang)(challenge); if (result.error) { console.log(result.value); throw new Error(result.error);