| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2019-09-25 20:16:08 +02:00
										 |  |  | const { dasherize } = require('../../../utils/slugs'); | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | const { viewTypes } = require('../challengeTypes'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const backend = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2019-09-19 12:44:58 +05:30
										 |  |  |   '../../src/templates/Challenges/projects/backend/Show.js' | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | const classic = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							|  |  |  |   '../../src/templates/Challenges/classic/Show.js' | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2019-09-19 12:44:58 +05:30
										 |  |  | const frontend = path.resolve( | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2019-09-19 12:44:58 +05:30
										 |  |  |   '../../src/templates/Challenges/projects/frontend/Show.js' | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | const intro = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							|  |  |  |   '../../src/templates/Introduction/Intro.js' | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | const superBlockIntro = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							|  |  |  |   '../../src/templates/Introduction/SuperBlockIntro.js' | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2020-04-06 14:49:56 -04:00
										 |  |  | const video = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							|  |  |  |   '../../src/templates/Challenges/video/Show.js' | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | const views = { | 
					
						
							|  |  |  |   backend, | 
					
						
							|  |  |  |   classic, | 
					
						
							|  |  |  |   modern: classic, | 
					
						
							| 
									
										
										
										
											2020-04-06 14:49:56 -04:00
										 |  |  |   frontend, | 
					
						
							|  |  |  |   video | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |   // quiz: Quiz
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const getNextChallengePath = (node, index, nodeArray) => { | 
					
						
							|  |  |  |   const next = nodeArray[index + 1]; | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  |   return next ? next.node.fields.slug : '/learn'; | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | const getPrevChallengePath = (node, index, nodeArray) => { | 
					
						
							|  |  |  |   const prev = nodeArray[index - 1]; | 
					
						
							|  |  |  |   return prev ? prev.node.fields.slug : '/learn'; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | const getTemplateComponent = challengeType => views[viewTypes[challengeType]]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const getIntroIfRequired = (node, index, nodeArray) => { | 
					
						
							|  |  |  |   const next = nodeArray[index + 1]; | 
					
						
							|  |  |  |   const isEndOfBlock = next && next.node.challengeOrder === 0; | 
					
						
							|  |  |  |   let nextSuperBlock = ''; | 
					
						
							|  |  |  |   let nextBlock = ''; | 
					
						
							|  |  |  |   if (next) { | 
					
						
							|  |  |  |     const { superBlock, block } = next.node; | 
					
						
							|  |  |  |     nextSuperBlock = superBlock; | 
					
						
							|  |  |  |     nextBlock = block; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return isEndOfBlock | 
					
						
							|  |  |  |     ? `/learn/${dasherize(nextSuperBlock)}/${dasherize(nextBlock)}` | 
					
						
							|  |  |  |     : ''; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.createChallengePages = createPage => ({ node }, index, thisArray) => { | 
					
						
							|  |  |  |   const { | 
					
						
							| 
									
										
										
										
											2020-02-04 06:03:56 +01:00
										 |  |  |     superBlock, | 
					
						
							| 
									
										
										
										
											2019-11-15 11:33:08 -06:00
										 |  |  |     block, | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |     fields: { slug }, | 
					
						
							|  |  |  |     required = [], | 
					
						
							|  |  |  |     template, | 
					
						
							|  |  |  |     challengeType, | 
					
						
							| 
									
										
										
										
											2020-05-22 18:04:25 +02:00
										 |  |  |     id | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |   } = node; | 
					
						
							| 
									
										
										
										
											2020-05-20 15:45:34 +02:00
										 |  |  |   // TODO: challengeType === 7 and isPrivate are the same, right? If so, we
 | 
					
						
							|  |  |  |   // should remove one of them.
 | 
					
						
							| 
									
										
										
										
											2020-05-22 18:04:25 +02:00
										 |  |  |   if (challengeType === 7) { | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return createPage({ | 
					
						
							|  |  |  |     path: slug, | 
					
						
							|  |  |  |     component: getTemplateComponent(challengeType), | 
					
						
							|  |  |  |     context: { | 
					
						
							|  |  |  |       challengeMeta: { | 
					
						
							| 
									
										
										
										
											2020-02-04 06:03:56 +01:00
										 |  |  |         superBlock, | 
					
						
							| 
									
										
										
										
											2019-11-15 11:33:08 -06:00
										 |  |  |         block: block, | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |         introPath: getIntroIfRequired(node, index, thisArray), | 
					
						
							|  |  |  |         template, | 
					
						
							|  |  |  |         required, | 
					
						
							|  |  |  |         nextChallengePath: getNextChallengePath(node, index, thisArray), | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  |         prevChallengePath: getPrevChallengePath(node, index, thisArray), | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |         id | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       slug | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.createBlockIntroPages = createPage => edge => { | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     fields: { slug }, | 
					
						
							|  |  |  |     frontmatter: { block } | 
					
						
							|  |  |  |   } = edge.node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return createPage({ | 
					
						
							|  |  |  |     path: slug, | 
					
						
							|  |  |  |     component: intro, | 
					
						
							|  |  |  |     context: { | 
					
						
							|  |  |  |       block: dasherize(block), | 
					
						
							|  |  |  |       slug | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exports.createSuperBlockIntroPages = createPage => edge => { | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     fields: { slug }, | 
					
						
							|  |  |  |     frontmatter: { superBlock } | 
					
						
							|  |  |  |   } = edge.node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return createPage({ | 
					
						
							|  |  |  |     path: slug, | 
					
						
							|  |  |  |     component: superBlockIntro, | 
					
						
							|  |  |  |     context: { | 
					
						
							|  |  |  |       superBlock: dasherize(superBlock), | 
					
						
							|  |  |  |       slug | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; |