@@ -32,7 +32,11 @@ exports.onCreateNode = function onCreateNode({ node, actions, getNode }) {
3232 }
3333} ;
3434
35- exports . createPages = function createPages ( { graphql, actions, reporter } ) {
35+ exports . createPages = async function createPages ( {
36+ graphql,
37+ actions,
38+ reporter
39+ } ) {
3640 if ( ! env . algoliaAPIKey || ! env . algoliaAppId ) {
3741 if ( process . env . FREECODECAMP_NODE_ENV === 'production' ) {
3842 throw new Error (
@@ -57,201 +61,140 @@ exports.createPages = function createPages({ graphql, actions, reporter }) {
5761
5862 const { createPage } = actions ;
5963
60- return new Promise ( ( resolve , reject ) => {
61- // Query for all markdown 'nodes' and for the slug we previously created.
62- resolve (
63- graphql ( `
64- {
65- allChallengeNode(
66- sort: {
67- fields: [
68- challenge___superOrder
69- challenge___order
70- challenge___challengeOrder
71- ]
72- }
73- ) {
74- edges {
75- node {
76- challenge {
77- block
78- certification
79- challengeType
80- dashedName
81- disableLoopProtectTests
82- disableLoopProtectPreview
83- fields {
84- slug
85- blockHashSlug
86- }
87- fillInTheBlank {
88- sentence
89- blanks {
90- answer
91- feedback
92- }
93- }
94- hasEditableBoundaries
95- id
96- msTrophyId
97- order
98- prerequisites {
99- id
100- title
101- }
102- required {
103- link
104- src
105- }
106- challengeOrder
107- challengeFiles {
108- name
109- ext
110- contents
111- head
112- tail
113- history
114- fileKey
115- }
116- solutions {
117- contents
118- ext
119- history
120- }
121- superBlock
122- superOrder
123- template
124- usesMultifileEditor
125- scene {
126- setup {
127- background
128- characters {
129- character
130- position {
131- x
132- y
133- z
134- }
135- }
136- audio {
137- filename
138- startTime
139- startTimestamp
140- finishTimestamp
141- }
142- alwaysShowDialogue
143- }
144- commands {
145- background
146- character
147- position {
148- x
149- y
150- z
151- }
152- startTime
153- finishTime
154- dialogue {
155- text
156- align
157- }
158- }
159- }
160- }
64+ const result = await graphql ( `
65+ {
66+ allChallengeNode(
67+ sort: {
68+ fields: [
69+ challenge___superOrder
70+ challenge___order
71+ challenge___challengeOrder
72+ ]
73+ }
74+ ) {
75+ edges {
76+ node {
77+ challenge {
78+ block
79+ certification
80+ challengeType
81+ dashedName
82+ disableLoopProtectTests
83+ disableLoopProtectPreview
84+ fields {
85+ slug
86+ blockHashSlug
16187 }
162- }
163- }
164- allMarkdownRemark {
165- edges {
166- node {
167- fields {
168- slug
169- nodeIdentity
170- component
171- }
172- frontmatter {
173- certification
174- block
175- superBlock
176- title
177- }
178- htmlAst
179- id
180- excerpt
88+ id
89+ order
90+ required {
91+ link
92+ src
18193 }
94+ challengeOrder
95+ challengeFiles {
96+ name
97+ ext
98+ contents
99+ head
100+ tail
101+ history
102+ fileKey
103+ }
104+ solutions {
105+ contents
106+ ext
107+ history
108+ }
109+ superBlock
110+ superOrder
111+ template
112+ usesMultifileEditor
182113 }
183114 }
184115 }
185- ` ) . then ( result => {
186- if ( result . errors ) {
187- console . log ( result . errors ) ;
188- return reject ( result . errors ) ;
116+ }
117+ allMarkdownRemark {
118+ edges {
119+ node {
120+ fields {
121+ slug
122+ nodeIdentity
123+ component
124+ }
125+ frontmatter {
126+ certification
127+ block
128+ superBlock
129+ title
130+ }
131+ htmlAst
132+ id
133+ excerpt
134+ }
189135 }
136+ }
137+ }
138+ ` ) ;
190139
191- // Create challenge pages.
192- result . data . allChallengeNode . edges . forEach (
193- createChallengePages ( createPage )
194- ) ;
140+ // Create challenge pages.
141+ result . data . allChallengeNode . edges . forEach ( createChallengePages ( createPage ) ) ;
195142
196- const blocks = uniq (
197- result . data . allChallengeNode . edges . map (
198- ( {
199- node : {
200- challenge : { block }
201- }
202- } ) => block
203- )
204- ) ;
143+ const blocks = uniq (
144+ result . data . allChallengeNode . edges . map (
145+ ( {
146+ node : {
147+ challenge : { block }
148+ }
149+ } ) => block
150+ )
151+ ) ;
205152
206- const superBlocks = uniq (
207- result . data . allChallengeNode . edges . map (
208- ( {
209- node : {
210- challenge : { superBlock }
211- }
212- } ) => superBlock
213- )
214- ) ;
153+ const superBlocks = uniq (
154+ result . data . allChallengeNode . edges . map (
155+ ( {
156+ node : {
157+ challenge : { superBlock }
158+ }
159+ } ) => superBlock
160+ )
161+ ) ;
215162
216- // Create intro pages
217- // TODO: Remove allMarkdownRemark (populate from elsewhere)
218- result . data . allMarkdownRemark . edges . forEach ( edge => {
219- const {
220- node : { frontmatter, fields }
221- } = edge ;
163+ // Create intro pages
164+ // TODO: Remove allMarkdownRemark (populate from elsewhere)
165+ result . data . allMarkdownRemark . edges . forEach ( edge => {
166+ const {
167+ node : { frontmatter, fields }
168+ } = edge ;
222169
223- if ( ! fields ) {
224- return ;
225- }
226- const { slug, nodeIdentity } = fields ;
227- if ( slug . includes ( 'LICENCE' ) ) {
228- return ;
229- }
230- try {
231- if ( nodeIdentity === 'blockIntroMarkdown' ) {
232- if ( ! blocks . includes ( frontmatter . block ) ) {
233- return ;
234- }
235- } else if ( ! superBlocks . includes ( frontmatter . superBlock ) ) {
236- return ;
237- }
238- const pageBuilder = createByIdentityMap [ nodeIdentity ] ( createPage ) ;
239- pageBuilder ( edge ) ;
240- } catch ( e ) {
241- console . log ( e ) ;
242- console . log ( `
170+ if ( ! fields ) {
171+ return ;
172+ }
173+ const { slug, nodeIdentity } = fields ;
174+ if ( slug . includes ( 'LICENCE' ) ) {
175+ return ;
176+ }
177+ if ( nodeIdentity === 'blockIntroMarkdown' ) {
178+ if ( ! blocks . includes ( frontmatter . block ) ) {
179+ return ;
180+ }
181+ } else if ( ! superBlocks . includes ( frontmatter . superBlock ) ) {
182+ return ;
183+ }
184+
185+ try {
186+ const pageBuilder = createByIdentityMap [ nodeIdentity ] ( createPage ) ;
187+ pageBuilder ( edge ) ;
188+ } catch ( e ) {
189+ console . log ( e ) ;
190+ console . log ( `
243191 ident: ${ nodeIdentity } does not belong to a function
244192
245193 ${ frontmatter ? JSON . stringify ( edge . node ) : 'no frontmatter' }
246194
247195
248196 ` ) ;
249- }
250- } ) ;
251-
252- return null ;
253- } )
254- ) ;
197+ }
255198 } ) ;
256199} ;
257200
0 commit comments