| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | const { viewTypes } = require('../challenge-types'); | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | const backend = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2021-06-25 09:59:33 -05:00
										 |  |  |   '../../src/templates/Challenges/projects/backend/Show.tsx' | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | const classic = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2021-09-17 13:37:53 -04:00
										 |  |  |   '../../src/templates/Challenges/classic/show.tsx' | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2019-09-19 12:44:58 +05:30
										 |  |  | const frontend = path.resolve( | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2021-06-25 09:59:33 -05:00
										 |  |  |   '../../src/templates/Challenges/projects/frontend/Show.tsx' | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-06-15 10:37:13 -05:00
										 |  |  | const codeally = path.resolve( | 
					
						
							|  |  |  |   __dirname, | 
					
						
							| 
									
										
										
										
											2021-06-25 09:59:33 -05:00
										 |  |  |   '../../src/templates/Challenges/codeally/show.tsx' | 
					
						
							| 
									
										
										
										
											2021-06-15 10:37:13 -05:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2021-06-25 09:59:33 -05:00
										 |  |  |   '../../src/templates/Challenges/video/Show.tsx' | 
					
						
							| 
									
										
										
										
											2020-04-06 14:49:56 -04:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | const views = { | 
					
						
							|  |  |  |   backend, | 
					
						
							|  |  |  |   classic, | 
					
						
							|  |  |  |   modern: classic, | 
					
						
							| 
									
										
										
										
											2020-04-06 14:49:56 -04:00
										 |  |  |   frontend, | 
					
						
							| 
									
										
										
										
											2021-06-15 10:37:13 -05:00
										 |  |  |   video, | 
					
						
							|  |  |  |   codeally | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |   // quiz: Quiz
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | function getNextChallengePath(_node, index, nodeArray) { | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  |   const next = nodeArray[index + 1]; | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  |   return next ? next.node.fields.slug : '/learn'; | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | function getPrevChallengePath(_node, index, nodeArray) { | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  |   const prev = nodeArray[index - 1]; | 
					
						
							|  |  |  |   return prev ? prev.node.fields.slug : '/learn'; | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-18 04:46:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | function getTemplateComponent(challengeType) { | 
					
						
							|  |  |  |   return views[viewTypes[challengeType]]; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | exports.createChallengePages = function (createPage) { | 
					
						
							|  |  |  |   return function ({ node }, index, thisArray) { | 
					
						
							| 
									
										
										
										
											2021-05-10 08:48:49 -07:00
										 |  |  |     const { | 
					
						
							|  |  |  |       superBlock, | 
					
						
							|  |  |  |       block, | 
					
						
							|  |  |  |       fields: { slug }, | 
					
						
							|  |  |  |       required = [], | 
					
						
							|  |  |  |       template, | 
					
						
							|  |  |  |       challengeType, | 
					
						
							|  |  |  |       id | 
					
						
							|  |  |  |     } = node; | 
					
						
							|  |  |  |     // TODO: challengeType === 7 and isPrivate are the same, right? If so, we
 | 
					
						
							|  |  |  |     // should remove one of them.
 | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  |     createPage({ | 
					
						
							| 
									
										
										
										
											2021-05-10 08:48:49 -07:00
										 |  |  |       path: slug, | 
					
						
							|  |  |  |       component: getTemplateComponent(challengeType), | 
					
						
							|  |  |  |       context: { | 
					
						
							|  |  |  |         challengeMeta: { | 
					
						
							|  |  |  |           superBlock, | 
					
						
							|  |  |  |           block, | 
					
						
							|  |  |  |           template, | 
					
						
							|  |  |  |           required, | 
					
						
							|  |  |  |           nextChallengePath: getNextChallengePath(node, index, thisArray), | 
					
						
							|  |  |  |           prevChallengePath: getPrevChallengePath(node, index, thisArray), | 
					
						
							|  |  |  |           id | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         slug | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | exports.createBlockIntroPages = function (createPage) { | 
					
						
							|  |  |  |   return function (edge) { | 
					
						
							|  |  |  |     const { | 
					
						
							|  |  |  |       fields: { slug }, | 
					
						
							|  |  |  |       frontmatter: { block } | 
					
						
							|  |  |  |     } = edge.node; | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  |     createPage({ | 
					
						
							|  |  |  |       path: slug, | 
					
						
							|  |  |  |       component: intro, | 
					
						
							|  |  |  |       context: { | 
					
						
							|  |  |  |         block: dasherize(block), | 
					
						
							|  |  |  |         slug | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | exports.createSuperBlockIntroPages = function (createPage) { | 
					
						
							|  |  |  |   return function (edge) { | 
					
						
							|  |  |  |     const { | 
					
						
							|  |  |  |       fields: { slug }, | 
					
						
							|  |  |  |       frontmatter: { superBlock } | 
					
						
							|  |  |  |     } = edge.node; | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  |     createPage({ | 
					
						
							|  |  |  |       path: slug, | 
					
						
							|  |  |  |       component: superBlockIntro, | 
					
						
							|  |  |  |       context: { | 
					
						
							|  |  |  |         superBlock, | 
					
						
							|  |  |  |         slug | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-11-29 12:12:15 +00:00
										 |  |  | }; |