Skip to content

Commit 07e8eb0

Browse files
authored
add prettier and rename project and url (#7)
* add prettier and rename project and url * fix merge conflicts
1 parent 547f759 commit 07e8eb0

File tree

5 files changed

+177
-81
lines changed

5 files changed

+177
-81
lines changed

.eslintrc.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
module.exports = {
22
env: {
33
browser: true,
4-
es2021: true
4+
es2021: true,
55
},
6-
extends: [
7-
'plugin:react/recommended',
8-
'standard-with-typescript'
9-
],
10-
overrides: [
11-
],
6+
extends: ['plugin:react/recommended', 'standard-with-typescript', 'prettier'],
7+
overrides: [],
128
parserOptions: {
139
ecmaVersion: 'latest',
1410
sourceType: 'module',
15-
project: './tsconfig.json'
11+
project: './tsconfig.json',
1612
},
17-
plugins: [
18-
'react'
19-
],
13+
plugins: ['react', 'prettier'],
2014
rules: {
2115
'comma-dangle': 'off',
22-
'@typescript-eslint/comma-dangle': 'off'
16+
'@typescript-eslint/comma-dangle': 'off',
17+
'prettier/prettier': 'error',
2318
},
2419
settings: {
2520
react: {
26-
version: 'detect'
27-
}
28-
}
29-
}
21+
version: 'detect',
22+
},
23+
},
24+
};

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "all",
8+
"bracketSpacing": true
9+
}

docusaurus.config.js

+110-65
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
// @ts-check
22
// 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');
66

7-
const path = require('path')
8-
const fs = require('fs')
7+
const path = require('path');
8+
const fs = require('fs');
99

10-
const docCollectionsLocation = './src/data/doc-collections'
11-
let cachedSources
10+
const docCollectionsLocation = './src/data/doc-collections';
11+
let cachedSources;
1212

1313
/**
1414
*
1515
* @returns {string[]}
1616
*/
1717
const getDocFileNames = () => {
1818
try {
19-
const docCollectionPath = path.join(__dirname, docCollectionsLocation, '/')
20-
const files = fs.readdirSync(docCollectionPath)
21-
return files.filter((filename) => filename.match(/\.json$/))
19+
const docCollectionPath = path.join(__dirname, docCollectionsLocation, '/');
20+
const files = fs.readdirSync(docCollectionPath);
21+
return files.filter((filename) => filename.match(/\.json$/));
2222
} catch (error) {
23-
console.error('Unable to scan directory: ' + error)
23+
console.error('Unable to scan directory: ' + error);
2424
}
25-
}
25+
};
2626
/**
2727
*
2828
* @param {string} filename
2929
* @returns {string}
3030
*/
3131
const getSource = (filename) => {
32-
const filePath = path.join(__dirname, docCollectionsLocation, filename)
32+
const filePath = path.join(__dirname, docCollectionsLocation, filename);
3333
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;
3636
} catch (error) {
37-
console.error('Cannot parse: ' + error)
37+
console.error('Cannot parse: ' + error);
3838
}
39-
}
39+
};
4040

4141
/**
4242
* @typedef {Object} Source
@@ -51,33 +51,33 @@ const getSource = (filename) => {
5151
*/
5252
const getSources = () => {
5353
if (!cachedSources) {
54-
const docFilenames = getDocFileNames()
54+
const docFilenames = getDocFileNames();
5555

5656
cachedSources = docFilenames.reduce((acc, filename) => {
57-
const source = getSource(filename)
57+
const source = getSource(filename);
5858
if (!source) {
59-
return acc
59+
return acc;
6060
}
61-
return [...acc, source]
62-
}, [])
61+
return [...acc, source];
62+
}, []);
6363
}
64-
return cachedSources
65-
}
64+
return cachedSources;
65+
};
6666

6767
/** @type {import('@docusaurus/plugin-content-docs').MetadataOptions['editUrl']} */
6868
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();
7272

73-
const sourceRepo = sources.find(({ name }) => name === repoName)
73+
const sourceRepo = sources.find(({ name }) => name === repoName);
7474
if (!sourceRepo) {
75-
return
75+
return;
7676
}
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+
};
8181

8282
/** @type {import('@docusaurus/types').Config} */
8383
const config = {
@@ -124,14 +124,17 @@ const config = {
124124
},
125125
blog: false,
126126
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+
],
128131
},
129132
...(process.env.GA_TRACKING_ID
130133
? {
131134
gtag: {
132135
trackingID: process.env.GA_TRACKING_ID,
133136
anonymizeIP: true,
134-
}
137+
},
135138
}
136139
: {}),
137140
}),
@@ -158,7 +161,6 @@ const config = {
158161
themeConfig:
159162
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
160163
({
161-
162164
colorMode: {
163165
defaultMode: 'dark',
164166
},
@@ -204,7 +206,7 @@ const config = {
204206
href: 'https://onflow.org/discord',
205207
label: 'Discord',
206208
position: 'right',
207-
}
209+
},
208210
],
209211
},
210212
footer: {
@@ -376,7 +378,7 @@ const config = {
376378
{
377379
href: 'https://onflow.org/',
378380
label: 'OnFlow',
379-
}
381+
},
380382
],
381383
},
382384
],
@@ -417,47 +419,90 @@ const config = {
417419
},
418420
}),
419421
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() {
421452
return {
422453
name: 'docusaurus-tailwindcss',
423-
configurePostCss (postcssOptions) {
454+
configurePostCss(postcssOptions) {
424455
// 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;
428459
},
429-
}
460+
};
430461
},
431462
/** this function needs doesn't pick up hot reload event, it needs a restart */
432463
function (context, options) {
433-
const { siteConfig } = context
464+
const { siteConfig } = context;
434465
return {
435466
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+
);
439478
return {
440479
networks,
441480
sporks,
442-
}
481+
};
443482
},
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+
);
449494
addRoute({
450495
path: `${siteConfig.baseUrl}network`,
451496
exact: true,
452497
component: '@site/src/components/networks',
453498
modules: {
454499
networks: networksJsonPath,
455500
sporks: sporksJsonPath,
456-
}
457-
})
501+
},
502+
});
458503

459504
networks.forEach(async (network) => {
460-
const { urlPath } = network
505+
const { urlPath } = network;
461506

462507
addRoute({
463508
path: `${siteConfig.baseUrl}network/${urlPath}`,
@@ -466,12 +511,12 @@ const config = {
466511
modules: {
467512
networks: networksJsonPath,
468513
sporks: sporksJsonPath,
469-
}
470-
})
471-
})
472-
}
473-
}
474-
}
514+
},
515+
});
516+
});
517+
},
518+
};
519+
},
475520
// require('./plugins/networks')
476521
],
477522
stylesheets: [
@@ -483,6 +528,6 @@ const config = {
483528
crossorigin: 'anonymous',
484529
},
485530
],
486-
}
531+
};
487532

488-
module.exports = config
533+
module.exports = config;

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"@docusaurus/core": "2.4.0",
1919
"@docusaurus/preset-classic": "2.4.0",
20+
"@docusaurus/plugin-client-redirects": "^2.4.0",
2021
"@floating-ui/react-dom": "1.3.0",
2122
"@headlessui/react": "1.7.13",
2223
"@mdx-js/react": "^1.6.22",
@@ -29,7 +30,10 @@
2930
"date-fns": "2.29.3",
3031
"discord.js": "14.8.0",
3132
"dotenv": "16.0.3",
33+
"eslint-config-prettier": "^8.8.0",
34+
"eslint-plugin-prettier": "^4.2.1",
3235
"postcss": "8.4.21",
36+
"prettier": "^2.8.7",
3337
"prism-react-renderer": "^1.3.5",
3438
"react": "^17.0.2",
3539
"react-dom": "^17.0.2",

0 commit comments

Comments
 (0)