1
1
// this patch is required to consistently load all the doc files
2
- const realFs = require ( 'fs' ) ;
3
- const gracefulFs = require ( 'graceful-fs' ) ;
2
+ const realFs = require ( "fs" ) ;
3
+ const path = require ( "path" ) ;
4
+ const gracefulFs = require ( "graceful-fs" ) ;
4
5
gracefulFs . gracefulify ( realFs ) ;
5
6
6
7
const { createFilePath } = require ( `gatsby-source-filesystem` ) ;
7
- const { exec, execSync } = require ( ' child_process' ) ;
8
+ const { exec, execSync } = require ( " child_process" ) ;
8
9
9
10
const {
10
11
replacePathVersion,
@@ -23,16 +24,16 @@ const {
23
24
configureLegacyRedirects,
24
25
readFile,
25
26
writeFile,
26
- } = require ( ' ./src/constants/gatsby-utils.js' ) ;
27
+ } = require ( " ./src/constants/gatsby-utils.js" ) ;
27
28
28
- const isBuild = process . env . NODE_ENV === ' production' ;
29
- const isProduction = process . env . APP_ENV === ' production' ;
29
+ const isBuild = process . env . NODE_ENV === " production" ;
30
+ const isProduction = process . env . APP_ENV === " production" ;
30
31
31
32
exports . onCreateNode = async ( { node, getNode, actions, loadNodeContent } ) => {
32
33
const { createNodeField } = actions ;
33
34
34
- if ( node . internal . mediaType === ' text/yaml' ) loadNodeContent ( node ) ;
35
- if ( node . internal . type !== ' Mdx' ) return ;
35
+ if ( node . internal . mediaType === " text/yaml" ) loadNodeContent ( node ) ;
36
+ if ( node . internal . type !== " Mdx" ) return ;
36
37
37
38
const fileNode = getNode ( node . parent ) ;
38
39
const nodeFields = {
@@ -41,7 +42,7 @@ exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => {
41
42
} ;
42
43
43
44
let relativeFilePath = createFilePath ( { node, getNode } ) ;
44
- if ( nodeFields . docType === ' doc' ) {
45
+ if ( nodeFields . docType === " doc" ) {
45
46
relativeFilePath = `/${ fileNode . sourceInstanceName } ${ relativeFilePath } ` ;
46
47
}
47
48
@@ -50,17 +51,17 @@ exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => {
50
51
depth : pathToDepth ( relativeFilePath ) ,
51
52
} ) ;
52
53
53
- if ( nodeFields . docType === ' doc' ) {
54
+ if ( nodeFields . docType === " doc" ) {
54
55
Object . assign ( nodeFields , {
55
- product : relativeFilePath . split ( '/' ) [ 1 ] ,
56
- version : relativeFilePath . split ( '/' ) [ 2 ] ,
57
- topic : ' null' ,
56
+ product : relativeFilePath . split ( "/" ) [ 1 ] ,
57
+ version : relativeFilePath . split ( "/" ) [ 2 ] ,
58
+ topic : " null" ,
58
59
} ) ;
59
- } else if ( nodeFields . docType === ' advocacy' ) {
60
+ } else if ( nodeFields . docType === " advocacy" ) {
60
61
Object . assign ( nodeFields , {
61
- product : ' null' ,
62
- version : '0' ,
63
- topic : relativeFilePath . split ( '/' ) [ 2 ] ,
62
+ product : " null" ,
63
+ version : "0" ,
64
+ topic : relativeFilePath . split ( "/" ) [ 2 ] ,
64
65
} ) ;
65
66
}
66
67
@@ -128,7 +129,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
128
129
` ) ;
129
130
130
131
if ( result . errors ) {
131
- reporter . panic ( ' createPages graphql query has errors!' , result . errors ) ;
132
+ reporter . panic ( " createPages graphql query has errors!" , result . errors ) ;
132
133
}
133
134
134
135
processFileNodes ( result . data . allFile . nodes , actions ) ;
@@ -139,7 +140,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
139
140
140
141
// it should be possible to remove these in the future,
141
142
// they are only used for navLinks generation
142
- const learn = nodes . filter ( ( file ) => file . fields . docType === ' advocacy' ) ;
143
+ const learn = nodes . filter ( ( file ) => file . fields . docType === " advocacy" ) ;
143
144
144
145
// perform depth first preorder traversal
145
146
const treeRoot = mdxNodesToTree ( nodes ) ;
@@ -155,17 +156,17 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
155
156
const addedChildPaths = { } ;
156
157
curr . navigationNodes = [ ] ;
157
158
( curr . mdxNode ?. frontmatter ?. navigation || [ ] ) . forEach ( ( navEntry ) => {
158
- if ( navEntry . startsWith ( '#' ) ) {
159
+ if ( navEntry . startsWith ( "#" ) ) {
159
160
curr . navigationNodes . push ( {
160
161
path : null ,
161
- title : navEntry . replace ( '#' , '' ) . trim ( ) ,
162
+ title : navEntry . replace ( "#" , "" ) . trim ( ) ,
162
163
} ) ;
163
164
return ;
164
165
}
165
166
166
167
const navChild = curr . children . find ( ( child ) => {
167
168
if ( addedChildPaths [ child . path ] ) return false ;
168
- const navName = child . path . split ( '/' ) . slice ( - 2 ) [ 0 ] ;
169
+ const navName = child . path . split ( "/" ) . slice ( - 2 ) [ 0 ] ;
169
170
return navName . toLowerCase ( ) === navEntry . toLowerCase ( ) ;
170
171
} ) ;
171
172
if ( ! navChild ?. mdxNode ) return ;
@@ -203,9 +204,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
203
204
const prevNext = findPrevNextNavNodes ( navTree , curr ) ;
204
205
205
206
const { docType } = node . fields ;
206
- if ( docType === ' doc' ) {
207
+ if ( docType === " doc" ) {
207
208
createDoc ( navTree , prevNext , node , productVersions , actions ) ;
208
- } else if ( docType === ' advocacy' ) {
209
+ } else if ( docType === " advocacy" ) {
209
210
createAdvocacy ( navTree , prevNext , node , learn , actions ) ;
210
211
}
211
212
}
@@ -237,18 +238,18 @@ const createDoc = (navTree, prevNext, doc, productVersions, actions) => {
237
238
}
238
239
239
240
const isIndexPage = isPathAnIndexPage ( doc . fileAbsolutePath ) ;
240
- const docsRepoUrl = ' https://github.com/EnterpriseDB/docs' ;
241
- const branch = isProduction ? ' main' : ' develop' ;
241
+ const docsRepoUrl = " https://github.com/EnterpriseDB/docs" ;
242
+ const branch = isProduction ? " main" : " develop" ;
242
243
const fileUrlSegment =
243
244
removeTrailingSlash ( doc . fields . path ) +
244
- ( isIndexPage ? ' /index.mdx' : ' .mdx' ) ;
245
+ ( isIndexPage ? " /index.mdx" : " .mdx" ) ;
245
246
const githubFileLink = `${ docsRepoUrl } /commits/${ branch } /product_docs/docs${ fileUrlSegment } ` ;
246
247
const githubEditLink = `${ docsRepoUrl } /edit/${ branch } /product_docs/docs${ fileUrlSegment } ` ;
247
248
const githubIssuesLink = `${ docsRepoUrl } /issues/new?title=Feedback%20on%20${ encodeURIComponent (
248
249
fileUrlSegment ,
249
250
) } `;
250
251
251
- const template = doc . frontmatter . productStub ? ' doc-stub.js' : ' doc.js' ;
252
+ const template = doc . frontmatter . productStub ? " doc-stub.js" : " doc.js" ;
252
253
const path = isLatest ? replacePathVersion ( doc . fields . path ) : doc . fields . path ;
253
254
254
255
// workaround for https://github.com/gatsbyjs/gatsby/issues/26520
@@ -296,12 +297,12 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
296
297
( node ) => node . fields . topic === doc . fields . topic ,
297
298
) ;
298
299
299
- const advocacyDocsRepoUrl = ' https://github.com/EnterpriseDB/docs' ;
300
- const branch = isProduction ? ' main' : ' develop' ;
300
+ const advocacyDocsRepoUrl = " https://github.com/EnterpriseDB/docs" ;
301
+ const branch = isProduction ? " main" : " develop" ;
301
302
const isIndexPage = isPathAnIndexPage ( doc . fileAbsolutePath ) ;
302
303
const fileUrlSegment =
303
304
removeTrailingSlash ( doc . fields . path ) +
304
- ( isIndexPage ? ' /index.mdx' : ' .mdx' ) ;
305
+ ( isIndexPage ? " /index.mdx" : " .mdx" ) ;
305
306
const githubFileLink = `${ advocacyDocsRepoUrl } /commits/${ branch } /advocacy_docs${ fileUrlSegment } ` ;
306
307
const githubEditLink = `${ advocacyDocsRepoUrl } /edit/${ branch } /advocacy_docs${ fileUrlSegment } ` ;
307
308
const githubIssuesLink = `${ advocacyDocsRepoUrl } /issues/new?title=Regarding%20${ encodeURIComponent (
@@ -311,13 +312,13 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
311
312
// workaround for https://github.com/gatsbyjs/gatsby/issues/26520
312
313
actions . createPage ( {
313
314
path : doc . fields . path ,
314
- component : require . resolve ( ' ./src/templates/learn-doc.js' ) ,
315
+ component : require . resolve ( " ./src/templates/learn-doc.js" ) ,
315
316
context : { } ,
316
317
} ) ;
317
318
318
319
actions . createPage ( {
319
320
path : doc . fields . path ,
320
- component : require . resolve ( ' ./src/templates/learn-doc.js' ) ,
321
+ component : require . resolve ( " ./src/templates/learn-doc.js" ) ,
321
322
context : {
322
323
nodeId : doc . id ,
323
324
frontmatter : doc . frontmatter ,
@@ -342,7 +343,7 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => {
342
343
const path = `${ doc . fields . path } ${ katacodaPage . scenario } ` ;
343
344
actions . createPage ( {
344
345
path : path ,
345
- component : require . resolve ( ' ./src/templates/katacoda-page.js' ) ,
346
+ component : require . resolve ( " ./src/templates/katacoda-page.js" ) ,
346
347
context : {
347
348
...katacodaPage ,
348
349
pagePath : path ,
@@ -359,7 +360,7 @@ const processFileNodes = (fileNodes, actions) => {
359
360
fileNodes . forEach ( ( node ) => {
360
361
actions . createPage ( {
361
362
path : node . relativePath ,
362
- component : require . resolve ( ' ./src/templates/file.js' ) ,
363
+ component : require . resolve ( " ./src/templates/file.js" ) ,
363
364
context : {
364
365
nodeId : node . id ,
365
366
} ,
@@ -375,13 +376,13 @@ exports.sourceNodes = async ({
375
376
// create edb-git node
376
377
const sha = (
377
378
await new Promise ( ( resolve , reject ) => {
378
- exec ( ' git rev-parse HEAD' , ( error , stdout , stderr ) => resolve ( stdout ) ) ;
379
+ exec ( " git rev-parse HEAD" , ( error , stdout , stderr ) => resolve ( stdout ) ) ;
379
380
} )
380
381
) . trim ( ) ;
381
382
382
383
const branch = (
383
384
await new Promise ( ( resolve , reject ) => {
384
- exec ( ' git branch --show-current' , ( error , stdout , stderr ) =>
385
+ exec ( " git branch --show-current" , ( error , stdout , stderr ) =>
385
386
resolve ( stdout ) ,
386
387
) ;
387
388
} )
@@ -390,9 +391,9 @@ exports.sourceNodes = async ({
390
391
const gitData = { sha, branch } ;
391
392
createNode ( {
392
393
...gitData ,
393
- id : createNodeId ( ' edb-git' ) ,
394
+ id : createNodeId ( " edb-git" ) ,
394
395
internal : {
395
- type : ' edbGit' ,
396
+ type : " edbGit" ,
396
397
contentDigest : createContentDigest ( gitData ) ,
397
398
} ,
398
399
} ) ;
@@ -424,29 +425,34 @@ exports.createSchemaCustomization = ({ actions }) => {
424
425
425
426
exports . onPreBootstrap = ( ) => {
426
427
console . log ( `
427
- _____ ____ _____ ____
428
- | __|| \\ | __ | | \\ ___ ___ ___
428
+ _____ ____ _____ ____
429
+ | __|| \\ | __ | | \\ ___ ___ ___
429
430
| __|| | || __ -| | | || . || _||_ -|
430
431
|_____||____/ |_____| |____/ |___||___||___|
431
-
432
+
432
433
` ) ;
433
434
} ;
434
435
435
436
exports . onPostBuild = async ( { reporter, pathPrefix } ) => {
436
- const originalRedirects = await readFile ( 'public/_redirects' ) ;
437
+ realFs . copyFileSync (
438
+ path . join ( __dirname , "/netlify.toml" ) ,
439
+ path . join ( __dirname , "/public/netlify.toml" ) ,
440
+ ) ;
441
+
442
+ const originalRedirects = await readFile ( "public/_redirects" ) ;
437
443
438
444
// filter out legacyRedirects that are loaded via nginx, not netlify
439
445
let filteredRedirects = originalRedirects
440
- . split ( '\n' )
446
+ . split ( "\n" )
441
447
. filter ( ( line ) => ! line . startsWith ( `${ pathPrefix } /edb-docs/` ) )
442
- . join ( '\n' ) ;
448
+ . join ( "\n" ) ;
443
449
444
450
if ( filteredRedirects . length === originalRedirects . length ) {
445
- reporter . warn ( ' no redirects were filtered out, did something change?' ) ;
451
+ reporter . warn ( " no redirects were filtered out, did something change?" ) ;
446
452
}
447
453
448
454
await writeFile (
449
- ' public/_redirects' ,
455
+ " public/_redirects" ,
450
456
`${ filteredRedirects } \n\n# Netlify pathPrefix path rewrite\n${ pathPrefix } /* /:splat 200` ,
451
457
) ;
452
458
} ;
0 commit comments