If you want to add new content or make structural updates to the documentation, follow this guide. Also, read the Writing Style Guide.
This documentation website uses the following infrastructure:
- Docusaurus (2.4.0)
- React (17.0.1)
- Node (>=16.14)
To see the current versions, open the package.json file.
The table below shows you the main structure of the documentation framework.
| Folder/File | Description |
|---|---|
| .docusaurus | Docusaurus default configuration module |
| .github | GitHub module |
| .husky | Husky script module |
| .vscode | Visual Studio Code editor configuration |
| build | Docusaurus build packages |
| config | Docusaurus detailed configuration modules |
| source/blog | Blog page module |
| source/docs | Main documentation .md files |
| source/i18n | Localization packages |
| scripts | Bash script module |
| src/assets | Asset modules (style/image/icons) |
| src/components | Component module |
| src/html | HTML codebase |
| src/mocks | Mocks data module |
| src/pages | React page module |
| src/utils | Utility module |
| static | Static modules (image/icons) |
| types | Type interface definition part |
| .env | Environment variables |
| .eslintrc | Eslint configuration |
| .prettierrc | Prettier configuration |
| .textlintrc | Text lint configuration |
| Babel.config.js | Babel configuration |
| Crowdin.yml | Crowdin configuration |
| Docusaurus.config.js | Docusaurus configuration |
| package.json | NPM package list |
| Tsconfig.js | Typescript configuration |
| yarn.lock | Package dependency graph |
Build and run the project as shown in the README.
You might find these commands useful:
yarn start- Run the project in dev modeyarn build- Build the project pagesyarn swizzle- Eject a Docusaurus core source component to customize it. Do not eject all components; eject a specific component by adding parameters to this commandyarn deploy- Deploy your Docusaurus project using GitHub hostingyarn clear- Remove previous buildsyarn serve- Host the projectyarn write-translations- Generate translation modules automatically from pagesyarn write-heading-ids-Generate translation modules automatically from pagesyarn crowdin:sync- Build, upload, and download translation modulesyarn run:prettier- Format the code baseyarn run:eslint- Check the code style based on eslintyarn format- Runprettierandlintin sequenceyarn reinstall- Reinstall allnpmpackagesyarn prepare- This is an internal command forhuskyinstall; you do not need to run this command because it is included inyarn installyarn commit- Internal command forlint-stage. This command is included in pre-commit hooks, so you do not need to run this command but we include this here for visibility
- To create a new document, add an
mdormdxfile at an intuitive location in the source directory, docs/casper. Page routing will depend on page hierarchy unless you specify the routing in the config folder.- You will need to update the sidebar to include the new file.
- To add an overview page or a new tutorial, use a template from the templates folder.
- Add images in the static/image directory.
- To create React pages, follow the pattern in the src/page directory.
- Create reusable components in the src/components directory based on their purpose.
- Define or declare the necessary types in the component or in the types directory.
- Follow the pattern from the Background or Hero components.
To add or update a sidebar:
- Open the config/sidebar.config.js file.
- To add a new directory or file in the sidebar, update the
module.exportsstructure. - Note that item hierarchy depends on the order in which you list the items in this file.
For example, if you want to add a new directory called workflow, then add the following code as a property in module.exports:
module.exports = {
workflow: [
"workflow/index",
"workflow/staking",
...
],
...To create or update a navbar, open and update the config/navbar.config.js file. Note that item hierarchy depends on the item order in this file. For example, if you want to create a navbar called Staking, add the following property in the module.exports structure:
{
to: `${routePrefix}/staking`,
activeBasePath: `${routePrefix}/staking`,
label: "Staking",
position: "left",
},To create or update a footer, open the config/footer.config.js file. Note that item hierarchy depends on the item order in this file. For example, assuming you want to add an item called Style Guide, add the following property:
title: 'Docs',
items: [
{
label: 'Style Guide',
to: 'docs/',
},To create new theme, add a variable in this file: scss/variable.scss and a theme class in the scss/theme.scss file.
To change an existing theme, modify the config/color.config.js file.
For example, you can switch to the light theme:
module.exports = {
defaultMode: "light",
respectPrefersColorScheme: false,
disableSwitch: false,
};To migrate reStructuredText (.rst) files to markdown (.md) files, follow these steps:
- Add the new
.rstdocuments into the top-level directory. - Run
yarn run:migrate. - Check that the
.rstdocuments were converted to.mdfiles. - Remove the original
.rstfiles.
For more information, reference the scripts/rst-to-md.sh script.
For embedding HTML, follow the example in the src/html/footer.html and config/footer.config.js files.
You can add icons and images in the static folder.
- Add icons in the
iconsub-folder, using this pattern:icon_name.svg. - Add images in the
imagesub-folder, using this pattern:image_name.png.
Open the config/algolia.config.js file and specify the apiKey and indexName. Customize the search box or create a new style using the src/assets/scss/theme.scss file.
If the Docusaurus version is updated, the navbar, footer and side bar could stop working. In that case, run this command to restructure the navbar:
npm run swizzle @docusaurus/theme-classic Navbar -- --ejectFor more information, visit https://docusaurus.io/docs/swizzling.
Use the following environment variables to enable the navbar:
DIRECTUS_URL=REPLACE_WITH_YOUR_DIRECTUS_URL
DIRECTUS_GRAPHQL_URL=REPLACE_WITH_YOUR_DIRECTUS_GRAPH_URL
DIRECTUS_TOKEN=REPLACE_WITH_YOUR_DIRECTUS_TOKEN
SITE_URL=REPLACE_WITH_YOUR_SITE_URL
ALGOLIA_SITE_APP_ID=REPLACE_WITH_YOUR_ALGOLIA_SITE_APP_ID
ALGOLIA_SITE_API_KEY=REPLACE_WITH_YOUR_ALGOLIA_SITE_API_KEY
ALGOLIA_SITE_INDEX_NAME=REPLACE_WITH_YOUR_ALGOLIA_SITE_INDEX_NAME
Run the project locally and go to http://localhost:3000/__docusaurus/debug/routes.
If Git hooks are not working, try the following:
-
Install
huskylocally in the root level of the project using this command:`yarn add -D husky` -
Create new Git hooks using this command:
npx husky add .husky/pre-commit "npm run commit" -
Update the
pre-commitmodule with this script:#!/bin/sh . "$(dirname "$0")/_/husky.sh" npm run commit
-
Create a new
.jsfile to test the commit flow. You should be able to see the Git hooks triggering. -
Undo the test commit by using the following command:
git reset --hard HEAD