1
1
// @ts -check
2
2
// Note: type annotations allow type checking and IDEs autocompletion
3
- require ( 'dotenv' ) . config ( )
4
- const lightCodeTheme = require ( 'prism-react-renderer/themes/github' )
5
- const darkCodeTheme = require ( 'prism-react-renderer/themes/dracula' )
3
+ require ( 'dotenv' ) . config ( ) ;
4
+ const lightCodeTheme = require ( 'prism-react-renderer/themes/github' ) ;
5
+ const darkCodeTheme = require ( 'prism-react-renderer/themes/dracula' ) ;
6
6
7
- const path = require ( 'path' )
8
- const fs = require ( 'fs' )
7
+ const path = require ( 'path' ) ;
8
+ const fs = require ( 'fs' ) ;
9
9
10
- const docCollectionsLocation = './src/data/doc-collections'
11
- let cachedSources
10
+ const docCollectionsLocation = './src/data/doc-collections' ;
11
+ let cachedSources ;
12
12
13
13
/**
14
14
*
15
15
* @returns {string[] }
16
16
*/
17
17
const getDocFileNames = ( ) => {
18
18
try {
19
- const docCollectionPath = path . join ( __dirname , docCollectionsLocation , '/' )
20
- const files = fs . readdirSync ( docCollectionPath )
21
- return files . filter ( ( filename ) => filename . match ( / \. j s o n $ / ) )
19
+ const docCollectionPath = path . join ( __dirname , docCollectionsLocation , '/' ) ;
20
+ const files = fs . readdirSync ( docCollectionPath ) ;
21
+ return files . filter ( ( filename ) => filename . match ( / \. j s o n $ / ) ) ;
22
22
} catch ( error ) {
23
- console . error ( 'Unable to scan directory: ' + error )
23
+ console . error ( 'Unable to scan directory: ' + error ) ;
24
24
}
25
- }
25
+ } ;
26
26
/**
27
27
*
28
28
* @param {string } filename
29
29
* @returns {string }
30
30
*/
31
31
const getSource = ( filename ) => {
32
- const filePath = path . join ( __dirname , docCollectionsLocation , filename )
32
+ const filePath = path . join ( __dirname , docCollectionsLocation , filename ) ;
33
33
try {
34
- const fileContent = JSON . parse ( fs . readFileSync ( filePath ) . toString ( ) )
35
- return fileContent . source
34
+ const fileContent = JSON . parse ( fs . readFileSync ( filePath ) . toString ( ) ) ;
35
+ return fileContent . source ;
36
36
} catch ( error ) {
37
- console . error ( 'Cannot parse: ' + error )
37
+ console . error ( 'Cannot parse: ' + error ) ;
38
38
}
39
- }
39
+ } ;
40
40
41
41
/**
42
42
* @typedef {Object } Source
@@ -51,33 +51,33 @@ const getSource = (filename) => {
51
51
*/
52
52
const getSources = ( ) => {
53
53
if ( ! cachedSources ) {
54
- const docFilenames = getDocFileNames ( )
54
+ const docFilenames = getDocFileNames ( ) ;
55
55
56
56
cachedSources = docFilenames . reduce ( ( acc , filename ) => {
57
- const source = getSource ( filename )
57
+ const source = getSource ( filename ) ;
58
58
if ( ! source ) {
59
- return acc
59
+ return acc ;
60
60
}
61
- return [ ...acc , source ]
62
- } , [ ] )
61
+ return [ ...acc , source ] ;
62
+ } , [ ] ) ;
63
63
}
64
- return cachedSources
65
- }
64
+ return cachedSources ;
65
+ } ;
66
66
67
67
/** @type {import('@docusaurus/plugin-content-docs').MetadataOptions['editUrl'] } */
68
68
const editUrl = ( { docPath } ) => {
69
- const docPathArray = docPath . split ( '/' )
70
- const repoName = docPathArray [ 0 ]
71
- const sources = getSources ( )
69
+ const docPathArray = docPath . split ( '/' ) ;
70
+ const repoName = docPathArray [ 0 ] ;
71
+ const sources = getSources ( ) ;
72
72
73
- const sourceRepo = sources . find ( ( { name } ) => name === repoName )
73
+ const sourceRepo = sources . find ( ( { name } ) => name === repoName ) ;
74
74
if ( ! sourceRepo ) {
75
- return
75
+ return ;
76
76
}
77
- const { owner, name, branch } = sourceRepo
78
- const sourceDockPath = docPathArray . slice ( 1 ) . join ( '/' )
79
- return `https://github.com/${ owner } /${ name } /tree/${ branch } /docs/${ sourceDockPath } `
80
- }
77
+ const { owner, name, branch } = sourceRepo ;
78
+ const sourceDockPath = docPathArray . slice ( 1 ) . join ( '/' ) ;
79
+ return `https://github.com/${ owner } /${ name } /tree/${ branch } /docs/${ sourceDockPath } ` ;
80
+ } ;
81
81
82
82
/** @type {import('@docusaurus/types').Config } */
83
83
const config = {
@@ -124,14 +124,17 @@ const config = {
124
124
} ,
125
125
blog : false ,
126
126
theme : {
127
- customCss : [ require . resolve ( './src/css/custom.css' ) , require . resolve ( './src/ui/design-system/styles/main.css' ) ] ,
127
+ customCss : [
128
+ require . resolve ( './src/css/custom.css' ) ,
129
+ require . resolve ( './src/ui/design-system/styles/main.css' ) ,
130
+ ] ,
128
131
} ,
129
132
...( process . env . GA_TRACKING_ID
130
133
? {
131
134
gtag : {
132
135
trackingID : process . env . GA_TRACKING_ID ,
133
136
anonymizeIP : true ,
134
- }
137
+ } ,
135
138
}
136
139
: { } ) ,
137
140
} ) ,
@@ -158,7 +161,6 @@ const config = {
158
161
themeConfig :
159
162
/** @type {import('@docusaurus/preset-classic').ThemeConfig } */
160
163
( {
161
-
162
164
colorMode : {
163
165
defaultMode : 'dark' ,
164
166
} ,
@@ -204,7 +206,7 @@ const config = {
204
206
href : 'https://onflow.org/discord' ,
205
207
label : 'Discord' ,
206
208
position : 'right' ,
207
- }
209
+ } ,
208
210
] ,
209
211
} ,
210
212
footer : {
@@ -376,7 +378,7 @@ const config = {
376
378
{
377
379
href : 'https://onflow.org/' ,
378
380
label : 'OnFlow' ,
379
- }
381
+ } ,
380
382
] ,
381
383
} ,
382
384
] ,
@@ -417,47 +419,90 @@ const config = {
417
419
} ,
418
420
} ) ,
419
421
plugins : [
420
- function tailwindPlugin ( context , options ) {
422
+ function redirectPlugin ( ) {
423
+ return {
424
+ name : '@docusaurus/plugin-client-redirects' ,
425
+ fromExtensions : [ 'html' , 'htm' ] , // /myPage.html -> /myPage
426
+ toExtensions : [ 'exe' , 'zip' ] , // /myAsset -> /myAsset.zip (if latter exists)
427
+ redirects : [
428
+ // /docs/oldDoc -> /docs/newDoc
429
+ {
430
+ to : '/docs/newDoc' ,
431
+ from : '/docs/oldDoc' ,
432
+ } ,
433
+ // Redirect from multiple old paths to the new path
434
+ {
435
+ to : '/docs/newDoc2' ,
436
+ from : [ '/docs/oldDocFrom2019' , '/docs/legacyDocFrom2016' ] ,
437
+ } ,
438
+ ] ,
439
+ createRedirects ( existingPath ) {
440
+ if ( existingPath . includes ( '/community' ) ) {
441
+ // Redirect from /docs/team/X to /community/X and /docs/support/X to /community/X
442
+ return [
443
+ existingPath . replace ( '/community' , '/docs/team' ) ,
444
+ existingPath . replace ( '/community' , '/docs/support' ) ,
445
+ ] ;
446
+ }
447
+ return undefined ; // Return a falsy value: no redirect created
448
+ } ,
449
+ } ;
450
+ } ,
451
+ function tailwindPlugin ( ) {
421
452
return {
422
453
name : 'docusaurus-tailwindcss' ,
423
- configurePostCss ( postcssOptions ) {
454
+ configurePostCss ( postcssOptions ) {
424
455
// Appends TailwindCSS and AutoPrefixer.
425
- postcssOptions . plugins . push ( require ( 'tailwindcss' ) )
426
- postcssOptions . plugins . push ( require ( 'autoprefixer' ) )
427
- return postcssOptions
456
+ postcssOptions . plugins . push ( require ( 'tailwindcss' ) ) ;
457
+ postcssOptions . plugins . push ( require ( 'autoprefixer' ) ) ;
458
+ return postcssOptions ;
428
459
} ,
429
- }
460
+ } ;
430
461
} ,
431
462
/** this function needs doesn't pick up hot reload event, it needs a restart */
432
463
function ( context , options ) {
433
- const { siteConfig } = context
464
+ const { siteConfig } = context ;
434
465
return {
435
466
name : 'docusaurus-flow-networks-plugin' ,
436
- async loadContent ( ) {
437
- const networks = JSON . parse ( fs . readFileSync ( path . join ( __dirname , './src/data/networks.json' ) ) . toString ( ) )
438
- const sporks = JSON . parse ( fs . readFileSync ( path . join ( __dirname , './src/data/sporks.json' ) ) . toString ( ) )
467
+ async loadContent ( ) {
468
+ const networks = JSON . parse (
469
+ fs
470
+ . readFileSync ( path . join ( __dirname , './src/data/networks.json' ) )
471
+ . toString ( ) ,
472
+ ) ;
473
+ const sporks = JSON . parse (
474
+ fs
475
+ . readFileSync ( path . join ( __dirname , './src/data/sporks.json' ) )
476
+ . toString ( ) ,
477
+ ) ;
439
478
return {
440
479
networks,
441
480
sporks,
442
- }
481
+ } ;
443
482
} ,
444
- async contentLoaded ( { content, actions } ) {
445
- const { networks, sporks } = content
446
- const { addRoute, createData } = actions
447
- const networksJsonPath = await createData ( 'networks.json' , JSON . stringify ( networks ) )
448
- const sporksJsonPath = await createData ( 'sporks.json' , JSON . stringify ( sporks ) )
483
+ async contentLoaded ( { content, actions } ) {
484
+ const { networks, sporks } = content ;
485
+ const { addRoute, createData } = actions ;
486
+ const networksJsonPath = await createData (
487
+ 'networks.json' ,
488
+ JSON . stringify ( networks ) ,
489
+ ) ;
490
+ const sporksJsonPath = await createData (
491
+ 'sporks.json' ,
492
+ JSON . stringify ( sporks ) ,
493
+ ) ;
449
494
addRoute ( {
450
495
path : `${ siteConfig . baseUrl } network` ,
451
496
exact : true ,
452
497
component : '@site/src/components/networks' ,
453
498
modules : {
454
499
networks : networksJsonPath ,
455
500
sporks : sporksJsonPath ,
456
- }
457
- } )
501
+ } ,
502
+ } ) ;
458
503
459
504
networks . forEach ( async ( network ) => {
460
- const { urlPath } = network
505
+ const { urlPath } = network ;
461
506
462
507
addRoute ( {
463
508
path : `${ siteConfig . baseUrl } network/${ urlPath } ` ,
@@ -466,12 +511,12 @@ const config = {
466
511
modules : {
467
512
networks : networksJsonPath ,
468
513
sporks : sporksJsonPath ,
469
- }
470
- } )
471
- } )
472
- }
473
- }
474
- }
514
+ } ,
515
+ } ) ;
516
+ } ) ;
517
+ } ,
518
+ } ;
519
+ } ,
475
520
// require('./plugins/networks')
476
521
] ,
477
522
stylesheets : [
@@ -483,6 +528,6 @@ const config = {
483
528
crossorigin : 'anonymous' ,
484
529
} ,
485
530
] ,
486
- }
531
+ } ;
487
532
488
- module . exports = config
533
+ module . exports = config ;
0 commit comments