-
Notifications
You must be signed in to change notification settings - Fork 55
/
docusaurus.config.js
658 lines (622 loc) · 18.6 KB
/
docusaurus.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
require('dotenv').config();
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const { remarkCodeHike } = require('@code-hike/mdx');
const path = require('path');
const fs = require('fs');
const flowNetwork = process.env.FLOW_NETWORK || 'testnet';
const externalDataSourceLocation = './src/data/data-sources.json';
let cachedRepositories;
const hasTypesense =
process.env.TYPESENSE_NODE && process.env.TYPESENSE_SEARCH_ONLY_API_KEY;
const mixpanelOnLoad = `
if ('${process.env.MIXPANEL_PROJECT_TOKEN}' && '${process.env.MIXPANEL_PROJECT_TOKEN}' !== 'undefined') {
window.mixpanel.init('${process.env.MIXPANEL_PROJECT_TOKEN}');
const viwedPayload = {
'Page Name': document.title,
'Page URL': window.location.pathname,
}
window.mixpanel.track('Page Viewed', viwedPayload);
const playUrl = 'play.flow.com';
const links = document.querySelectorAll('a') || [];
const isPlayPage = Array.from(links).some((link) => link.href.includes(playUrl));
if (isPlayPage) {
window.mixpanel.track('Play Page Viewed', viwedPayload);
}
window.document.addEventListener('click', function (event) {
var target = event.target;
// Check if the clicked element is a link with an href attribute
if (target.tagName === 'A' && target.hasAttribute('href')) {
if (window.mixpanel) {
const payload = {
href: target.getAttribute('href'),
id: target.id,
class: target.className,
}
window.mixpanel.track('Link clicked', payload);
const isPlay = payload.href.includes('play.flow.com');
if (isPlay) {
window.mixpanel.track('Play Link clicked', payload);
}
}
}
});
}
`;
const fetchSporkData = async () => {
const fetch = await import('node-fetch');
let data = {};
try {
const response = await fetch.default(
'https://raw.githubusercontent.com/onflow/flow/master/sporks.json',
);
data = (await response.json()) || {};
} catch (error) {
console.error('Error:', error);
}
return data;
};
const getUrl = () => {
if (process.env.VERCEL_ENV === 'production') {
return 'https://developers.flow.com';
}
if (process.env.VERCEL_URL) {
return `https://${process.env.VERCEL_URL}`;
}
return 'https://onflow.github.io';
};
/**
* @typedef {Object} SourceDestination
* @property {string} source - Source
* @property {string} destination - Destination
*/
/**
* @typedef {Object} Repository
* @property {string} owner - Repo owner
* @property {string} name - Repo name
* @property {string} branch - Repo branch
* @property {SourceDestination[]} data - Source-Destination
*/
/**
* @typedef {Object} Repo
* @property {Repository} repository - Repo owner
*/
/**
* @returns {Repo[]}
*/
const getRepositories = () => {
if (!cachedRepositories) {
const filePath = path.join(__dirname, externalDataSourceLocation);
try {
cachedRepositories = JSON.parse(fs.readFileSync(filePath).toString());
} catch (error) {
console.error('Cannot parse: ' + error);
}
}
return cachedRepositories;
};
/** @type {import('@docusaurus/plugin-content-docs').MetadataOptions['editUrl']} */
const editUrl = ({ docPath }) => {
const repositories = getRepositories();
const sourceRepository = repositories.reduce((acc, { repository }) => {
const sourceData = repository.data.find(({ destination }) =>
docPath.includes(destination),
);
if (sourceData) {
return {
...repository,
...sourceData,
};
}
return acc;
}, null);
if (!sourceRepository) {
return `https://github.com/onflow/docs/tree/main/docs/${docPath}`;
}
const { owner, name, branch, source, destination } = sourceRepository;
const sourceDocPath = docPath.replace(destination, source);
return `https://github.com/${owner}/${name}/tree/${branch}/${sourceDocPath}`;
};
const baseUrl = process.env.BASE_URL || '/';
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Flow Developer Portal',
tagline: '',
favicon: 'favicon.ico',
// Set the production url of your site here
url: getUrl(),
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl,
// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
organizationName: 'onflow', // Usually your GitHub org/user name.
projectName: 'docs', // Usually your repo name.
trailingSlash: false,
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'throw',
onDuplicateRoutes: 'warn',
// Even if you don't use internalization, you can use this field to set useful
// metadata like html lang. For example, if your site is Chinese, you may want
// to replace "en" with "zh-Hans".
i18n: {
defaultLocale: 'en',
locales: ['en'],
},
presets: [
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
beforeDefaultRemarkPlugins: [
require('./src/plugins/code-reference').plugin,
[
remarkCodeHike,
{ theme: 'nord', lineNumbers: true, showCopyButton: true },
],
],
sidebarPath: require.resolve('./sidebars.js'),
routeBasePath: '/',
editUrl,
remarkPlugins: [require('remark-math')],
rehypePlugins: [require('rehype-katex')],
showLastUpdateTime: true,
showLastUpdateAuthor: true,
numberPrefixParser: true,
},
blog: false,
theme: {
customCss: [
require.resolve('./src/ui/design-system/styles/main.css'),
require.resolve('@code-hike/mdx/styles.css'),
require.resolve('./src/css/custom.css'),
],
},
...(process.env.GTAG
? {
gtag: {
trackingID: process.env.GTAG,
anonymizeIP: true,
},
}
: {}),
}),
],
[
'redocusaurus',
{
// Plugin Options for loading OpenAPI files
specs: [
{
spec: 'https://raw.githubusercontent.com/onflow/flow/master/openapi/access.yaml',
route: '/http-api/',
},
],
// Theme Options for modifying how redoc renders them
theme: {
// Change with your site colors
primaryColor: '#1890ff',
},
},
],
],
themes: [hasTypesense && 'docusaurus-theme-search-typesense'].filter(Boolean),
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
colorMode: {
defaultMode: 'dark',
},
// Replace with your project's social card
image: 'img/FlowDocs_Logo_FlowLogo_Horizontal_Green_BlackText.svg',
docs: {
sidebar: {
autoCollapseCategories: true,
},
},
navbar: {
title: '',
logo: {
alt: 'Flow Developer Portal Logo',
src: 'img/flow-docs-logo-dark.png',
srcDark: 'img/flow-docs-logo-light.png',
},
items: [
{
to: 'build/flow',
position: 'left',
label: 'Build With Cadence',
activeBasePath: '/build',
},
{
to: 'evm/about',
position: 'left',
label: 'Build With EVM',
activeBasePath: '/evm',
},
{
to: 'tools/flow-cli',
position: 'left',
label: 'Tools',
activeBasePath: '/tools',
},
{
to: 'networks/flow-networks',
position: 'left',
label: 'Networks',
activeBasePath: '/networks',
},
{
to: 'ecosystem',
position: 'left',
label: 'Ecosystem',
activeBasePath: '/ecosystem',
},
{
to: 'growth',
position: 'left',
label: 'Growth',
activeBasePath: '/growth',
},
{
type: 'custom-connectButton',
position: 'right',
},
{
href: 'https://github.com/onflow',
html: '<img src="" alt="GitHub" id="navbar-github" class="box-content h-32 w-32"/><span class="p-2 desktop:hidden">Github</span>',
position: 'right',
className: 'h-8 desktop:p-1',
},
{
href: 'https://discord.gg/flow',
html: '<img src="" alt="Discord" id="navbar-discord" class="box-content h-32 w-32"/><span class="p-2 desktop:hidden">Discord</span>',
position: 'right',
className: 'h-8 desktop:p-1',
},
],
},
footer: {
style: 'dark',
links: [
{
title: 'Documentation',
items: [
{
label: 'Getting Started',
to: '/build/getting-started/contract-interaction',
},
{
label: "SDK's & Tools",
to: '/tools',
},
{
to: 'https://cadence-lang.org/docs/',
label: 'Cadence',
},
{
to: '/build/guides/mobile/overview',
label: 'Mobile',
},
{
to: '/tools/clients/fcl-js/',
label: 'FCL',
},
{
to: '/build/smart-contracts/testing',
label: 'Testing',
},
{
to: '/tools/flow-cli/',
label: 'CLI',
},
{
to: '/tools/emulator/',
label: 'Emulator',
},
{
href: 'https://github.com/onflow/fcl-dev-wallet',
label: 'Dev Wallet',
},
{
to: '/tools/vscode-extension/',
label: 'VS Code Extension',
},
],
},
{
title: 'Community',
items: [
{
to: '/ecosystem',
label: 'Ecosystem',
},
{
href: 'https://port.onflow.org/',
label: 'Flow Port',
},
{
href: 'https://github.com/onflow/developer-grants',
label: 'Developer Grants',
},
{
href: 'https://flow.com/flow-responsible-disclosure',
label: 'Responsible Disclosure',
},
{
href: 'https://www.flowverse.co/',
label: 'Flowverse',
},
{
href: 'https://academy.ecdao.org/',
label: 'Emerald Academy',
},
{
href: 'https://floats.city/',
label: 'FLOATs (Attendance NFTs)',
},
],
},
{
title: 'Start Building',
items: [
{
href: 'https://play.flow.com/',
label: 'Flow Playground',
},
{
to: 'https://cadence-lang.org/docs/tutorial/first-steps',
label: 'Cadence Tutorials',
},
{
href: 'https://open-cadence.onflow.org',
label: 'Cadence Cookbook',
},
{
to: '/build/core-contracts/',
label: 'Core Contracts & Standards',
},
{
href: '/evm/about',
label: 'EVM',
},
],
},
{
title: 'Network',
items: [
{
href: 'https://status.onflow.org/',
label: 'Network Status',
},
{
href: 'https://flowdiver.io/',
label: 'Flowdiver Mainnet',
},
{
href: 'https://testnet.flowdiver.io/',
label: 'Flowdiver Testnet',
},
{
to: '/networks/node-ops/node-operation/past-sporks',
label: 'Past Sporks',
},
{
to: '/networks/node-ops/node-operation/upcoming-sporks',
label: 'Upcoming Sporks',
},
{
to: '/networks/node-ops',
label: 'Node Operation',
},
{
to: '/networks/node-ops/node-operation/spork',
label: 'Spork Information',
},
],
},
{
title: 'More',
items: [
{
href: 'https://github.com/onflow',
label: 'GitHub',
},
{
href: 'https://discord.gg/flow',
label: 'Discord',
},
{
href: 'https://forum.onflow.org/',
label: 'Forum',
},
{
href: 'https://onflow.org/',
label: 'OnFlow',
},
{
href: 'https://flow.com/blog',
label: 'Blog',
},
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} Flow, Inc. Built with Docusaurus.`,
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
typesense: hasTypesense && {
// Replace this with the name of your index/collection.
// It should match the "index_name" entry in the scraper's "config.json" file.
typesenseCollectionName: 'flow_docs',
typesenseServerConfig: {
nodes: [
{
host: process.env.TYPESENSE_NODE,
port: 443,
protocol: 'https',
},
],
apiKey: process.env.TYPESENSE_SEARCH_ONLY_API_KEY,
},
// Optional: Typesense search parameters: https://typesense.org/docs/0.24.0/api/search.html#search-parameters
typesenseSearchParameters: {},
// Optional
contextualSearch: true,
},
}),
plugins: [
function customizedSvgo() {
return {
name: 'docusaurus-svgo',
configureWebpack(config) {
// allow svgr to use svgo config file
for (const rule of config.module.rules) {
if (
typeof rule === 'object' &&
rule.test.toString() === '/\\.svg$/i'
) {
for (const nestedRule of rule.oneOf) {
if (nestedRule.use instanceof Array) {
for (const loader of nestedRule.use) {
if (
typeof loader === 'object' &&
loader.loader === require.resolve('@svgr/webpack')
) {
if (typeof loader.options === 'object') {
loader.options.svgoConfig = null;
}
}
}
}
}
}
}
return {
mergeStrategy: {
'module.rules': 'replace',
},
module: {
rules: config.module.rules,
},
};
},
};
},
function tailwindPlugin() {
return {
name: 'docusaurus-tailwindcss',
configurePostCss(postcssOptions) {
// Appends TailwindCSS and AutoPrefixer.
postcssOptions.plugins.push(require('tailwindcss'));
postcssOptions.plugins.push(require('autoprefixer'));
return postcssOptions;
},
};
},
/** this function needs doesn't pick up hot reload event, it needs a restart */
// @ts-expect-error
function (context, options) {
const { siteConfig } = context;
return {
name: 'docusaurus-flow-networks-plugin',
async loadContent() {
const networks = JSON.parse(
fs
.readFileSync(path.join(__dirname, './src/data/networks.json'))
.toString(),
);
const sporks = await fetchSporkData();
return {
networks,
sporks,
};
},
async contentLoaded({ content, actions }) {
// @ts-expect-error
const { networks, sporks } = content;
const { addRoute, createData } = actions;
const networksJsonPath = await createData(
'networks.json',
JSON.stringify(networks),
);
const sporksJsonPath = await createData(
'sporks.json',
JSON.stringify(sporks),
);
addRoute({
path: `${siteConfig.baseUrl}network`,
exact: true,
component: '@site/src/components/networks',
modules: {
networks: networksJsonPath,
sporks: sporksJsonPath,
},
});
networks.forEach(async (network) => {
const { urlPath } = network;
addRoute({
path: `${siteConfig.baseUrl}network/${urlPath}`,
exact: true,
component: '@site/src/components/network',
modules: {
networks: networksJsonPath,
sporks: sporksJsonPath,
},
});
});
},
};
},
// require('./plugins/networks')
[
'@docusaurus/plugin-client-redirects',
{
redirects: [
{
to: '/build/smart-contracts/overview',
from: '/build/basics/smart-contracts',
},
],
createRedirects(existingPath) {
if (existingPath.includes('/cadence')) {
return [
existingPath.replace('https://cadence-lang.org/docs', '/cadence'),
];
}
return undefined;
},
},
],
],
stylesheets: [
{
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
type: 'text/css',
integrity:
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
crossorigin: 'anonymous',
},
],
scripts: [
{
src: `${baseUrl}mixpanel.js`,
async: true,
onload: mixpanelOnLoad,
},
{
src: `${baseUrl}hotjar.js`,
async: true,
},
],
clientModules: [require.resolve('./src/modules/toolscards.ts')],
customFields: {
flowNetwork,
},
};
module.exports = config;