mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 17:57:48 +02:00
chore: release Docusaurus 3.3.0 + 3.3.1 + 3.3.2 (#10101)
This commit is contained in:
parent
2d8281fc03
commit
c125f7a272
146 changed files with 21297 additions and 228 deletions
117
CHANGELOG.md
117
CHANGELOG.md
|
@ -1,4 +1,119 @@
|
|||
# Docusaurus 2 Changelog
|
||||
# Docusaurus Changelog
|
||||
|
||||
## 3.3.2 (2024-05-03)
|
||||
|
||||
#### :bug: Bug Fix
|
||||
|
||||
- `docusaurus-module-type-aliases`, `docusaurus`
|
||||
- [#10103](https://github.com/facebook/docusaurus/pull/10103) fix(core): do not recreate ReactDOM Root, fix React warning on hot reload ([@slorber](https://github.com/slorber))
|
||||
|
||||
#### Committers: 1
|
||||
|
||||
- Sébastien Lorber ([@slorber](https://github.com/slorber))
|
||||
|
||||
## 3.3.1 (2024-05-03)
|
||||
|
||||
Failed release
|
||||
|
||||
## 3.3.0 (2024-05-03)
|
||||
|
||||
#### :rocket: New Feature
|
||||
|
||||
- `docusaurus-plugin-sitemap`
|
||||
- [#10083](https://github.com/facebook/docusaurus/pull/10083) feat: add createSitemapItems hook ([@johnnyreilly](https://github.com/johnnyreilly))
|
||||
- `docusaurus-mdx-loader`, `docusaurus-types`, `docusaurus`
|
||||
- [#10064](https://github.com/facebook/docusaurus/pull/10064) feat(core): add new site config option `siteConfig.markdown.anchors.maintainCase` ([@iAdramelk](https://github.com/iAdramelk))
|
||||
- `docusaurus`
|
||||
- [#9767](https://github.com/facebook/docusaurus/pull/9767) feat(cli): docusaurus deploy should support a --target-dir option ([@SandPod](https://github.com/SandPod))
|
||||
- `docusaurus-plugin-content-blog`, `docusaurus-plugin-content-docs`, `docusaurus-plugin-content-pages`, `docusaurus-plugin-debug`, `docusaurus-types`, `docusaurus`
|
||||
- [#10042](https://github.com/facebook/docusaurus/pull/10042) feat(core): simplify plugin API, support route.props ([@slorber](https://github.com/slorber))
|
||||
- `docusaurus-plugin-content-pages`, `docusaurus-theme-classic`, `docusaurus-theme-common`
|
||||
- [#10032](https://github.com/facebook/docusaurus/pull/10032) feat(pages): add LastUpdateAuthor & LastUpdateTime & editUrl ([@OzakIOne](https://github.com/OzakIOne))
|
||||
|
||||
#### :bug: Bug Fix
|
||||
|
||||
- `docusaurus-cssnano-preset`, `docusaurus-utils`, `docusaurus`
|
||||
- [#10092](https://github.com/facebook/docusaurus/pull/10092) chore: Upgrade svgr / svgo / cssnano ([@slorber](https://github.com/slorber))
|
||||
- `docusaurus-theme-classic`
|
||||
- [#10091](https://github.com/facebook/docusaurus/pull/10091) fix(theme): `<Tabs>` props should allow overriding defaults ([@gagdiez](https://github.com/gagdiez))
|
||||
- [#10080](https://github.com/facebook/docusaurus/pull/10080) fix(theme): `<Admonition>` should render properly without heading/icon ([@andrmaz](https://github.com/andrmaz))
|
||||
- `docusaurus`
|
||||
- [#10090](https://github.com/facebook/docusaurus/pull/10090) fix(core): `docusaurus serve` redirects should include the site `/baseUrl/` prefix ([@slorber](https://github.com/slorber))
|
||||
- `docusaurus-module-type-aliases`, `docusaurus-preset-classic`, `docusaurus-theme-classic`, `docusaurus-theme-live-codeblock`, `docusaurus`
|
||||
- [#10079](https://github.com/facebook/docusaurus/pull/10079) fix: handle React v18.3 warnings ([@slorber](https://github.com/slorber))
|
||||
- `docusaurus-theme-translations`
|
||||
- [#10070](https://github.com/facebook/docusaurus/pull/10070) fix(theme-translations): add missing theme translations for pt-BR ([@h3nr1ke](https://github.com/h3nr1ke))
|
||||
- [#10051](https://github.com/facebook/docusaurus/pull/10051) fix(theme-translations): correct label for tip admonition in italian ([@tomsotte](https://github.com/tomsotte))
|
||||
- `docusaurus-theme-search-algolia`
|
||||
- [#10048](https://github.com/facebook/docusaurus/pull/10048) fix(algolia): add insights property on Algolia Theme Config object TS definition ([@Virgil993](https://github.com/Virgil993))
|
||||
- `docusaurus-plugin-content-docs`, `docusaurus`
|
||||
- [#10054](https://github.com/facebook/docusaurus/pull/10054) fix(core): sortRoutes shouldn't have a default baseUrl value, this led to a bug ([@slorber](https://github.com/slorber))
|
||||
- `docusaurus-plugin-content-docs`
|
||||
- [#10025](https://github.com/facebook/docusaurus/pull/10025) fix(docs): sidebar item label impact the pagination label of docs ([@Abdullah-03](https://github.com/Abdullah-03))
|
||||
- `docusaurus-utils`
|
||||
- [#10022](https://github.com/facebook/docusaurus/pull/10022) fix(utils): getFileCommitDate should support `log.showSignature=true` ([@slorber](https://github.com/slorber))
|
||||
|
||||
#### :running_woman: Performance
|
||||
|
||||
- `docusaurus`
|
||||
- [#10060](https://github.com/facebook/docusaurus/pull/10060) refactor(core): optimize App entrypoint, it should not re-render when navigating ([@slorber](https://github.com/slorber))
|
||||
|
||||
#### :nail_care: Polish
|
||||
|
||||
- `docusaurus-theme-classic`
|
||||
- [#10061](https://github.com/facebook/docusaurus/pull/10061) refactor(theme): simplify CSS solution to solve empty search container ([@slorber](https://github.com/slorber))
|
||||
- `docusaurus-theme-common`
|
||||
- [#10023](https://github.com/facebook/docusaurus/pull/10023) refactor(website): refactor showcase components ([@slorber](https://github.com/slorber))
|
||||
|
||||
#### :memo: Documentation
|
||||
|
||||
- [#10096](https://github.com/facebook/docusaurus/pull/10096) docs: Fix `déja` to `déjà` in `swizzling.mdx` ([@Zwyx](https://github.com/Zwyx))
|
||||
- [#10093](https://github.com/facebook/docusaurus/pull/10093) docs: Fix dead Typesense links ([@kaihoffman](https://github.com/kaihoffman))
|
||||
- [#10085](https://github.com/facebook/docusaurus/pull/10085) docs: make `ThemedImage` example work out of the box ([@lebalz](https://github.com/lebalz))
|
||||
- [#10082](https://github.com/facebook/docusaurus/pull/10082) docs: add note regarding ts extension for config file. ([@homotechsual](https://github.com/homotechsual))
|
||||
- [#9490](https://github.com/facebook/docusaurus/pull/9490) docs: add troubleshooting steps to migration/upgrade page ([@homotechsual](https://github.com/homotechsual))
|
||||
- [#10056](https://github.com/facebook/docusaurus/pull/10056) docs(search): Algolia troubleshooting section for index configuration problems ([@slorber](https://github.com/slorber))
|
||||
- [#10039](https://github.com/facebook/docusaurus/pull/10039) docs: visit is a named export of unist-util-visit ([@pearmini](https://github.com/pearmini))
|
||||
- [#10020](https://github.com/facebook/docusaurus/pull/10020) docs: Fix wrong path example ([@tomy0000000](https://github.com/tomy0000000))
|
||||
- [#10011](https://github.com/facebook/docusaurus/pull/10011) docs: add stormkit as deployment platform ([@eldemcan](https://github.com/eldemcan))
|
||||
|
||||
#### :robot: Dependencies
|
||||
|
||||
- [#10097](https://github.com/facebook/docusaurus/pull/10097) chore(deps): bump ejs from 3.1.9 to 3.1.10 ([@dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- [#10089](https://github.com/facebook/docusaurus/pull/10089) chore(deps): bump actions/dependency-review-action from 4.2.5 to 4.3.1 ([@dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- [#10088](https://github.com/facebook/docusaurus/pull/10088) chore(deps): bump preactjs/compressed-size-action from 2.5.0 to 2.6.0 ([@dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- [#10034](https://github.com/facebook/docusaurus/pull/10034) chore(deps): bump semver from 7.3.4 to 7.6.0 ([@dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
#### :wrench: Maintenance
|
||||
|
||||
- `create-docusaurus`, `docusaurus-cssnano-preset`, `docusaurus-logger`, `docusaurus-mdx-loader`, `docusaurus-plugin-client-redirects`, `docusaurus-plugin-content-blog`, `docusaurus-plugin-content-docs`, `docusaurus-plugin-content-pages`, `docusaurus-plugin-debug`, `docusaurus-plugin-google-analytics`, `docusaurus-plugin-google-gtag`, `docusaurus-plugin-google-tag-manager`, `docusaurus-plugin-ideal-image`, `docusaurus-plugin-pwa`, `docusaurus-plugin-sitemap`, `docusaurus-plugin-vercel-analytics`, `docusaurus-preset-classic`, `docusaurus-remark-plugin-npm2yarn`, `docusaurus-theme-classic`, `docusaurus-theme-common`, `docusaurus-theme-live-codeblock`, `docusaurus-theme-mermaid`, `docusaurus-theme-search-algolia`, `docusaurus-theme-translations`, `docusaurus-utils-common`, `docusaurus-utils-validation`, `docusaurus-utils`, `docusaurus`, `eslint-plugin`, `lqip-loader`, `stylelint-copyright`
|
||||
- [#10065](https://github.com/facebook/docusaurus/pull/10065) refactor: extract base TS client config + upgrade TS + refactor TS setup ([@slorber](https://github.com/slorber))
|
||||
- Other
|
||||
- [#10063](https://github.com/facebook/docusaurus/pull/10063) test(e2e): TypeCheck website/starter in min/max range of TS versions ([@slorber](https://github.com/slorber))
|
||||
- [#10049](https://github.com/facebook/docusaurus/pull/10049) fix(website): fix website manifest.json name "Docusaurus v2" to just "Docusaurus" ([@volcanofr](https://github.com/volcanofr))
|
||||
|
||||
#### Committers: 20
|
||||
|
||||
- Abdullah Saud ([@Abdullah-03](https://github.com/Abdullah-03))
|
||||
- Alexander Sandor ([@SandPod](https://github.com/SandPod))
|
||||
- Alexey Ivanov ([@iAdramelk](https://github.com/iAdramelk))
|
||||
- Andrea Mazzucchelli ([@andrmaz](https://github.com/andrmaz))
|
||||
- Bairui Su ([@pearmini](https://github.com/pearmini))
|
||||
- Balthasar Hofer ([@lebalz](https://github.com/lebalz))
|
||||
- Can Eldem ([@eldemcan](https://github.com/eldemcan))
|
||||
- Daniel Li ([@d4nyll](https://github.com/d4nyll))
|
||||
- Guille ([@gagdiez](https://github.com/gagdiez))
|
||||
- H3NR1KE ([@h3nr1ke](https://github.com/h3nr1ke))
|
||||
- John Reilly ([@johnnyreilly](https://github.com/johnnyreilly))
|
||||
- Kai Hoffman ([@kaihoffman](https://github.com/kaihoffman))
|
||||
- Mikey O'Toole ([@homotechsual](https://github.com/homotechsual))
|
||||
- Sébastien Lorber ([@slorber](https://github.com/slorber))
|
||||
- Tommaso Sotte ([@tomsotte](https://github.com/tomsotte))
|
||||
- Tomy Hsieh ([@tomy0000000](https://github.com/tomy0000000))
|
||||
- Zwyx ([@Zwyx](https://github.com/Zwyx))
|
||||
- [@Virgil993](https://github.com/Virgil993)
|
||||
- [@volcanofr](https://github.com/volcanofr)
|
||||
- ozaki ([@OzakIOne](https://github.com/OzakIOne))
|
||||
|
||||
## 3.2.1 (2024-04-04)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "new.docusaurus.io",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "npx --package netlify-cli netlify dev"
|
||||
|
|
|
@ -68,7 +68,7 @@ yarn serve
|
|||
|
||||
This local test step is optional because it will be run by the CI on your release PR ([see](https://github.com/facebook/docusaurus/pull/2954/checks?check_run_id=780871959))
|
||||
|
||||
### 3. Update the v2 changelog
|
||||
### 3. Update the changelog
|
||||
|
||||
The changelog uses GitHub labels to classify each pull request. Use the GitHub interface to assign each newly merged pull request to a GitHub label starting with `pr:`, otherwise the PR won't appear in the changelog.
|
||||
|
||||
|
@ -187,7 +187,7 @@ If all accesses are available, build all the necessary packages, and then run th
|
|||
|
||||
```sh
|
||||
yarn build:packages
|
||||
yarn lerna publish --exact 2.0.0-beta.0
|
||||
yarn lerna publish --force-publish --exact 2.0.0-beta.0
|
||||
```
|
||||
|
||||
This command does a few things:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "argos",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Argos visual diff tests",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"useNx": false,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "create-docusaurus",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Create Docusaurus apps easily.",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
@ -22,8 +22,8 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"commander": "^5.1.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docusaurus-2-classic-typescript-template",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
@ -15,8 +15,8 @@
|
|||
"typecheck": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/preset-classic": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/preset-classic": "3.3.2",
|
||||
"@mdx-js/react": "^3.0.0",
|
||||
"clsx": "^2.0.0",
|
||||
"prism-react-renderer": "^2.3.0",
|
||||
|
@ -24,9 +24,9 @@
|
|||
"react-dom": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/tsconfig": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/tsconfig": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"typescript": "~5.2.2"
|
||||
},
|
||||
"browserslist": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docusaurus-2-classic-template",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
@ -14,8 +14,8 @@
|
|||
"write-heading-ids": "docusaurus write-heading-ids"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/preset-classic": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/preset-classic": "3.3.2",
|
||||
"@mdx-js/react": "^3.0.0",
|
||||
"clsx": "^2.0.0",
|
||||
"prism-react-renderer": "^2.3.0",
|
||||
|
@ -23,8 +23,8 @@
|
|||
"react-dom": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1"
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/cssnano-preset",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Advanced cssnano preset for maximum optimization.",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/logger",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "An encapsulated logger for semantically formatting console messages.",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/mdx-loader",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus Loader for MDX",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,9 +18,9 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@mdx-js/mdx": "^3.0.0",
|
||||
"@slorber/remark-comment": "^1.0.0",
|
||||
"escape-html": "^1.0.3",
|
||||
|
@ -44,7 +44,7 @@
|
|||
"webpack": "^5.88.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@types/escape-html": "^1.0.2",
|
||||
"@types/mdast": "^4.0.2",
|
||||
"@types/stringify-object": "^3.3.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/module-type-aliases",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus module type aliases.",
|
||||
"types": "./src/index.d.ts",
|
||||
"publishConfig": {
|
||||
|
@ -12,7 +12,7 @@
|
|||
"directory": "packages/docusaurus-module-type-aliases"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@types/history": "^4.7.11",
|
||||
"@types/react": "*",
|
||||
"@types/react-router-config": "*",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-client-redirects",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Client redirects plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,18 +18,18 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"eta": "^2.2.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"tslib": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/types": "3.2.1"
|
||||
"@docusaurus/types": "3.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18.0.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-content-blog",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Blog plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/plugin-content-blog.d.ts",
|
||||
|
@ -31,13 +31,13 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/mdx-loader": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/mdx-loader": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"feed": "^4.2.2",
|
||||
"fs-extra": "^11.1.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-content-docs",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docs plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"sideEffects": false,
|
||||
|
@ -35,14 +35,14 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/mdx-loader": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/mdx-loader": "3.3.2",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@types/react-router-config": "^5.0.7",
|
||||
"combine-promises": "^1.1.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-content-pages",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Pages plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/plugin-content-pages.d.ts",
|
||||
|
@ -18,11 +18,11 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/mdx-loader": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/mdx-loader": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"fs-extra": "^11.1.1",
|
||||
"tslib": "^2.6.0",
|
||||
"webpack": "^5.88.1"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-debug",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Debug plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/plugin-debug.d.ts",
|
||||
|
@ -20,9 +20,9 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"fs-extra": "^11.1.1",
|
||||
"react-json-view-lite": "^1.2.0",
|
||||
"tslib": "^2.6.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-google-analytics",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Global analytics (analytics.js) plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,9 +18,9 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"tslib": "^2.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-google-gtag",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Global Site Tag (gtag.js) plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,9 +18,9 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@types/gtag.js": "^0.0.12",
|
||||
"tslib": "^2.6.0"
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-google-tag-manager",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Google Tag Manager (gtm.js) plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,9 +18,9 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"tslib": "^2.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-ideal-image",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder).",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/plugin-ideal-image.d.ts",
|
||||
|
@ -20,12 +20,12 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/lqip-loader": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/lqip-loader": "3.3.2",
|
||||
"@docusaurus/responsive-loader": "^1.7.0",
|
||||
"@docusaurus/theme-translations": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/theme-translations": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@slorber/react-ideal-image": "^0.0.12",
|
||||
"react-waypoint": "^10.3.0",
|
||||
"sharp": "^0.32.3",
|
||||
|
@ -33,7 +33,7 @@
|
|||
"webpack": "^5.88.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"fs-extra": "^11.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-pwa",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus Plugin to add PWA support.",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/plugin-pwa.d.ts",
|
||||
|
@ -22,12 +22,12 @@
|
|||
"dependencies": {
|
||||
"@babel/core": "^7.23.3",
|
||||
"@babel/preset-env": "^7.23.3",
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/theme-translations": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/theme-translations": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"babel-loader": "^9.1.3",
|
||||
"clsx": "^2.0.0",
|
||||
"core-js": "^3.31.1",
|
||||
|
@ -41,7 +41,7 @@
|
|||
"workbox-window": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"fs-extra": "^11.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-sitemap",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Simple sitemap generation plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,12 +18,12 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"fs-extra": "^11.1.1",
|
||||
"sitemap": "^7.1.1",
|
||||
"tslib": "^2.6.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-vercel-analytics",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Global vercel analytics plugin for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,11 +18,11 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@vercel/analytics": "^1.1.1",
|
||||
"tslib": "^2.6.0"
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/preset-classic",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Classic preset for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -18,19 +18,19 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/plugin-content-blog": "3.2.1",
|
||||
"@docusaurus/plugin-content-docs": "3.2.1",
|
||||
"@docusaurus/plugin-content-pages": "3.2.1",
|
||||
"@docusaurus/plugin-debug": "3.2.1",
|
||||
"@docusaurus/plugin-google-analytics": "3.2.1",
|
||||
"@docusaurus/plugin-google-gtag": "3.2.1",
|
||||
"@docusaurus/plugin-google-tag-manager": "3.2.1",
|
||||
"@docusaurus/plugin-sitemap": "3.2.1",
|
||||
"@docusaurus/theme-classic": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/theme-search-algolia": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1"
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/plugin-content-blog": "3.3.2",
|
||||
"@docusaurus/plugin-content-docs": "3.3.2",
|
||||
"@docusaurus/plugin-content-pages": "3.3.2",
|
||||
"@docusaurus/plugin-debug": "3.3.2",
|
||||
"@docusaurus/plugin-google-analytics": "3.3.2",
|
||||
"@docusaurus/plugin-google-gtag": "3.3.2",
|
||||
"@docusaurus/plugin-google-tag-manager": "3.3.2",
|
||||
"@docusaurus/plugin-sitemap": "3.3.2",
|
||||
"@docusaurus/theme-classic": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/theme-search-algolia": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18.0.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/remark-plugin-npm2yarn",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Remark plugin for converting npm commands to Yarn commands as tabs.",
|
||||
"main": "lib/index.js",
|
||||
"publishConfig": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/theme-classic",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Classic theme for Docusaurus",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/theme-classic.d.ts",
|
||||
|
@ -20,18 +20,18 @@
|
|||
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/mdx-loader": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/plugin-content-blog": "3.2.1",
|
||||
"@docusaurus/plugin-content-docs": "3.2.1",
|
||||
"@docusaurus/plugin-content-pages": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/theme-translations": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/mdx-loader": "3.3.2",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/plugin-content-blog": "3.3.2",
|
||||
"@docusaurus/plugin-content-docs": "3.3.2",
|
||||
"@docusaurus/plugin-content-pages": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/theme-translations": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@mdx-js/react": "^3.0.0",
|
||||
"clsx": "^2.0.0",
|
||||
"copy-text-to-clipboard": "^3.2.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/theme-common",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Common code for Docusaurus themes.",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
@ -30,13 +30,13 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/mdx-loader": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/plugin-content-blog": "3.2.1",
|
||||
"@docusaurus/plugin-content-docs": "3.2.1",
|
||||
"@docusaurus/plugin-content-pages": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/mdx-loader": "3.3.2",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/plugin-content-blog": "3.3.2",
|
||||
"@docusaurus/plugin-content-docs": "3.3.2",
|
||||
"@docusaurus/plugin-content-pages": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@types/history": "^4.7.11",
|
||||
"@types/react": "*",
|
||||
"@types/react-router-config": "*",
|
||||
|
@ -47,8 +47,8 @@
|
|||
"utility-types": "^3.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"fs-extra": "^11.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"schema-dts": "^1.1.2"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/theme-live-codeblock",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus live code block component.",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/theme-live-codeblock.d.ts",
|
||||
|
@ -23,10 +23,10 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/theme-translations": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/theme-translations": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"@philpl/buble": "^0.19.7",
|
||||
"clsx": "^2.0.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
|
@ -34,7 +34,7 @@
|
|||
"tslib": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@types/buble": "^0.20.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/theme-mermaid",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Mermaid components for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/theme-mermaid.d.ts",
|
||||
|
@ -33,11 +33,11 @@
|
|||
"copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"mermaid": "^10.4.0",
|
||||
"tslib": "^2.6.0"
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/theme-search-algolia",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Algolia search component for Docusaurus.",
|
||||
"main": "lib/index.js",
|
||||
"sideEffects": [
|
||||
|
@ -34,13 +34,13 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@docsearch/react": "^3.5.2",
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/plugin-content-docs": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/theme-translations": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/plugin-content-docs": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/theme-translations": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"algoliasearch": "^4.18.0",
|
||||
"algoliasearch-helper": "^3.13.3",
|
||||
"clsx": "^2.0.0",
|
||||
|
@ -51,7 +51,7 @@
|
|||
"utility-types": "^3.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.2.1"
|
||||
"@docusaurus/module-type-aliases": "3.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18.0.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/theme-translations",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus theme translations.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -23,8 +23,8 @@
|
|||
"tslib": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/tsconfig",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Docusaurus base TypeScript configuration.",
|
||||
"main": "tsconfig.json",
|
||||
"publishConfig": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/types",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Common types for Docusaurus packages.",
|
||||
"types": "./src/index.d.ts",
|
||||
"publishConfig": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/utils-common",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Common (Node/Browser) utility functions for Docusaurus packages.",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/utils-validation",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Node validation utility functions for Docusaurus packages.",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
@ -18,9 +18,9 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"joi": "^17.9.2",
|
||||
"js-yaml": "^4.1.0",
|
||||
"tslib": "^2.6.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/utils",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Node utility functions for Docusaurus packages.",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
|
@ -18,8 +18,8 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@svgr/webpack": "^8.1.0",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"file-loader": "^6.2.0",
|
||||
|
@ -42,7 +42,7 @@
|
|||
"node": ">=18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@types/dedent": "^0.7.0",
|
||||
"@types/github-slugger": "^1.3.0",
|
||||
"@types/micromatch": "^4.0.2",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@docusaurus/core",
|
||||
"description": "Easy to Maintain Open Source Documentation Websites",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@ -43,12 +43,12 @@
|
|||
"@babel/runtime": "^7.22.6",
|
||||
"@babel/runtime-corejs3": "^7.22.6",
|
||||
"@babel/traverse": "^7.22.8",
|
||||
"@docusaurus/cssnano-preset": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/mdx-loader": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/utils-validation": "3.2.1",
|
||||
"@docusaurus/cssnano-preset": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/mdx-loader": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@docusaurus/utils-validation": "3.3.2",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"babel-loader": "^9.1.3",
|
||||
"babel-plugin-dynamic-import-node": "^2.3.3",
|
||||
|
@ -103,8 +103,8 @@
|
|||
"webpackbar": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.2.1",
|
||||
"@docusaurus/types": "3.2.1",
|
||||
"@docusaurus/module-type-aliases": "3.3.2",
|
||||
"@docusaurus/types": "3.3.2",
|
||||
"@total-typescript/shoehorn": "^0.1.2",
|
||||
"@types/detect-port": "^1.3.3",
|
||||
"@types/react-dom": "^18.2.7",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/eslint-plugin",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "ESLint plugin to enforce best Docusaurus practices.",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@docusaurus/lqip-loader",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Low Quality Image Placeholders (LQIP) loader for webpack.",
|
||||
"main": "lib/index.js",
|
||||
"publishConfig": {
|
||||
|
@ -17,7 +17,7 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"file-loader": "^6.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"sharp": "^0.32.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "stylelint-copyright",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"description": "Stylelint plugin to check CSS files for a copyright header.",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
|
|
BIN
website/blog/releases/3.3/img/social-card.png
Normal file
BIN
website/blog/releases/3.3/img/social-card.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 187 KiB |
110
website/blog/releases/3.3/index.mdx
Normal file
110
website/blog/releases/3.3/index.mdx
Normal file
|
@ -0,0 +1,110 @@
|
|||
---
|
||||
title: Docusaurus 3.3
|
||||
authors: [slorber]
|
||||
tags: [release]
|
||||
image: ./img/social-card.png
|
||||
date: 2024-05-03
|
||||
---
|
||||
|
||||
We are happy to announce **Docusaurus 3.3**.
|
||||
|
||||
Upgrading should be easy. Our [release process](/community/release-process) respects [Semantic Versioning](https://semver.org/). Minor versions do not include any breaking changes.
|
||||
|
||||

|
||||
|
||||
<!--truncate-->
|
||||
|
||||
import BrowserWindow from '@site/src/components/BrowserWindow';
|
||||
import IframeWindow from '@site/src/components/BrowserWindow/IframeWindow';
|
||||
|
||||
## Highlights
|
||||
|
||||
### Prepare for React 19
|
||||
|
||||
The React core team recently [released the first **React 19 beta**](https://react.dev/blog/2024/04/25/react-19). They also [published an upgrade guide and a ** React v18.3 release**](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) with new warnings to help us identify issues **before upgrading to React 19**.
|
||||
|
||||
Docusaurus v3 depends on React `18.x`. When initializing a new Docusaurus sites, it will use that new React `18.3` release. It's also the case if you decide to upgrade your dependencies, or re-generate your package manager lockfile.
|
||||
|
||||
It turns out in its current state, **Docusaurus had a few of those extra warnings to fix**, notably this one immediately appearing on your dev console on any page load and navigation:
|
||||
|
||||
> Warning: LoadableComponent uses the legacy contextTypes API which is no longer supported and will be removed in the next major release. Use React.createContext() with static contextType instead.
|
||||
|
||||
In [#10079](https://github.com/facebook/docusaurus/pull/10079), we got Docusaurus ready for React 19. We fixed all the React 18.3 warnings we encountered. In case we missed any, don't hesitate to [**report new warnings**](https://github.com/facebook/docusaurus/issues/10099) if you see them, to us but also to other Docusaurus third-party plugin authors.
|
||||
|
||||
### `createSitemapItems`
|
||||
|
||||
In [#10083](https://github.com/facebook/docusaurus/pull/10083), we introduced a new flexible `createSitemapItems()` hook to the sitemap plugin. This enables users to create/filter/transform/enhance the sitemap items with their own custom logic.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
sitemap: {
|
||||
// highlight-start
|
||||
createSitemapItems: async ({
|
||||
defaultCreateSitemapItems,
|
||||
...params
|
||||
}) => {
|
||||
const items = await defaultCreateSitemapItems(params);
|
||||
return items.filter((item) => !item.url.includes('/tags/'));
|
||||
},
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### Pages plugin improvements
|
||||
|
||||
The Docusaurus [pages plugin](/docs/api/plugins/@docusaurus/plugin-content-pages) has historically been lagging behind the docs and blog plugins in terms of available feature.
|
||||
|
||||
In [#10032](https://github.com/facebook/docusaurus/pull/10032) we normalized the options available on each core content plugins by adding a few the missing page plugins APIs related to the edit url and the last update metadata displayed at the bottom on Markdown pages.
|
||||
|
||||
```js
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
pages: {
|
||||
// highlight-start
|
||||
editUrl:
|
||||
'https://github.com/facebook/docusaurus/tree/main/website/src/pages',
|
||||
editLocalizedFiles: true,
|
||||
showLastUpdateAuthor: true,
|
||||
showLastUpdateTime: true,
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
<IframeWindow url="/examples/markdownPageExample" />
|
||||
|
||||
:::note Only for Markdown pages
|
||||
|
||||
These new plugin options only apply to Markdown pages, and have no effect on React pages for which you have full control over the layout with JSX.
|
||||
|
||||
:::
|
||||
|
||||
## Other changes
|
||||
|
||||
Other notable changes include:
|
||||
|
||||
- [#10064](https://github.com/facebook/docusaurus/pull/10064): new site config option `siteConfig.markdown.anchors.maintainCase`
|
||||
- [#9767](https://github.com/facebook/docusaurus/pull/9767): new `docusaurus deploy --target-dir` option
|
||||
- [#10042](https://github.com/facebook/docusaurus/pull/10042): new (experimental) plugin API: `route.props`
|
||||
- [#10060](https://github.com/facebook/docusaurus/pull/10060): optimizes the App entrypoint, avoid useless re-renders on navigations
|
||||
- [#10080](https://github.com/facebook/docusaurus/pull/10080): `<Admonition>` component can render properly without heading/icon
|
||||
- [#10091](https://github.com/facebook/docusaurus/pull/10091): `<Tabs>` props can now override defaults
|
||||
- [#10090](https://github.com/facebook/docusaurus/pull/10090): `docusaurus serve` works better with a `/baseUrl/` pathname prefix
|
||||
- [#10070](https://github.com/facebook/docusaurus/pull/10070): add missing theme translations for `pt-BR`
|
||||
- [#10025](https://github.com/facebook/docusaurus/pull/10025): doc sidebar item label now impacts the doc pagination label
|
||||
|
||||
Check the **[3.3.0 changelog entry](/changelog/3.3.0)** for an exhaustive list of changes.
|
|
@ -39,15 +39,37 @@ const ArchivedVersionsDropdownItems = Object.entries(VersionsArchived).splice(
|
|||
|
||||
function isPrerelease(version: string) {
|
||||
return (
|
||||
version.includes('-') ||
|
||||
version.includes('alpha') ||
|
||||
version.includes('beta') ||
|
||||
version.includes('rc')
|
||||
);
|
||||
}
|
||||
|
||||
function getLastVersion() {
|
||||
const firstStableVersion = versions.find((version) => !isPrerelease(version));
|
||||
return firstStableVersion ?? versions[0];
|
||||
function getLastStableVersion() {
|
||||
const lastStableVersion = versions.find((version) => !isPrerelease(version));
|
||||
if (!lastStableVersion) {
|
||||
throw new Error('unexpected, no stable Docusaurus version?');
|
||||
}
|
||||
return lastStableVersion;
|
||||
}
|
||||
const announcedVersion = getAnnouncedVersion();
|
||||
|
||||
function getLastStableVersionTuple(): [string, string, string] {
|
||||
const lastStableVersion = getLastStableVersion();
|
||||
const parts = lastStableVersion.split('.');
|
||||
if (parts.length !== 3) {
|
||||
throw new Error(`Unexpected stable version name: ${lastStableVersion}`);
|
||||
}
|
||||
return [parts[0]!, parts[1]!, parts[2]!];
|
||||
}
|
||||
|
||||
// The version announced on the homepage hero and announcement banner
|
||||
// 3.3.2 => 3.3
|
||||
// 3.0.5 => 3.0
|
||||
function getAnnouncedVersion() {
|
||||
const [major, minor] = getLastStableVersionTuple();
|
||||
return `${major}.${minor}`;
|
||||
}
|
||||
|
||||
// This probably only makes sense for the alpha/beta/rc phase, temporary
|
||||
|
@ -228,6 +250,7 @@ export default async function createConfigAsync() {
|
|||
isDeployPreview,
|
||||
description:
|
||||
'An optimized site generator in React. Docusaurus helps you to move fast and write content. Build documentation websites, blogs, marketing pages, and more.',
|
||||
announcedVersion,
|
||||
},
|
||||
staticDirectories: [
|
||||
'static',
|
||||
|
@ -420,7 +443,7 @@ export default async function createConfigAsync() {
|
|||
isBranchDeploy ||
|
||||
isBuildFast
|
||||
? 'current'
|
||||
: getLastVersion(),
|
||||
: getLastStableVersion(),
|
||||
|
||||
onlyIncludeVersions: (() => {
|
||||
if (isBuildFast) {
|
||||
|
@ -511,9 +534,9 @@ export default async function createConfigAsync() {
|
|||
respectPrefersColorScheme: true,
|
||||
},
|
||||
announcementBar: {
|
||||
id: 'announcementBar-v3.2', // Increment on change
|
||||
id: `announcementBar-v${announcedVersion}`,
|
||||
// content: `⭐️ If you like Docusaurus, give it a star on <a target="_blank" rel="noopener noreferrer" href="https://github.com/facebook/docusaurus">GitHub</a> and follow us on <a target="_blank" rel="noopener noreferrer" href="https://twitter.com/docusaurus">Twitter ${TwitterSvg}</a>`,
|
||||
content: `🎉️ <b><a target="_blank" href="https://docusaurus.io/blog/releases/3.2">Docusaurus v3.2</a> is out!</b> 🥳️`,
|
||||
content: `🎉️ <b><a target="_blank" href="https://docusaurus.io/blog/releases/${announcedVersion}">Docusaurus v${announcedVersion}</a> is out!</b> 🥳️`,
|
||||
},
|
||||
prism: {
|
||||
additionalLanguages: [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "website",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
@ -36,19 +36,19 @@
|
|||
"dependencies": {
|
||||
"@crowdin/cli": "^3.13.0",
|
||||
"@crowdin/crowdin-api-client": "^1.29.5",
|
||||
"@docusaurus/core": "3.2.1",
|
||||
"@docusaurus/logger": "3.2.1",
|
||||
"@docusaurus/plugin-client-redirects": "3.2.1",
|
||||
"@docusaurus/plugin-ideal-image": "3.2.1",
|
||||
"@docusaurus/plugin-pwa": "3.2.1",
|
||||
"@docusaurus/preset-classic": "3.2.1",
|
||||
"@docusaurus/remark-plugin-npm2yarn": "3.2.1",
|
||||
"@docusaurus/theme-classic": "3.2.1",
|
||||
"@docusaurus/theme-common": "3.2.1",
|
||||
"@docusaurus/theme-live-codeblock": "3.2.1",
|
||||
"@docusaurus/theme-mermaid": "3.2.1",
|
||||
"@docusaurus/utils": "3.2.1",
|
||||
"@docusaurus/utils-common": "3.2.1",
|
||||
"@docusaurus/core": "3.3.2",
|
||||
"@docusaurus/logger": "3.3.2",
|
||||
"@docusaurus/plugin-client-redirects": "3.3.2",
|
||||
"@docusaurus/plugin-ideal-image": "3.3.2",
|
||||
"@docusaurus/plugin-pwa": "3.3.2",
|
||||
"@docusaurus/preset-classic": "3.3.2",
|
||||
"@docusaurus/remark-plugin-npm2yarn": "3.3.2",
|
||||
"@docusaurus/theme-classic": "3.3.2",
|
||||
"@docusaurus/theme-common": "3.3.2",
|
||||
"@docusaurus/theme-live-codeblock": "3.3.2",
|
||||
"@docusaurus/theme-mermaid": "3.3.2",
|
||||
"@docusaurus/utils": "3.3.2",
|
||||
"@docusaurus/utils-common": "3.3.2",
|
||||
"@swc/core": "1.2.197",
|
||||
"clsx": "^2.0.0",
|
||||
"color": "^4.2.3",
|
||||
|
@ -81,8 +81,8 @@
|
|||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/eslint-plugin": "3.2.1",
|
||||
"@docusaurus/tsconfig": "3.2.1",
|
||||
"@docusaurus/eslint-plugin": "3.3.2",
|
||||
"@docusaurus/tsconfig": "3.3.2",
|
||||
"@types/color": "^3.0.4",
|
||||
"@types/jest": "^29.5.3",
|
||||
"cross-env": "^7.0.3",
|
||||
|
|
|
@ -203,29 +203,21 @@ function FeaturesContainer() {
|
|||
}
|
||||
|
||||
function TopBanner() {
|
||||
/* TODO restore Ukraine banner after launch
|
||||
<Translate
|
||||
id="homepage.banner"
|
||||
values={{
|
||||
link: (
|
||||
<Link to="https://opensource.facebook.com/support-ukraine">
|
||||
<Translate id="homepage.banner.link">
|
||||
Help Provide Humanitarian Aid to Ukraine
|
||||
</Translate>
|
||||
</Link>
|
||||
),
|
||||
}}>
|
||||
{'Support Ukraine 🇺🇦 {link}.'}
|
||||
</Translate>
|
||||
*/
|
||||
// TODO We should be able to strongly type customFields
|
||||
// Refactor to use a CustomFields interface + TS declaration merging
|
||||
const announcedVersion = useDocusaurusContext().siteConfig.customFields
|
||||
?.announcedVersion as string;
|
||||
|
||||
return (
|
||||
<div className={styles.topBanner}>
|
||||
<div className={styles.topBannerTitle}>
|
||||
{'🎉\xa0'}
|
||||
<Link to="/blog/releases/3.2" className={styles.topBannerTitleText}>
|
||||
<Link
|
||||
to={`/blog/releases/${announcedVersion}`}
|
||||
className={styles.topBannerTitleText}>
|
||||
<Translate
|
||||
id="homepage.banner.launch.newVersion"
|
||||
values={{newVersion: '3.2'}}>
|
||||
values={{newVersion: announcedVersion}}>
|
||||
{'Docusaurus\xa0{newVersion} is\xa0out!️'}
|
||||
</Translate>
|
||||
</Link>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
description: How Docusaurus works to build your app
|
||||
---
|
||||
|
||||
# Architecture
|
||||
|
||||
```mdx-code-block
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
import Zoom from 'react-medium-image-zoom';
|
||||
```
|
||||
|
||||
<Zoom>
|
||||
|
||||

|
||||
|
||||
</Zoom>
|
||||
|
||||
This diagram shows how Docusaurus works to build your app. Plugins each collect their content and emit JSON data; themes provide layout components which receive the JSON data as route modules. The bundler bundles all the components and emits a server bundle and a client bundle.
|
||||
|
||||
Although you (either plugin authors or site creators) are writing JavaScript all the time, bear in mind that the JS is actually run in different environments:
|
||||
|
||||
- All plugin lifecycle methods are run in Node. Therefore, until we support ES Modules in our codebase, plugin source code must be provided as ES modules that can be imported, or CommonJS that can be `require`'d.
|
||||
- The theme code is built with Webpack. They can be provided as ESM—following React conventions.
|
||||
|
||||
Plugin code and theme code never directly import each other: they only communicate through protocols (in our case, through JSON temp files and calls to `addRoute`). A useful mental model is to imagine that the plugins are not written in JavaScript, but in another language like Rust. The only way to interact with plugins for the user is through `docusaurus.config.js`, which itself is run in Node (hence you can use `require` and pass callbacks as plugin options).
|
||||
|
||||
During bundling, the config file itself is serialized and bundled, allowing the theme to access config options like `themeConfig` or `baseUrl` through [`useDocusaurusContext()`](../docusaurus-core.mdx#useDocusaurusContext). However, the `siteConfig` object only contains **serializable values** (values that are preserved after `JSON.stringify()`). Functions, regexes, etc. would be lost on the client side. The `themeConfig` is designed to be entirely serializable.
|
184
website/versioned_docs/version-3.3.2/advanced/client.mdx
Normal file
184
website/versioned_docs/version-3.3.2/advanced/client.mdx
Normal file
|
@ -0,0 +1,184 @@
|
|||
---
|
||||
description: How the Docusaurus client is structured
|
||||
---
|
||||
|
||||
# Client architecture
|
||||
|
||||
## Theme aliases {#theme-aliases}
|
||||
|
||||
A theme works by exporting a set of components, e.g. `Navbar`, `Layout`, `Footer`, to render the data passed down from plugins. Docusaurus and users use these components by importing them using the `@theme` webpack alias:
|
||||
|
||||
```js
|
||||
import Navbar from '@theme/Navbar';
|
||||
```
|
||||
|
||||
The alias `@theme` can refer to a few directories, in the following priority:
|
||||
|
||||
1. A user's `website/src/theme` directory, which is a special directory that has the higher precedence.
|
||||
2. A Docusaurus theme package's `theme` directory.
|
||||
3. Fallback components provided by Docusaurus core (usually not needed).
|
||||
|
||||
This is called a _layered architecture_: a higher-priority layer providing the component would shadow a lower-priority layer, making swizzling possible. Given the following structure:
|
||||
|
||||
```
|
||||
website
|
||||
├── node_modules
|
||||
│ └── @docusaurus/theme-classic
|
||||
│ └── theme
|
||||
│ └── Navbar.js
|
||||
└── src
|
||||
└── theme
|
||||
└── Navbar.js
|
||||
```
|
||||
|
||||
`website/src/theme/Navbar.js` takes precedence whenever `@theme/Navbar` is imported. This behavior is called component swizzling. If you are familiar with Objective C where a function's implementation can be swapped during runtime, it's the exact same concept here with changing the target `@theme/Navbar` is pointing to!
|
||||
|
||||
We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](../swizzling.mdx#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import.
|
||||
|
||||
Here's an example of using this feature to enhance the default theme `CodeBlock` component with a `react-live` playground feature.
|
||||
|
||||
```js
|
||||
import InitialCodeBlock from '@theme-init/CodeBlock';
|
||||
import React from 'react';
|
||||
|
||||
export default function CodeBlock(props) {
|
||||
return props.live ? (
|
||||
<ReactLivePlayground {...props} />
|
||||
) : (
|
||||
<InitialCodeBlock {...props} />
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Check the code of `@docusaurus/theme-live-codeblock` for details.
|
||||
|
||||
:::warning
|
||||
|
||||
Unless you want to publish a re-usable "theme enhancer" (like `@docusaurus/theme-live-codeblock`), you likely don't need `@theme-init`.
|
||||
|
||||
:::
|
||||
|
||||
It can be quite hard to wrap your mind around these aliases. Let's imagine the following case with a super convoluted setup with three themes/plugins and the site itself all trying to define the same component. Internally, Docusaurus loads these themes as a "stack".
|
||||
|
||||
```text
|
||||
+-------------------------------------------------+
|
||||
| `website/src/theme/CodeBlock.js` | <-- `@theme/CodeBlock` always points to the top
|
||||
+-------------------------------------------------+
|
||||
| `theme-live-codeblock/theme/CodeBlock/index.js` | <-- `@theme-original/CodeBlock` points to the topmost non-swizzled component
|
||||
+-------------------------------------------------+
|
||||
| `plugin-awesome-codeblock/theme/CodeBlock.js` |
|
||||
+-------------------------------------------------+
|
||||
| `theme-classic/theme/CodeBlock/index.js` | <-- `@theme-init/CodeBlock` always points to the bottom
|
||||
+-------------------------------------------------+
|
||||
```
|
||||
|
||||
The components in this "stack" are pushed in the order of `preset plugins > preset themes > plugins > themes > site`, so the swizzled component in `website/src/theme` always comes out on top because it's loaded last.
|
||||
|
||||
`@theme/*` always points to the topmost component—when `CodeBlock` is swizzled, all other components requesting `@theme/CodeBlock` receive the swizzled version.
|
||||
|
||||
`@theme-original/*` always points to the topmost non-swizzled component. That's why you can import `@theme-original/CodeBlock` in the swizzled component—it points to the next one in the "component stack", a theme-provided one. Plugin authors should not try to use this because your component could be the topmost component and cause a self-import.
|
||||
|
||||
`@theme-init/*` always points to the bottommost component—usually, this comes from the theme or plugin that first provides this component. Individual plugins / themes trying to enhance code block can safely use `@theme-init/CodeBlock` to get its basic version. Site creators should generally not use this because you likely want to enhance the _topmost_ instead of the _bottommost_ component. It's also possible that the `@theme-init/CodeBlock` alias does not exist at all—Docusaurus only creates it when it points to a different one from `@theme-original/CodeBlock`, i.e. when it's provided by more than one theme. We don't waste aliases!
|
||||
|
||||
## Client modules {#client-modules}
|
||||
|
||||
Client modules are part of your site's bundle, just like theme components. However, they are usually side-effect-ful. Client modules are anything that can be `import`ed by Webpack—CSS, JS, etc. JS scripts usually work on the global context, like registering event listeners, creating global variables...
|
||||
|
||||
These modules are imported globally before React even renders the initial UI.
|
||||
|
||||
```js title="@docusaurus/core/App.tsx"
|
||||
// How it works under the hood
|
||||
import '@generated/client-modules';
|
||||
```
|
||||
|
||||
Plugins and sites can both declare client modules, through [`getClientModules`](../api/plugin-methods/lifecycle-apis.mdx#getClientModules) and [`siteConfig.clientModules`](../api/docusaurus.config.js.mdx#clientModules), respectively.
|
||||
|
||||
Client modules are called during server-side rendering as well, so remember to check the [execution environment](./ssg.mdx#escape-hatches) before accessing client-side globals.
|
||||
|
||||
```js title="mySiteGlobalJs.js"
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
// As soon as the site loads in the browser, register a global event listener
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.code === 'Period') {
|
||||
location.assign(location.href.replace('.com', '.dev'));
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
CSS stylesheets imported as client modules are [global](../styling-layout.mdx#global-styles).
|
||||
|
||||
```css title="mySiteGlobalCss.css"
|
||||
/* This stylesheet is global. */
|
||||
.globalSelector {
|
||||
color: red;
|
||||
}
|
||||
```
|
||||
|
||||
### Client module lifecycles {#client-module-lifecycles}
|
||||
|
||||
Besides introducing side-effects, client modules can optionally export two lifecycle functions: `onRouteUpdate` and `onRouteDidUpdate`.
|
||||
|
||||
Because Docusaurus builds a single-page application, `script` tags will only be executed the first time the page loads, but will not re-execute on page transitions. These lifecycles are useful if you have some imperative JS logic that should execute every time a new page has loaded, e.g., to manipulate DOM elements, to send analytics data, etc.
|
||||
|
||||
For every route transition, there will be several important timings:
|
||||
|
||||
1. The user clicks a link, which causes the router to change its current location.
|
||||
2. Docusaurus preloads the next route's assets, while keeping displaying the current page's content.
|
||||
3. The next route's assets have loaded.
|
||||
4. The new location's route component gets rendered to DOM.
|
||||
|
||||
`onRouteUpdate` will be called at event (2), and `onRouteDidUpdate` will be called at (4). They both receive the current location and the previous location (which can be `null`, if this is the first screen).
|
||||
|
||||
`onRouteUpdate` can optionally return a "cleanup" callback, which will be called at (3). For example, if you want to display a progress bar, you can start a timeout in `onRouteUpdate`, and clear the timeout in the callback. (The classic theme already provides an `nprogress` integration this way.)
|
||||
|
||||
Note that the new page's DOM is only available during event (4). If you need to manipulate the new page's DOM, you'll likely want to use `onRouteDidUpdate`, which will be fired as soon as the DOM on the new page has mounted.
|
||||
|
||||
```js title="myClientModule.js"
|
||||
export function onRouteDidUpdate({location, previousLocation}) {
|
||||
// Don't execute if we are still on the same page; the lifecycle may be fired
|
||||
// because the hash changes (e.g. when navigating between headings)
|
||||
if (location.pathname !== previousLocation?.pathname) {
|
||||
const title = document.getElementsByTagName('h1')[0];
|
||||
if (title) {
|
||||
title.innerText += '❤️';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function onRouteUpdate({location, previousLocation}) {
|
||||
if (location.pathname !== previousLocation?.pathname) {
|
||||
const progressBarTimeout = window.setTimeout(() => {
|
||||
nprogress.start();
|
||||
}, delay);
|
||||
return () => window.clearTimeout(progressBarTimeout);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
```
|
||||
|
||||
Or, if you are using TypeScript and you want to leverage contextual typing:
|
||||
|
||||
```ts title="myClientModule.ts"
|
||||
import type {ClientModule} from '@docusaurus/types';
|
||||
|
||||
const module: ClientModule = {
|
||||
onRouteUpdate({location, previousLocation}) {
|
||||
// ...
|
||||
},
|
||||
onRouteDidUpdate({location, previousLocation}) {
|
||||
// ...
|
||||
},
|
||||
};
|
||||
export default module;
|
||||
```
|
||||
|
||||
Both lifecycles will fire on first render, but they will not fire on server-side, so you can safely access browser globals in them.
|
||||
|
||||
:::tip Prefer using React
|
||||
|
||||
Client module lifecycles are purely imperative, and you can't use React hooks or access React contexts within them. If your operations are state-driven or involve complicated DOM manipulations, you should consider [swizzling components](../swizzling.mdx) instead.
|
||||
|
||||
:::
|
11
website/versioned_docs/version-3.3.2/advanced/index.mdx
Normal file
11
website/versioned_docs/version-3.3.2/advanced/index.mdx
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Advanced Tutorials
|
||||
|
||||
This section is not going to be very structured, but we will cover the following topics:
|
||||
|
||||
```mdx-code-block
|
||||
import DocCardList from '@theme/DocCardList';
|
||||
|
||||
<DocCardList />
|
||||
```
|
||||
|
||||
We will assume that you have finished the guides, and know the basics like how to configure plugins, how to write React components, etc. These sections will have plugin authors and code contributors in mind, so we may occasionally refer to [plugin APIs](../api/plugin-methods/README.mdx) or other architecture details. Don't panic if you don't understand everything😉
|
129
website/versioned_docs/version-3.3.2/advanced/plugins.mdx
Normal file
129
website/versioned_docs/version-3.3.2/advanced/plugins.mdx
Normal file
|
@ -0,0 +1,129 @@
|
|||
# Plugins
|
||||
|
||||
Plugins are the building blocks of features in a Docusaurus site. Each plugin handles its own individual feature. Plugins may work and be distributed as part of a bundle via presets.
|
||||
|
||||
## Creating plugins {#creating-plugins}
|
||||
|
||||
A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](../api/plugin-methods/README.mdx).
|
||||
|
||||
### Function definition {#function-definition}
|
||||
|
||||
You can use a plugin as a function directly included in the Docusaurus config file:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
plugins: [
|
||||
// highlight-start
|
||||
async function myPlugin(context, options) {
|
||||
// ...
|
||||
return {
|
||||
name: 'my-plugin',
|
||||
async loadContent() {
|
||||
// ...
|
||||
},
|
||||
async contentLoaded({content, actions}) {
|
||||
// ...
|
||||
},
|
||||
/* other lifecycle API */
|
||||
};
|
||||
},
|
||||
// highlight-end
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### Module definition {#module-definition}
|
||||
|
||||
You can use a plugin as a module path referencing a separate file or npm package:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
plugins: [
|
||||
// without options:
|
||||
'./my-plugin',
|
||||
// or with options:
|
||||
['./my-plugin', options],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
Then in the folder `my-plugin`, you can create an `index.js` such as this:
|
||||
|
||||
```js title="my-plugin/index.js"
|
||||
export default async function myPlugin(context, options) {
|
||||
// ...
|
||||
return {
|
||||
name: 'my-plugin',
|
||||
async loadContent() {
|
||||
/* ... */
|
||||
},
|
||||
async contentLoaded({content, actions}) {
|
||||
/* ... */
|
||||
},
|
||||
/* other lifecycle API */
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
You can view all plugins installed in your site using the [debug plugin's metadata panel](/__docusaurus/debug/metadata).
|
||||
|
||||
Plugins come as several types:
|
||||
|
||||
- `package`: an external package you installed
|
||||
- `project`: a plugin you created in your project, given to Docusaurus as a local file path
|
||||
- `local`: a plugin created using the function definition
|
||||
- `synthetic`: a "fake plugin" Docusaurus created internally, so we take advantage of our modular architecture and don't let the core do much special work. You won't see this in the metadata because it's an implementation detail.
|
||||
|
||||
You can access them on the client side with `useDocusaurusContext().siteMetadata.pluginVersions`.
|
||||
|
||||
## Plugin design {#plugin-design}
|
||||
|
||||
Docusaurus' implementation of the plugins system provides us with a convenient way to hook into the website's lifecycle to modify what goes on during development/build, which involves (but is not limited to) extending the webpack config, modifying the data loaded, and creating new components to be used in a page.
|
||||
|
||||
### Theme design {#theme-design}
|
||||
|
||||
When plugins have loaded their content, the data is made available to the client side through actions like [`createData` + `addRoute`](../api/plugin-methods/lifecycle-apis.mdx#addRoute) or [`setGlobalData`](../api/plugin-methods/lifecycle-apis.mdx#setGlobalData). This data has to be _serialized_ to plain strings, because [plugins and themes run in different environments](./architecture.mdx). Once the data arrives on the client side, the rest becomes familiar to React developers: data is passed along components, components are bundled with Webpack, and rendered to the window through `ReactDOM.render`...
|
||||
|
||||
**Themes provide the set of UI components to render the content.** Most content plugins need to be paired with a theme in order to be actually useful. The UI is a separate layer from the data schema, which makes swapping designs easy.
|
||||
|
||||
For example, a Docusaurus blog may consist of a blog plugin and a blog theme.
|
||||
|
||||
:::note
|
||||
|
||||
This is a contrived example: in practice, `@docusaurus/theme-classic` provides the theme for docs, blog, and layouts.
|
||||
|
||||
:::
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// highlight-next-line
|
||||
themes: ['theme-blog'],
|
||||
plugins: ['plugin-content-blog'],
|
||||
};
|
||||
```
|
||||
|
||||
And if you want to use Bootstrap styling, you can swap out the theme with `theme-blog-bootstrap` (another fictitious non-existing theme):
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// highlight-next-line
|
||||
themes: ['theme-blog-bootstrap'],
|
||||
plugins: ['plugin-content-blog'],
|
||||
};
|
||||
```
|
||||
|
||||
Now, although the theme receives the same data from the plugin, how the theme chooses to _render_ the data as UI can be drastically different.
|
||||
|
||||
While themes share the exact same lifecycle methods with plugins, themes' implementations can look very different from those of plugins based on themes' designed objectives.
|
||||
|
||||
Themes are designed to complete the build of your Docusaurus site and supply the components used by your site, plugins, and the themes themselves. A theme still acts like a plugin and exposes some lifecycle methods, but most likely they would not use [`loadContent`](../api/plugin-methods/lifecycle-apis.mdx#loadContent), since they only receive data from plugins, but don't generate data themselves; themes are typically also accompanied by an `src/theme` directory full of components, which are made known to the core through the [`getThemePath`](../api/plugin-methods/extend-infrastructure.mdx#getThemePath) lifecycle.
|
||||
|
||||
To summarize:
|
||||
|
||||
- Themes share the same lifecycle methods with Plugins
|
||||
- Themes are run after all existing Plugins
|
||||
- Themes add component aliases by providing `getThemePath`.
|
289
website/versioned_docs/version-3.3.2/advanced/routing.mdx
Normal file
289
website/versioned_docs/version-3.3.2/advanced/routing.mdx
Normal file
|
@ -0,0 +1,289 @@
|
|||
---
|
||||
description: "Docusaurus' routing system follows single-page application conventions: one route, one component."
|
||||
---
|
||||
|
||||
# Routing
|
||||
|
||||
```mdx-code-block
|
||||
import Link from '@docusaurus/Link';
|
||||
import {useLatestVersion, useActiveDocContext} from '@docusaurus/plugin-content-docs/client';
|
||||
import {useLocation} from '@docusaurus/router';
|
||||
import BrowserWindow from '@site/src/components/BrowserWindow';
|
||||
```
|
||||
|
||||
Docusaurus' routing system follows single-page application conventions: one route, one component. In this section, we will begin by talking about routing within the three content plugins (docs, blog, and pages), and then go beyond to talk about the underlying routing system.
|
||||
|
||||
## Routing in content plugins {#routing-in-content-plugins}
|
||||
|
||||
Every content plugin provides a `routeBasePath` option. It defines where the plugins append their routes to. By default, the docs plugin puts its routes under `/docs`; the blog plugin, `/blog`; and the pages plugin, `/`. You can think about the route structure like this:
|
||||
|
||||
```mermaid
|
||||
graph LR;
|
||||
A(["https://example.com/"])
|
||||
B(["/base-url/"])
|
||||
C(["/docs/"])
|
||||
D(["/blog/"])
|
||||
E(["/"])
|
||||
F["All docs <br/>routes"]
|
||||
G["All blog <br/>routes"]
|
||||
H["All pages <br/>routes"]
|
||||
A---B;
|
||||
B---C;
|
||||
B---D;
|
||||
B---E;
|
||||
C---F;
|
||||
D---G;
|
||||
E---H;
|
||||
```
|
||||
|
||||
Any route will be matched against this nested route config until a good match is found. For example, when given a route `/docs/configuration`, Docusaurus first enters the `/docs` branch, and then searches among the subroutes created by the docs plugin.
|
||||
|
||||
Changing `routeBasePath` can effectively alter your site's route structure. For example, in [Docs-only mode](../guides/docs/docs-introduction.mdx#docs-only-mode), we mentioned that configuring `routeBasePath: '/'` for docs means that all routes that the docs plugin create would not have the `/docs` prefix, yet it doesn't prevent you from having more subroutes like `/blog` created by other plugins.
|
||||
|
||||
Next, let's look at how the three plugins structure their own "boxes of subroutes".
|
||||
|
||||
### Pages routing {#pages-routing}
|
||||
|
||||
Pages routing are straightforward: the file paths directly map to URLs, without any other way to customize. See the [pages docs](../guides/creating-pages.mdx#routing) for more information.
|
||||
|
||||
The component used for Markdown pages is `@theme/MDXPage`. React pages are directly used as the route's component.
|
||||
|
||||
### Blog routing {#blog-routing}
|
||||
|
||||
The blog creates the following routes:
|
||||
|
||||
- **Posts list pages**: `/`, `/page/2`, `/page/3`...
|
||||
- The route is customizable through the `pageBasePath` option.
|
||||
- The component is `@theme/BlogListPage`.
|
||||
- **Post pages**: `/2021/11/21/algolia-docsearch-migration`, `/2021/05/12/announcing-docusaurus-two-beta`...
|
||||
- Generated from each Markdown post.
|
||||
- The routes are fully customizable through the `slug` front matter.
|
||||
- The component is `@theme/BlogPostPage`.
|
||||
- **Tags list page**: `/tags`
|
||||
- The route is customizable through the `tagsBasePath` option.
|
||||
- The component is `@theme/BlogTagsListPage`.
|
||||
- **Tag pages**: `/tags/adoption`, `/tags/beta`...
|
||||
- Generated through the tags defined in each post's front matter.
|
||||
- The routes always have base defined in `tagsBasePath`, but the subroutes are customizable through the tag's `permalink` field.
|
||||
- The component is `@theme/BlogTagsPostsPage`.
|
||||
- **Archive page**: `/archive`
|
||||
- The route is customizable through the `archiveBasePath` option.
|
||||
- The component is `@theme/BlogArchivePage`.
|
||||
|
||||
### Docs routing {#docs-routing}
|
||||
|
||||
The docs is the only plugin that creates **nested routes**. At the top, it registers [**version paths**](../guides/docs/versioning.mdx): `/`, `/next`, `/2.0.0-beta.13`... which provide the version context, including the layout and sidebar. This ensures that when switching between individual docs, the sidebar's state is preserved, and that you can switch between versions through the navbar dropdown while staying on the same doc. The component used is `@theme/DocPage`.
|
||||
|
||||
```mdx-code-block
|
||||
export const URLPath = () => <code>{useLocation().pathname}</code>;
|
||||
|
||||
export const FilePath = () => {
|
||||
const currentVersion = useActiveDocContext('default').activeVersion.name;
|
||||
return <code>{currentVersion === 'current' ? './docs/' : `./versioned_docs/version-${currentVersion}/`}advanced/routing.md</code>;
|
||||
}
|
||||
```
|
||||
|
||||
The individual docs are rendered in the remaining space after the navbar, footer, sidebar, etc. have all been provided by the `DocPage` component. For example, this page, <URLPath />, is generated from the file at <FilePath />. The component used is `@theme/DocItem`.
|
||||
|
||||
The doc's `slug` front matter customizes the last part of the route, but the base route is always defined by the plugin's `routeBasePath` and the version's `path`.
|
||||
|
||||
### File paths and URL paths {#file-paths-and-url-paths}
|
||||
|
||||
Throughout the documentation, we always try to be unambiguous about whether we are talking about file paths or URL paths. Content plugins usually map file paths directly to URL paths, for example, `./docs/advanced/routing.md` will become `/docs/advanced/routing`. However, with `slug`, you can make URLs totally decoupled from the file structure.
|
||||
|
||||
When writing links in Markdown, you could either mean a _file path_, or a _URL path_, which Docusaurus would use several heuristics to determine.
|
||||
|
||||
- If the path has a `@site` prefix, it is _always_ an asset file path.
|
||||
- If the path has an `http(s)://` prefix, it is _always_ a URL path.
|
||||
- If the path doesn't have an extension, it is a URL path. For example, a link `[page](../plugins)` on a page with URL `/docs/advanced/routing` will link to `/docs/plugins`. Docusaurus will only detect broken links when building your site (when it knows the full route structure), but will make no assumptions about the existence of a file. It is exactly equivalent to writing `<a href="../plugins">page</a>` in a JSX file.
|
||||
- If the path has an `.md(x)` extension, Docusaurus would try to resolve that Markdown file to a URL, and replace the file path with a URL path.
|
||||
- If the path has any other extension, Docusaurus would treat it as [an asset](../guides/markdown-features/markdown-features-assets.mdx) and bundle it.
|
||||
|
||||
The following directory structure may help you visualize this file → URL mapping. Assume that there's no slug customization in any page.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>A sample site structure</summary>
|
||||
|
||||
```bash
|
||||
.
|
||||
├── blog # blog plugin has routeBasePath: '/blog'
|
||||
│ ├── 2019-05-28-first-blog-post.md # -> /blog/2019/05/28/first-blog-post
|
||||
│ ├── 2019-05-29-long-blog-post.md # -> /blog/2019/05/29/long-blog-post
|
||||
│ ├── 2021-08-01-mdx-blog-post.mdx # -> /blog/2021/08/01/mdx-blog-post
|
||||
│ └── 2021-08-26-welcome
|
||||
│ ├── docusaurus-plushie-banner.jpeg
|
||||
│ └── index.md # -> /blog/2021/08/26/welcome
|
||||
├── docs # docs plugin has routeBasePath: '/docs'; current version has base path '/'
|
||||
│ ├── intro.md # -> /docs/intro
|
||||
│ ├── tutorial-basics
|
||||
│ │ ├── _category_.json
|
||||
│ │ ├── congratulations.md # -> /docs/tutorial-basics/congratulations
|
||||
│ │ └── markdown-features.mdx # -> /docs/tutorial-basics/markdown-features
|
||||
│ └── tutorial-extras
|
||||
│ ├── _category_.json
|
||||
│ ├── manage-docs-versions.md # -> /docs/tutorial-extras/manage-docs-versions
|
||||
│ └── translate-your-site.md # -> /docs/tutorial-extras/translate-your-site
|
||||
├── src
|
||||
│ └── pages # pages plugin has routeBasePath: '/'
|
||||
│ ├── index.module.css
|
||||
│ ├── index.tsx # -> /
|
||||
│ └── markdown-page.md # -> /markdown-page
|
||||
└── versioned_docs
|
||||
└── version-1.0.0 # version has base path '/1.0.0'
|
||||
├── intro.md # -> /docs/1.0.0/intro
|
||||
├── tutorial-basics
|
||||
│ ├── _category_.json
|
||||
│ ├── congratulations.md # -> /docs/1.0.0/tutorial-basics/congratulations
|
||||
│ └── markdown-features.mdx # -> /docs/1.0.0/tutorial-basics/markdown-features
|
||||
└── tutorial-extras
|
||||
├── _category_.json
|
||||
├── manage-docs-versions.md # -> /docs/1.0.0/tutorial-extras/manage-docs-versions
|
||||
└── translate-your-site.md # -> /docs/1.0.0/tutorial-extras/translate-your-site
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
So much about content plugins. Let's take one step back and talk about how routing works in a Docusaurus app in general.
|
||||
|
||||
## Routes become HTML files {#routes-become-html-files}
|
||||
|
||||
Because Docusaurus is a server-side rendering framework, all routes generated will be server-side rendered into static HTML files. If you are familiar with the behavior of HTTP servers like [Apache2](https://httpd.apache.org/docs/trunk/getting-started.html), you will understand how this is done: when the browser sends a request to the route `/docs/advanced/routing`, the server interprets that as request for the HTML file `/docs/advanced/routing/index.html`, and returns that.
|
||||
|
||||
The `/docs/advanced/routing` route can correspond to either `/docs/advanced/routing/index.html` or `/docs/advanced/routing.html`. Some hosting providers differentiate between them using the presence of a trailing slash, and may or may not tolerate the other. Read more in the [trailing slash guide](https://github.com/slorber/trailing-slash-guide).
|
||||
|
||||
For example, the build output of the directory above is (ignoring other assets and JS bundle):
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Output of the above workspace</summary>
|
||||
|
||||
```bash
|
||||
build
|
||||
├── 404.html # /404/
|
||||
├── blog
|
||||
│ ├── archive
|
||||
│ │ └── index.html # /blog/archive/
|
||||
│ ├── first-blog-post
|
||||
│ │ └── index.html # /blog/first-blog-post/
|
||||
│ ├── index.html # /blog/
|
||||
│ ├── long-blog-post
|
||||
│ │ └── index.html # /blog/long-blog-post/
|
||||
│ ├── mdx-blog-post
|
||||
│ │ └── index.html # /blog/mdx-blog-post/
|
||||
│ ├── tags
|
||||
│ │ ├── docusaurus
|
||||
│ │ │ └── index.html # /blog/tags/docusaurus/
|
||||
│ │ ├── hola
|
||||
│ │ │ └── index.html # /blog/tags/hola/
|
||||
│ │ └── index.html # /blog/tags/
|
||||
│ └── welcome
|
||||
│ └── index.html # /blog/welcome/
|
||||
├── docs
|
||||
│ ├── 1.0.0
|
||||
│ │ ├── intro
|
||||
│ │ │ └── index.html # /docs/1.0.0/intro/
|
||||
│ │ ├── tutorial-basics
|
||||
│ │ │ ├── congratulations
|
||||
│ │ │ │ └── index.html # /docs/1.0.0/tutorial-basics/congratulations/
|
||||
│ │ │ └── markdown-features
|
||||
│ │ │ └── index.html # /docs/1.0.0/tutorial-basics/markdown-features/
|
||||
│ │ └── tutorial-extras
|
||||
│ │ ├── manage-docs-versions
|
||||
│ │ │ └── index.html # /docs/1.0.0/tutorial-extras/manage-docs-versions/
|
||||
│ │ └── translate-your-site
|
||||
│ │ └── index.html # /docs/1.0.0/tutorial-extras/translate-your-site/
|
||||
│ ├── intro
|
||||
│ │ └── index.html # /docs/1.0.0/intro/
|
||||
│ ├── tutorial-basics
|
||||
│ │ ├── congratulations
|
||||
│ │ │ └── index.html # /docs/tutorial-basics/congratulations/
|
||||
│ │ └── markdown-features
|
||||
│ │ └── index.html # /docs/tutorial-basics/markdown-features/
|
||||
│ └── tutorial-extras
|
||||
│ ├── manage-docs-versions
|
||||
│ │ └── index.html # /docs/tutorial-extras/manage-docs-versions/
|
||||
│ └── translate-your-site
|
||||
│ └── index.html # /docs/tutorial-extras/translate-your-site/
|
||||
├── index.html # /
|
||||
└── markdown-page
|
||||
└── index.html # /markdown-page/
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
If `trailingSlash` is set to `false`, the build would emit `intro.html` instead of `intro/index.html`.
|
||||
|
||||
All HTML files will reference its JS assets using absolute URLs, so in order for the correct assets to be located, you have to configure the `baseUrl` field. Note that `baseUrl` doesn't affect the emitted bundle's file structure: the base URL is one level above the Docusaurus routing system. You can see the aggregate of `url` and `baseUrl` as the actual location of your Docusaurus site.
|
||||
|
||||
For example, the emitted HTML would contain links like `<link rel="preload" href="/assets/js/runtime~main.7ed5108a.js" as="script">`. Because absolute URLs are resolved from the host, if the bundle placed under the path `https://example.com/base/`, the link will point to `https://example.com/assets/js/runtime~main.7ed5108a.js`, which is, well, non-existent. By specifying `/base/` as base URL, the link will correctly point to `/base/assets/js/runtime~main.7ed5108a.js`.
|
||||
|
||||
Localized sites have the locale as part of the base URL as well. For example, `https://docusaurus.io/zh-CN/docs/advanced/routing/` has base URL `/zh-CN/`.
|
||||
|
||||
## Generating and accessing routes {#generating-and-accessing-routes}
|
||||
|
||||
The `addRoute` lifecycle action is used to generate routes. It registers a piece of route config to the route tree, giving a route, a component, and props that the component needs. The props and the component are both provided as paths for the bundler to `require`, because as explained in the [architecture overview](architecture.mdx), server and client only communicate through temp files.
|
||||
|
||||
All routes are aggregated in `.docusaurus/routes.js`, which you can view with the debug plugin's [routes panel](/__docusaurus/debug/routes).
|
||||
|
||||
On the client side, we offer `@docusaurus/router` to access the page's route. `@docusaurus/router` is a re-export of the [`react-router-dom`](https://www.npmjs.com/package/react-router-dom/v/5.3.0) package. For example, you can use `useLocation` to get the current page's [location](https://developer.mozilla.org/en-US/docs/Web/API/Location), and `useHistory` to access the [history object](https://developer.mozilla.org/en-US/docs/Web/API/History). (They are not the same as the browser API, although similar in functionality. Refer to the React Router documentation for specific APIs.)
|
||||
|
||||
This API is **SSR safe**, as opposed to the browser-only `window.location`.
|
||||
|
||||
```jsx title="myComponent.js"
|
||||
import React from 'react';
|
||||
import {useLocation} from '@docusaurus/router';
|
||||
|
||||
export function PageRoute() {
|
||||
// React router provides the current component's route, even in SSR
|
||||
const location = useLocation();
|
||||
return (
|
||||
<span>
|
||||
We are currently on <code>{location.pathname}</code>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
export function PageRoute() {
|
||||
const location = useLocation();
|
||||
return (
|
||||
<span>
|
||||
We are currently on <code>{location.pathname}</code>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
<BrowserWindow>
|
||||
|
||||
<PageRoute />
|
||||
|
||||
</BrowserWindow>
|
||||
```
|
||||
|
||||
## Escaping from SPA redirects {#escaping-from-spa-redirects}
|
||||
|
||||
Docusaurus builds a [single-page application](https://developer.mozilla.org/en-US/docs/Glossary/SPA), where route transitions are done through the `history.push()` method of React router. This operation is done on the client side. However, the prerequisite for a route transition to happen this way is that the target URL is known to our router. Otherwise, the router catches this path and displays a 404 page instead.
|
||||
|
||||
If you put some HTML pages under the `static` folder, they will be copied to the build output and therefore become accessible as part of your website, yet it's not part of the Docusaurus route system. We provide a `pathname://` protocol that allows you to redirect to another part of your domain in a non-SPA fashion, as if this route is an external link.
|
||||
|
||||
```md
|
||||
- [pathname:///pure-html](pathname:///pure-html)
|
||||
```
|
||||
|
||||
<BrowserWindow>
|
||||
|
||||
- [`pathname:///pure-html`](pathname:///pure-html)
|
||||
|
||||
</BrowserWindow>
|
||||
|
||||
The `pathname://` protocol is useful for referencing any content in the static folder. For example, Docusaurus would convert [all Markdown static assets to require() calls](../guides/markdown-features/markdown-features-assets.mdx#static-assets). You can use `pathname://` to keep it a regular link instead of being hashed by Webpack.
|
||||
|
||||
```md title="my-doc.md"
|
||||

|
||||
|
||||
[An asset from the static](pathname:///files/asset.pdf)
|
||||
```
|
||||
|
||||
Docusaurus will only strip the `pathname://` prefix without processing the content.
|
218
website/versioned_docs/version-3.3.2/advanced/ssg.mdx
Normal file
218
website/versioned_docs/version-3.3.2/advanced/ssg.mdx
Normal file
|
@ -0,0 +1,218 @@
|
|||
---
|
||||
sidebar_label: Static site generation
|
||||
description: Docusaurus statically renders your React code into HTML, allowing faster load speed and better SEO.
|
||||
---
|
||||
|
||||
# Static site generation (SSG)
|
||||
|
||||
In [architecture](architecture.mdx), we mentioned that the theme is run in Webpack. But beware: that doesn't mean it always has access to browser globals! The theme is built twice:
|
||||
|
||||
- During **server-side rendering**, the theme is compiled in a sandbox called [React DOM Server](https://reactjs.org/docs/react-dom-server.html). You can see this as a "headless browser", where there is no `window` or `document`, only React. SSR produces static HTML pages.
|
||||
- During **client-side rendering**, the theme is compiled to JavaScript that gets eventually executed in the browser, so it has access to browser variables.
|
||||
|
||||
:::info SSR or SSG?
|
||||
|
||||
_Server-side rendering_ and _static site generation_ can be different concepts, but we use them interchangeably.
|
||||
|
||||
Strictly speaking, Docusaurus is a static site generator, because there's no server-side runtime—we statically render to HTML files that are deployed on a CDN, instead of dynamically pre-rendering on each request. This differs from the working model of [Next.js](https://nextjs.org/).
|
||||
|
||||
:::
|
||||
|
||||
Therefore, while you probably know not to access Node globals like `process` ([or can we?](#node-env)) or the `'fs'` module, you can't freely access browser globals either.
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
|
||||
export default function WhereAmI() {
|
||||
return <span>{window.location.href}</span>;
|
||||
}
|
||||
```
|
||||
|
||||
This looks like idiomatic React, but if you run `docusaurus build`, you will get an error:
|
||||
|
||||
```
|
||||
ReferenceError: window is not defined
|
||||
```
|
||||
|
||||
This is because during server-side rendering, the Docusaurus app isn't actually run in browser, and it doesn't know what `window` is.
|
||||
|
||||
```mdx-code-block
|
||||
<details id="node-env">
|
||||
<summary>What about <code>process.env.NODE_ENV</code>?</summary>
|
||||
```
|
||||
|
||||
One exception to the "no Node globals" rule is `process.env.NODE_ENV`. In fact, you can use it in React, because Webpack injects this variable as a global:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
|
||||
export default function expensiveComp() {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return <>This component is not shown in development</>;
|
||||
}
|
||||
const res = someExpensiveOperationThatLastsALongTime();
|
||||
return <>{res}</>;
|
||||
}
|
||||
```
|
||||
|
||||
During Webpack build, the `process.env.NODE_ENV` will be replaced with the value, either `'development'` or `'production'`. You will then get different build results after dead code elimination:
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="Development">
|
||||
```
|
||||
|
||||
```diff
|
||||
import React from 'react';
|
||||
|
||||
export default function expensiveComp() {
|
||||
// highlight-next-line
|
||||
if ('development' === 'development') {
|
||||
+ return <>This component is not shown in development</>;
|
||||
}
|
||||
- const res = someExpensiveOperationThatLastsALongTime();
|
||||
- return <>{res}</>;
|
||||
}
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="Production">
|
||||
```
|
||||
|
||||
```diff
|
||||
import React from 'react';
|
||||
|
||||
export default function expensiveComp() {
|
||||
// highlight-next-line
|
||||
- if ('production' === 'development') {
|
||||
- return <>This component is not shown in development</>;
|
||||
- }
|
||||
+ const res = someExpensiveOperationThatLastsALongTime();
|
||||
+ return <>{res}</>;
|
||||
}
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
</details>
|
||||
```
|
||||
|
||||
## Understanding SSR {#understanding-ssr}
|
||||
|
||||
React is not just a dynamic UI runtime—it's also a templating engine. Because Docusaurus sites mostly contain static contents, it should be able to work without any JavaScript (which React runs in), but only plain HTML/CSS. And that's what server-side rendering offers: statically rendering your React code into HTML, without any dynamic content. An HTML file has no concept of client state (it's purely markup), hence it shouldn't rely on browser APIs.
|
||||
|
||||
These HTML files are the first to arrive at the user's browser screen when a URL is visited (see [routing](routing.mdx)). Afterwards, the browser fetches and runs other JS code to provide the "dynamic" parts of your site—anything implemented with JavaScript. However, before that, the main content of your page is already visible, allowing faster loading.
|
||||
|
||||
In CSR-only apps, all DOM elements are generated on client side with React, and the HTML file only ever contains one root element for React to mount DOM to; in SSR, React is already facing a fully built HTML page, and it only needs to correlate the DOM elements with the virtual DOM in its model. This step is called "hydration". After React has hydrated the static markup, the app starts to work as any normal React app.
|
||||
|
||||
Note that Docusaurus is ultimately a single-page application, so static site generation is only an optimization (_progressive enhancement_, as it's called), but our functionality does not fully depend on those HTML files. This is contrary to site generators like [Jekyll](https://jekyllrb.com/) and [Docusaurus v1](https://v1.docusaurus.io/), where all files are statically transformed to markup, and interactiveness is added through external JavaScript linked with `<script>` tags. If you inspect the build output, you will still see JS assets under `build/assets/js`, which are, really, the core of Docusaurus.
|
||||
|
||||
## Escape hatches {#escape-hatches}
|
||||
|
||||
If you want to render any dynamic content on your screen that relies on the browser API to be functional at all, for example:
|
||||
|
||||
- Our [live codeblock](../guides/markdown-features/markdown-features-code-blocks.mdx#interactive-code-editor), which runs in the browser's JS runtime
|
||||
- Our [themed image](../guides/markdown-features/markdown-features-assets.mdx#themed-images) that detects the user's color scheme to display different images
|
||||
- The JSON viewer of our debug panel which uses the `window` global for styling
|
||||
|
||||
You may need to escape from SSR since static HTML can't display anything useful without knowing the client state.
|
||||
|
||||
:::warning
|
||||
|
||||
It is important for the first client-side render to produce the exact same DOM structure as server-side rendering, otherwise, React will correlate virtual DOM with the wrong DOM elements.
|
||||
|
||||
Therefore, the naïve attempt of `if (typeof window !== 'undefined) {/* render something */}` won't work appropriately as a browser vs. server detection, because the first client render would instantly render different markup from the server-generated one.
|
||||
|
||||
You can read more about this pitfall in [The Perils of Rehydration](https://www.joshwcomeau.com/react/the-perils-of-rehydration/).
|
||||
|
||||
:::
|
||||
|
||||
We provide several more reliable ways to escape SSR.
|
||||
|
||||
### `<BrowserOnly>` {#browseronly}
|
||||
|
||||
If you need to render some component in browser only (for example, because the component relies on browser specifics to be functional at all), one common approach is to wrap your component with [`<BrowserOnly>`](../docusaurus-core.mdx#browseronly) to make sure it's invisible during SSR and only rendered in CSR.
|
||||
|
||||
```jsx
|
||||
import BrowserOnly from '@docusaurus/BrowserOnly';
|
||||
|
||||
function MyComponent(props) {
|
||||
return (
|
||||
// highlight-start
|
||||
<BrowserOnly fallback={<div>Loading...</div>}>
|
||||
{() => {
|
||||
const LibComponent =
|
||||
require('some-lib-that-accesses-window').LibComponent;
|
||||
return <LibComponent {...props} />;
|
||||
}}
|
||||
</BrowserOnly>
|
||||
// highlight-end
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
It's important to realize that the children of `<BrowserOnly>` is not a JSX element, but a function that _returns_ an element. This is a design decision. Consider this code:
|
||||
|
||||
```jsx
|
||||
import BrowserOnly from '@docusaurus/BrowserOnly';
|
||||
|
||||
function MyComponent() {
|
||||
return (
|
||||
<BrowserOnly>
|
||||
{/* highlight-start */}
|
||||
{/* DON'T DO THIS - doesn't actually work */}
|
||||
<span>page url = {window.location.href}</span>
|
||||
{/* highlight-end */}
|
||||
</BrowserOnly>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
While you may expect that `BrowserOnly` hides away the children during server-side rendering, it actually can't. When the React renderer tries to render this JSX tree, it does see the `{window.location.href}` variable as a node of this tree and tries to render it, although it's actually not used! Using a function ensures that we only let the renderer see the browser-only component when it's needed.
|
||||
|
||||
### `useIsBrowser` {#useisbrowser}
|
||||
|
||||
You can also use the `useIsBrowser()` hook to test if the component is currently in a browser environment. It returns `false` in SSR and `true` is CSR, after first client render. Use this hook if you only need to perform certain conditional operations on client-side, but not render an entirely different UI.
|
||||
|
||||
```jsx
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
|
||||
function MyComponent() {
|
||||
const isBrowser = useIsBrowser();
|
||||
const location = isBrowser ? window.location.href : 'fetching location...';
|
||||
return <span>{location}</span>;
|
||||
}
|
||||
```
|
||||
|
||||
### `useEffect` {#useeffect}
|
||||
|
||||
Lastly, you can put your logic in `useEffect()` to delay its execution until after first CSR. This is most appropriate if you are only performing side-effects but don't _get_ data from the client state.
|
||||
|
||||
```jsx
|
||||
function MyComponent() {
|
||||
useEffect(() => {
|
||||
// Only logged in the browser console; nothing is logged during server-side rendering
|
||||
console.log("I'm now in the browser");
|
||||
}, []);
|
||||
return <span>Some content...</span>;
|
||||
}
|
||||
```
|
||||
|
||||
### `ExecutionEnvironment` {#executionenvironment}
|
||||
|
||||
The [`ExecutionEnvironment`](../docusaurus-core.mdx#executionenvironment) namespace contains several values, and `canUseDOM` is an effective way to detect browser environment.
|
||||
|
||||
Beware that it essentially checked `typeof window !== 'undefined'` under the hood, so you should not use it for rendering-related logic, but only imperative code, like reacting to user input by sending web requests, or dynamically importing libraries, where DOM isn't updated at all.
|
||||
|
||||
```js title="a-client-module.js"
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
document.title = "I'm loaded!";
|
||||
}
|
||||
```
|
|
@ -0,0 +1,706 @@
|
|||
---
|
||||
sidebar_position: 0
|
||||
description: API reference for Docusaurus configuration file.
|
||||
slug: /api/docusaurus-config
|
||||
---
|
||||
|
||||
# `docusaurus.config.js`
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
:::info
|
||||
|
||||
Refer to the Getting Started [**Configuration**](../configuration.mdx) for examples.
|
||||
|
||||
:::
|
||||
|
||||
## Overview {#overview}
|
||||
|
||||
`docusaurus.config.js` contains configurations for your site and is placed in the root directory of your site.
|
||||
|
||||
:::note
|
||||
|
||||
With a [TypeScript](../typescript-support.mdx) Docusaurus codebase your config file may be called `docusaurus.config.ts`. The syntax is broadly identical to the `js` config file with the addition of types. You can see an example on the [Docusaurus Website](https://github.com/facebook/docusaurus/blob/main/website/docusaurus.config.ts) itself.
|
||||
|
||||
:::
|
||||
|
||||
This file is run in Node.js and should export a site configuration object, or a function that creates it.
|
||||
|
||||
The `docusaurus.config.js` file supports:
|
||||
|
||||
- [**ES Modules**](https://flaviocopes.com/es-modules/)
|
||||
- [**CommonJS**](https://flaviocopes.com/commonjs/)
|
||||
- [**TypeScript**](../typescript-support.mdx#typing-config)
|
||||
|
||||
Examples:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
```
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default async function createConfigAsync() {
|
||||
return {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
Refer to [**Syntax to declare `docusaurus.config.js`**](../configuration.mdx#syntax-to-declare-docusaurus-config) for a more exhaustive list of examples and explanations.
|
||||
|
||||
:::
|
||||
|
||||
## Required fields {#required-fields}
|
||||
|
||||
### `title` {#title}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Title for your website. Will be used in metadata and as browser tab title.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
title: 'Docusaurus',
|
||||
};
|
||||
```
|
||||
|
||||
### `url` {#url}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
URL for your website. This can also be considered the top-level hostname. For example, `https://facebook.github.io` is the URL of https://facebook.github.io/metro/, and `https://docusaurus.io` is the URL for https://docusaurus.io. This field is related to the [`baseUrl`](#baseUrl) field.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
```
|
||||
|
||||
### `baseUrl` {#baseUrl}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Base URL for your site. Can be considered as the path after the host. For example, `/metro/` is the base URL of https://facebook.github.io/metro/. For URLs that have no path, the baseUrl should be set to `/`. This field is related to the [`url`](#url) field. Always has both leading and trailing slash.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
baseUrl: '/',
|
||||
};
|
||||
```
|
||||
|
||||
## Optional fields {#optional-fields}
|
||||
|
||||
### `favicon` {#favicon}
|
||||
|
||||
- Type: `string | undefined`
|
||||
|
||||
Path to your site favicon; must be a URL that can be used in link's href. For example, if your favicon is in `static/img/favicon.ico`:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
favicon: '/img/favicon.ico',
|
||||
};
|
||||
```
|
||||
|
||||
### `trailingSlash` {#trailingSlash}
|
||||
|
||||
- Type: `boolean | undefined`
|
||||
|
||||
Allow to customize the presence/absence of a trailing slash at the end of URLs/links, and how static HTML files are generated:
|
||||
|
||||
- `undefined` (default): keeps URLs untouched, and emit `/docs/myDoc/index.html` for `/docs/myDoc.md`
|
||||
- `true`: add trailing slashes to URLs/links, and emit `/docs/myDoc/index.html` for `/docs/myDoc.md`
|
||||
- `false`: remove trailing slashes from URLs/links, and emit `/docs/myDoc.html` for `/docs/myDoc.md`
|
||||
|
||||
:::tip
|
||||
|
||||
Each static hosting provider serves static files differently (this behavior may even change over time).
|
||||
|
||||
Refer to the [deployment guide](../deployment.mdx) and [slorber/trailing-slash-guide](https://github.com/slorber/trailing-slash-guide) to choose the appropriate setting.
|
||||
|
||||
:::
|
||||
|
||||
### `i18n` {#i18n}
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
The i18n configuration object to [localize your site](../i18n/i18n-introduction.mdx).
|
||||
|
||||
Example:
|
||||
|
||||
{/* cSpell:ignore فارسی */}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
locales: ['en', 'fa'],
|
||||
path: 'i18n',
|
||||
localeConfigs: {
|
||||
en: {
|
||||
label: 'English',
|
||||
direction: 'ltr',
|
||||
htmlLang: 'en-US',
|
||||
calendar: 'gregory',
|
||||
path: 'en',
|
||||
},
|
||||
fa: {
|
||||
label: 'فارسی',
|
||||
direction: 'rtl',
|
||||
htmlLang: 'fa-IR',
|
||||
calendar: 'persian',
|
||||
path: 'fa',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
- `defaultLocale`: The locale that (1) does not have its name in the base URL (2) gets started with `docusaurus start` without `--locale` option (3) will be used for the `<link hrefLang="x-default">` tag
|
||||
- `locales`: List of locales deployed on your site. Must contain `defaultLocale`.
|
||||
- `path`: Root folder which all locale folders are relative to. Can be absolute or relative to the config file. Defaults to `i18n`.
|
||||
- `localeConfigs`: Individual options for each locale.
|
||||
- `label`: The label displayed for this locale in the locales dropdown.
|
||||
- `direction`: `ltr` (default) or `rtl` (for [right-to-left languages](https://developer.mozilla.org/en-US/docs/Glossary/rtl) like Farsi, Arabic, Hebrew, etc.). Used to select the locale's CSS and HTML meta attribute.
|
||||
- `htmlLang`: BCP 47 language tag to use in `<html lang="...">` (or any other DOM tag name) and in `<link ... hreflang="...">`
|
||||
- `calendar`: the [calendar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar) used to calculate the date era. Note that it doesn't control the actual string displayed: `MM/DD/YYYY` and `DD/MM/YYYY` are both `gregory`. To choose the format (`DD/MM/YYYY` or `MM/DD/YYYY`), set your locale name to `en-GB` or `en-US` (`en` means `en-US`).
|
||||
- `path`: Root folder that all plugin localization folders of this locale are relative to. Will be resolved against `i18n.path`. Defaults to the locale's name. Note: this has no effect on the locale's `baseUrl`—customization of base URL is a work-in-progress.
|
||||
|
||||
### `noIndex` {#noIndex}
|
||||
|
||||
- Type: `boolean`
|
||||
|
||||
This option adds `<meta name="robots" content="noindex, nofollow">` to every page to tell search engines to avoid indexing your site (more information [here](https://moz.com/learn/seo/robots-meta-directives)).
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
noIndex: true, // Defaults to `false`
|
||||
};
|
||||
```
|
||||
|
||||
### `onBrokenLinks` {#onBrokenLinks}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'throw'`
|
||||
|
||||
The behavior of Docusaurus when it detects any broken link.
|
||||
|
||||
By default, it throws an error, to ensure you never ship any broken link.
|
||||
|
||||
:::note
|
||||
|
||||
The broken links detection is only available for a production build (`docusaurus build`).
|
||||
|
||||
:::
|
||||
|
||||
### `onBrokenAnchors` {#onBrokenAnchors}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'throw'`
|
||||
|
||||
The behavior of Docusaurus when it detects any broken anchor declared with the `Heading` component of Docusaurus.
|
||||
|
||||
By default, it prints a warning, to let you know about your broken anchors.
|
||||
|
||||
### `onBrokenMarkdownLinks` {#onBrokenMarkdownLinks}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'throw'`
|
||||
|
||||
The behavior of Docusaurus when it detects any broken Markdown link.
|
||||
|
||||
By default, it prints a warning, to let you know about your broken Markdown link.
|
||||
|
||||
### `onDuplicateRoutes` {#onDuplicateRoutes}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'throw'`
|
||||
|
||||
The behavior of Docusaurus when it detects any [duplicate routes](/guides/creating-pages.mdx#duplicate-routes).
|
||||
|
||||
By default, it displays a warning after you run `yarn start` or `yarn build`.
|
||||
|
||||
### `tagline` {#tagline}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The tagline for your website.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
tagline:
|
||||
'Docusaurus makes it easy to maintain Open Source documentation websites.',
|
||||
};
|
||||
```
|
||||
|
||||
### `organizationName` {#organizationName}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The GitHub user or organization that owns the repository. You don't need this if you are not using the `docusaurus deploy` command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// Docusaurus' organization is facebook
|
||||
organizationName: 'facebook',
|
||||
};
|
||||
```
|
||||
|
||||
### `projectName` {#projectName}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The name of the GitHub repository. You don't need this if you are not using the `docusaurus deploy` command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
projectName: 'docusaurus',
|
||||
};
|
||||
```
|
||||
|
||||
### `deploymentBranch` {#deploymentBranch}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The name of the branch to deploy the static files to. You don't need this if you are not using the `docusaurus deploy` command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
deploymentBranch: 'gh-pages',
|
||||
};
|
||||
```
|
||||
|
||||
### `githubHost` {#githubHost}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The hostname of your server. Useful if you are using GitHub Enterprise. You don't need this if you are not using the `docusaurus deploy` command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
githubHost: 'github.com',
|
||||
};
|
||||
```
|
||||
|
||||
### `githubPort` {#githubPort}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The port of your server. Useful if you are using GitHub Enterprise. You don't need this if you are not using the `docusaurus deploy` command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
githubPort: '22',
|
||||
};
|
||||
```
|
||||
|
||||
### `themeConfig` {#themeConfig}
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
The [theme configuration](./themes/theme-configuration.mdx) object to customize your site UI like navbar and footer.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
themeConfig: {
|
||||
docs: {
|
||||
sidebar: {
|
||||
hideable: false,
|
||||
autoCollapseCategories: false,
|
||||
},
|
||||
},
|
||||
colorMode: {
|
||||
defaultMode: 'light',
|
||||
disableSwitch: false,
|
||||
respectPrefersColorScheme: true,
|
||||
},
|
||||
navbar: {
|
||||
title: 'Site Title',
|
||||
logo: {
|
||||
alt: 'Site Logo',
|
||||
src: 'img/logo.svg',
|
||||
width: 32,
|
||||
height: 32,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
to: 'docs/docusaurus.config.js',
|
||||
activeBasePath: 'docs',
|
||||
label: 'docusaurus.config.js',
|
||||
position: 'left',
|
||||
},
|
||||
// ... other links
|
||||
],
|
||||
},
|
||||
footer: {
|
||||
style: 'dark',
|
||||
links: [
|
||||
{
|
||||
title: 'Docs',
|
||||
items: [
|
||||
{
|
||||
label: 'Docs',
|
||||
to: 'docs/doc1',
|
||||
},
|
||||
],
|
||||
},
|
||||
// ... other links
|
||||
],
|
||||
logo: {
|
||||
alt: 'Meta Open Source Logo',
|
||||
src: 'img/meta_oss_logo.png',
|
||||
href: 'https://opensource.fb.com',
|
||||
width: 160,
|
||||
height: 51,
|
||||
},
|
||||
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, // You can also put own HTML here
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### `plugins` {#plugins}
|
||||
|
||||
- Type: `PluginConfig[]`
|
||||
|
||||
```ts
|
||||
type PluginConfig = string | [string, any] | PluginModule | [PluginModule, any];
|
||||
```
|
||||
|
||||
See [plugin method references](./plugin-methods/README.mdx) for the shape of a `PluginModule`.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
'docusaurus-plugin-awesome',
|
||||
['docusuarus-plugin-confetti', {fancy: false}],
|
||||
() => ({
|
||||
postBuild() {
|
||||
console.log('Build finished');
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `themes` {#themes}
|
||||
|
||||
- Type: `PluginConfig[]`
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
themes: ['@docusaurus/theme-classic'],
|
||||
};
|
||||
```
|
||||
|
||||
### `presets` {#presets}
|
||||
|
||||
- Type: `PresetConfig[]`
|
||||
|
||||
```ts
|
||||
type PresetConfig = string | [string, any];
|
||||
```
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
presets: [],
|
||||
};
|
||||
```
|
||||
|
||||
### `markdown` {#markdown}
|
||||
|
||||
The global Docusaurus Markdown config.
|
||||
|
||||
- Type: `MarkdownConfig`
|
||||
|
||||
```ts
|
||||
type MarkdownPreprocessor = (args: {
|
||||
filePath: string;
|
||||
fileContent: string;
|
||||
}) => string;
|
||||
|
||||
type MDX1CompatOptions =
|
||||
| boolean
|
||||
| {
|
||||
comments: boolean;
|
||||
admonitions: boolean;
|
||||
headingIds: boolean;
|
||||
};
|
||||
|
||||
export type ParseFrontMatter = (params: {
|
||||
filePath: string;
|
||||
fileContent: string;
|
||||
defaultParseFrontMatter: ParseFrontMatter;
|
||||
}) => Promise<{
|
||||
frontMatter: {[key: string]: unknown};
|
||||
content: string;
|
||||
}>;
|
||||
|
||||
type MarkdownAnchorsConfig = {
|
||||
maintainCase: boolean;
|
||||
};
|
||||
|
||||
type MarkdownConfig = {
|
||||
format: 'mdx' | 'md' | 'detect';
|
||||
mermaid: boolean;
|
||||
preprocessor?: MarkdownPreprocessor;
|
||||
parseFrontMatter?: ParseFrontMatter;
|
||||
mdx1Compat: MDX1CompatOptions;
|
||||
remarkRehypeOptions: object; // see https://github.com/remarkjs/remark-rehype#options
|
||||
anchors: MarkdownAnchorsConfig;
|
||||
};
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
markdown: {
|
||||
format: 'mdx',
|
||||
mermaid: true,
|
||||
preprocessor: ({filePath, fileContent}) => {
|
||||
return fileContent.replaceAll('{{MY_VAR}}', 'MY_VALUE');
|
||||
},
|
||||
parseFrontMatter: async (params) => {
|
||||
const result = await params.defaultParseFrontMatter(params);
|
||||
result.frontMatter.description =
|
||||
result.frontMatter.description?.replaceAll('{{MY_VAR}}', 'MY_VALUE');
|
||||
return result;
|
||||
},
|
||||
mdx1Compat: {
|
||||
comments: true,
|
||||
admonitions: true,
|
||||
headingIds: true,
|
||||
},
|
||||
anchors: {
|
||||
maintainCase: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `format` | `'mdx' \| 'md' \| 'detect'` | `'mdx'` | The default parser format to use for Markdown content. Using 'detect' will select the appropriate format automatically based on file extensions: `.md` vs `.mdx`. |
|
||||
| `mermaid` | `boolean` | `false` | When `true`, allows Docusaurus to render Markdown code blocks with `mermaid` language as Mermaid diagrams. |
|
||||
| `preprocessor` | `MarkdownPreprocessor` | `undefined` | Gives you the ability to alter the Markdown content string before parsing. Use it as a last-resort escape hatch or workaround: it is almost always better to implement a Remark/Rehype plugin. |
|
||||
| `parseFrontMatter` | `ParseFrontMatter` | `undefined` | Gives you the ability to provide your own front matter parser, or to enhance the default parser. Read our [front matter guide](../guides/markdown-features/markdown-features-intro.mdx#front-matter) for details. |
|
||||
| `mdx1Compat` | `MDX1CompatOptions` | `{comments: true, admonitions: true, headingIds: true}` | Compatibility options to make it easier to upgrade to Docusaurus v3+. |
|
||||
| `anchors` | `MarkdownAnchorsConfig` | `{maintainCase: false}` | Options to control the behavior of anchors generated from Markdown headings |
|
||||
| `remarkRehypeOptions` | `object` | `undefined` | Makes it possible to pass custom [`remark-rehype` options](https://github.com/remarkjs/remark-rehype#options). |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### `customFields` {#customFields}
|
||||
|
||||
Docusaurus guards `docusaurus.config.js` from unknown fields. To add a custom field, define it on `customFields`.
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
customFields: {
|
||||
admin: 'endi',
|
||||
superman: 'lol',
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Attempting to add unknown fields in the config will lead to errors during build time:
|
||||
|
||||
```bash
|
||||
Error: The field(s) 'foo', 'bar' are not recognized in docusaurus.config.js
|
||||
```
|
||||
|
||||
### `staticDirectories` {#staticDirectories}
|
||||
|
||||
An array of paths, relative to the site's directory or absolute. Files under these paths will be copied to the build output as-is.
|
||||
|
||||
- Type: `string[]`
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
staticDirectories: ['static'],
|
||||
};
|
||||
```
|
||||
|
||||
### `headTags` {#headTags}
|
||||
|
||||
An array of tags that will be inserted in the HTML `<head>`. The values must be objects that contain two properties; `tagName` and `attributes`. `tagName` must be a string that determines the tag being created; eg `"link"`. `attributes` must be an attribute-value map.
|
||||
|
||||
- Type: `{ tagName: string; attributes: Object; }[]`
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
headTags: [
|
||||
{
|
||||
tagName: 'link',
|
||||
attributes: {
|
||||
rel: 'icon',
|
||||
href: '/img/docusaurus.png',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
This would become `<link rel="icon" href="img/docusaurus.png" />` in the generated HTML.
|
||||
|
||||
### `scripts` {#scripts}
|
||||
|
||||
An array of scripts to load. The values can be either strings or plain objects of attribute-value maps. The `<script>` tags will be inserted in the HTML `<head>`. If you use a plain object, the only required attribute is `src`, and any other attributes are permitted (each one should have boolean/string values).
|
||||
|
||||
Note that `<script>` added here are render-blocking, so you might want to add `async: true`/`defer: true` to the objects.
|
||||
|
||||
- Type: `(string | Object)[]`
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
scripts: [
|
||||
// String format.
|
||||
'https://docusaurus.io/script.js',
|
||||
// Object format.
|
||||
{
|
||||
src: 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
|
||||
async: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `stylesheets` {#stylesheets}
|
||||
|
||||
An array of CSS sources to load. The values can be either strings or plain objects of attribute-value maps. The `<link>` tags will be inserted in the HTML `<head>`. If you use an object, the only required attribute is `href`, and any other attributes are permitted (each one should have boolean/string values).
|
||||
|
||||
- Type: `(string | Object)[]`
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
stylesheets: [
|
||||
// String format.
|
||||
'https://docusaurus.io/style.css',
|
||||
// Object format.
|
||||
{
|
||||
href: 'http://mydomain.com/style.css',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
:::info
|
||||
|
||||
By default, the `<link>` tags will have `rel="stylesheet"`, but you can explicitly add a custom `rel` value to inject any kind of `<link>` tag, not necessarily stylesheets.
|
||||
|
||||
:::
|
||||
|
||||
### `clientModules` {#clientModules}
|
||||
|
||||
An array of [client modules](../advanced/client.mdx#client-modules) to load globally on your site.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
clientModules: ['./mySiteGlobalJs.js', './mySiteGlobalCss.css'],
|
||||
};
|
||||
```
|
||||
|
||||
### `ssrTemplate` {#ssrTemplate}
|
||||
|
||||
An HTML template written in [Eta's syntax](https://eta.js.org/docs/syntax#syntax-overview) that will be used to render your application. This can be used to set custom attributes on the `body` tags, additional `meta` tags, customize the `viewport`, etc. Please note that Docusaurus will rely on the template to be correctly structured in order to function properly, once you do customize it, you will have to make sure that your template is compliant with the requirements from upstream.
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
ssrTemplate: `<!DOCTYPE html>
|
||||
<html <%~ it.htmlAttributes %>>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="generator" content="Docusaurus v<%= it.version %>">
|
||||
<% it.metaAttributes.forEach((metaAttribute) => { %>
|
||||
<%~ metaAttribute %>
|
||||
<% }); %>
|
||||
<%~ it.headTags %>
|
||||
<% it.stylesheets.forEach((stylesheet) => { %>
|
||||
<link rel="stylesheet" href="<%= it.baseUrl %><%= stylesheet %>" />
|
||||
<% }); %>
|
||||
<% it.scripts.forEach((script) => { %>
|
||||
<link rel="preload" href="<%= it.baseUrl %><%= script %>" as="script">
|
||||
<% }); %>
|
||||
</head>
|
||||
<body <%~ it.bodyAttributes %>>
|
||||
<%~ it.preBodyTags %>
|
||||
<div id="__docusaurus">
|
||||
<%~ it.appHtml %>
|
||||
</div>
|
||||
<% it.scripts.forEach((script) => { %>
|
||||
<script src="<%= it.baseUrl %><%= script %>"></script>
|
||||
<% }); %>
|
||||
<%~ it.postBodyTags %>
|
||||
</body>
|
||||
</html>`,
|
||||
};
|
||||
```
|
||||
|
||||
### `titleDelimiter` {#titleDelimiter}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Will be used as title delimiter in the generated `<title>` tag.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
titleDelimiter: '🦖', // Defaults to `|`
|
||||
};
|
||||
```
|
||||
|
||||
### `baseUrlIssueBanner` {#baseUrlIssueBanner}
|
||||
|
||||
- Type: `boolean`
|
||||
|
||||
When enabled, will show a banner in case your site can't load its CSS or JavaScript files, which is a very common issue, often related to a wrong `baseUrl` in site config.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
baseUrlIssueBanner: true, // Defaults to `true`
|
||||
};
|
||||
```
|
||||
|
||||

|
||||
|
||||
:::warning
|
||||
|
||||
This banner needs to inline CSS / JS in case all asset loading fails due to wrong base URL.
|
||||
|
||||
If you have a strict [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), you should rather disable it.
|
||||
|
||||
:::
|
|
@ -0,0 +1,2 @@
|
|||
label: Miscellaneous
|
||||
position: 4
|
|
@ -0,0 +1,58 @@
|
|||
---
|
||||
sidebar_position: 0
|
||||
slug: /api/misc/create-docusaurus
|
||||
---
|
||||
|
||||
# 📦 create-docusaurus
|
||||
|
||||
A scaffolding utility to help you instantly set up a functional Docusaurus app.
|
||||
|
||||
## Usage {#usage}
|
||||
|
||||
```bash
|
||||
npx create-docusaurus@latest [name] [template] [rootDir]
|
||||
```
|
||||
|
||||
The `name` argument will be used as the site's path as well as the `name` field in the created app's package.json. It can be an absolute path, or a path relative to `rootDir`.
|
||||
|
||||
The `template` argument can be one of the following:
|
||||
|
||||
- `classic`: Uses the classic template (recommended)
|
||||
- `facebook`: Uses the Facebook/Meta template, which contains some Meta-specific setup
|
||||
- A git repo URL (beginning with `https://` or `git@`), which can be cloned to the destination
|
||||
- A local file path relative to CWD, which contains the files to be copied to destination
|
||||
|
||||
The `rootDir` will be used to resolve the absolute path to the site directory. The default is CWD.
|
||||
|
||||
:::warning
|
||||
|
||||
This command should be preferably used in an interactive shell so all features are available.
|
||||
|
||||
:::
|
||||
|
||||
## Options {#options}
|
||||
|
||||
### `-t, --typescript` {#typescript}
|
||||
|
||||
Used when the template argument is a recognized name. Currently, only `classic` provides a TypeScript variant.
|
||||
|
||||
### `-g, --git-strategy` {#git-strategy}
|
||||
|
||||
Used when the template argument is a git repo. It needs to be one of:
|
||||
|
||||
- `deep`: preserves full git history
|
||||
- `shallow`: clones with `--depth=1`
|
||||
- `copy`: does a shallow clone, but does not create a git repo
|
||||
- `custom`: enter your custom git clone command. We will prompt you for it. You can write something like `git clone --depth 10`, and we will append the repository URL and destination directory.
|
||||
|
||||
### `-p, --package-manager` {#package-manager}
|
||||
|
||||
Value should be one of `npm`, `yarn`, `pnpm`, or `bun`. If it's not explicitly provided, Docusaurus will infer one based on:
|
||||
|
||||
- The lockfile already present in the CWD (e.g. if you are setting up website in an existing project)
|
||||
- The command used to invoke `create-docusaurus` (e.g. `npm init`, `npx`, `yarn create`, `bunx`, etc.)
|
||||
- Interactive prompting, in case all heuristics are not present
|
||||
|
||||
### `-s, --skip-install` {#skip-install}
|
||||
|
||||
If provided, Docusaurus will not automatically install dependencies after creating the app. The `--package-manager` option is only useful when you are actually installing dependencies.
|
|
@ -0,0 +1,74 @@
|
|||
---
|
||||
sidebar_position: 1
|
||||
slug: /api/misc/@docusaurus/eslint-plugin
|
||||
---
|
||||
|
||||
# 📦 eslint-plugin
|
||||
|
||||
[ESLint](https://eslint.org/) is a tool that statically analyzes your code and reports problems or suggests best practices through editor hints and command line. Docusaurus provides an ESLint plugin to enforce best Docusaurus practices.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save-dev @docusaurus/eslint-plugin
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Recommended config
|
||||
|
||||
Add `plugin:@docusaurus/recommended` to the `extends` section of your `.eslintrc` configuration file:
|
||||
|
||||
```json title=".eslintrc"
|
||||
{
|
||||
"extends": ["plugin:@docusaurus/recommended"]
|
||||
}
|
||||
```
|
||||
|
||||
This will enable the `@docusaurus` eslint plugin and use the `recommended` config. See [Supported rules](#supported-rules) below for a list of rules that this will enable.
|
||||
|
||||
### Manual config
|
||||
|
||||
For more fine-grained control, you can also enable the plugin manually and configure the rules you want to use directly:
|
||||
|
||||
```json title=".eslintrc"
|
||||
{
|
||||
"plugins": ["@docusaurus"],
|
||||
"rules": {
|
||||
"@docusaurus/string-literal-i18n-messages": "error",
|
||||
"@docusaurus/no-untranslated-text": "warn"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Supported configs
|
||||
|
||||
- Recommended: recommended rule set for most Docusaurus sites that should be extended from.
|
||||
- All: **all** rules enabled. This will change between minor versions, so you should not use this if you want to avoid unexpected breaking changes.
|
||||
|
||||
## Supported rules
|
||||
|
||||
| Name | Description | |
|
||||
| --- | --- | --- |
|
||||
| [`@docusaurus/no-untranslated-text`](./no-untranslated-text.mdx) | Enforce text labels in JSX to be wrapped by translate calls | |
|
||||
| [`@docusaurus/string-literal-i18n-messages`](./string-literal-i18n-messages.mdx) | Enforce translate APIs to be called on plain text labels | ✅ |
|
||||
| [`@docusaurus/no-html-links`](./no-html-links.mdx) | Ensures @docusaurus/Link is used instead of `<a>` tags | ✅ |
|
||||
| [`@docusaurus/prefer-docusaurus-heading`](./prefer-docusaurus-heading.mdx) | Ensures @theme/Heading is used instead of `<hn>` tags for headings | ✅ |
|
||||
|
||||
✅ = recommended
|
||||
|
||||
## Example configuration
|
||||
|
||||
Here's an example configuration:
|
||||
|
||||
```js title=".eslintrc.js"
|
||||
module.exports = {
|
||||
extends: ['plugin:@docusaurus/recommended'],
|
||||
rules: {
|
||||
'@docusaurus/no-untranslated-text': [
|
||||
'warn',
|
||||
{ignoredStrings: ['·', '—', '×']},
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
slug: /api/misc/@docusaurus/eslint-plugin/no-html-links
|
||||
---
|
||||
|
||||
# no-html-links
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
Ensure that the Docusaurus [`<Link>`](../../../docusaurus-core.mdx#link) component is used instead of `<a>` tags.
|
||||
|
||||
The `<Link>` component has prefetching and preloading built-in. It also does build-time broken link detection, and helps Docusaurus understand your site's structure better.
|
||||
|
||||
## Rule Details {#details}
|
||||
|
||||
Examples of **incorrect** code for this rule:
|
||||
|
||||
```html
|
||||
<a href="/page">go to page!</a>
|
||||
|
||||
<a href="https://twitter.com/docusaurus" target="_blank">Twitter</a>
|
||||
```
|
||||
|
||||
Examples of **correct** code for this rule:
|
||||
|
||||
```js
|
||||
import Link from '@docusaurus/Link'
|
||||
|
||||
<Link to="/page">go to page!</Link>
|
||||
|
||||
<Link to="https://twitter.com/docusaurus">Twitter</Link>
|
||||
```
|
||||
|
||||
## Rule Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `ignoreFullyResolved` | `boolean` | `false` | Set to true will not report any `<a>` tags with absolute URLs including a protocol. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
slug: /api/misc/@docusaurus/eslint-plugin/no-untranslated-text
|
||||
---
|
||||
|
||||
# no-untranslated-text
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
Enforce text labels in JSX to be wrapped by translate calls.
|
||||
|
||||
When the [i18n feature](../../../i18n/i18n-introduction.mdx) is used, this rule ensures that all labels appearing on the website are translatable, so no string accidentally slips through untranslated.
|
||||
|
||||
## Rule Details {#details}
|
||||
|
||||
Examples of **incorrect** code for this rule:
|
||||
|
||||
```js
|
||||
// Hello World is not translated
|
||||
<Component>Hello World</Component>
|
||||
```
|
||||
|
||||
Examples of **correct** code for this rule:
|
||||
|
||||
```js
|
||||
// Hello World is translated
|
||||
<Component>
|
||||
<Translate>Hello World</Translate>
|
||||
</Component>
|
||||
```
|
||||
|
||||
## Rule Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `ignoredStrings` | `string[]` | `[]` | Text labels that only contain strings in this list will not be reported. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
## When Not To Use It {#when-not-to-use}
|
||||
|
||||
If you're not using the [i18n feature](../../../i18n/i18n-introduction.mdx), you can disable this rule. You can also disable this rule where the text is not supposed to be translated.
|
||||
|
||||
## Further Reading {#further-reading}
|
||||
|
||||
- https://docusaurus.io/docs/docusaurus-core#translate
|
||||
- https://docusaurus.io/docs/docusaurus-core#translate-imperative
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
slug: /api/misc/@docusaurus/eslint-plugin/prefer-docusaurus-heading
|
||||
---
|
||||
|
||||
# prefer-docusaurus-heading
|
||||
|
||||
Ensures that the `@theme/Heading` theme component provided by Docusaurus [`theme-classic`](../../themes/theme-classic.mdx) is used instead of `<hn>` tags for headings.
|
||||
|
||||
## Rule Details {#details}
|
||||
|
||||
Examples of **incorrect** code for this rule:
|
||||
|
||||
```html
|
||||
<h1>This is heading 1</h1>
|
||||
|
||||
<h2>This is heading 2</h2>
|
||||
|
||||
<h3>This is heading 3</h3>
|
||||
```
|
||||
|
||||
Examples of **correct** code for this rule:
|
||||
|
||||
```javascript
|
||||
import Heading from '@theme/Heading'
|
||||
|
||||
<Heading as='h1'>This is heading 1</Heading>
|
||||
|
||||
<Heading as='h2'>This is heading 2</Heading>
|
||||
|
||||
<Heading as='h3'>This is heading 3</Heading>
|
||||
```
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
slug: /api/misc/@docusaurus/eslint-plugin/string-literal-i18n-messages
|
||||
---
|
||||
|
||||
# string-literal-i18n-messages
|
||||
|
||||
Enforce translate APIs to be called on plain text labels.
|
||||
|
||||
Docusaurus offers the [`docusaurus write-translations`](../../../cli.mdx#docusaurus-write-translations-sitedir) API, which statically extracts the text labels marked as translatable. Dynamic values used in `<Translate>` or `translate()` calls will fail to be extracted. This rule will ensure that all translate calls are statically extractable.
|
||||
|
||||
## Rule Details {#details}
|
||||
|
||||
Examples of **incorrect** code for this rule:
|
||||
|
||||
```js
|
||||
const text = 'Some text to be translated'
|
||||
|
||||
// Invalid <Translate> child
|
||||
<Translate>{text}</Translate>
|
||||
|
||||
// Invalid message attribute
|
||||
translate({message: text})
|
||||
```
|
||||
|
||||
Examples of **correct** code for this rule:
|
||||
|
||||
```js
|
||||
// Valid <Translate> child
|
||||
<Translate>Some text to be translated</Translate>
|
||||
|
||||
// Valid message attribute
|
||||
translate({message: 'Some text to be translated'})
|
||||
|
||||
// Valid <Translate> child using values object as prop
|
||||
<Translate values={{firstName: 'Sébastien'}}>
|
||||
{'Welcome, {firstName}! How are you?'}
|
||||
</Translate>
|
||||
|
||||
// Valid message attribute using values object as second argument
|
||||
translate({message: 'The logo of site {siteName}'}, {siteName: 'Docusaurus'})
|
||||
```
|
||||
|
||||
## When Not To Use It {#when-not-to-use}
|
||||
|
||||
If you're not using the [i18n feature](../../../i18n/i18n-introduction.mdx), you can disable this rule.
|
||||
|
||||
## Further Reading {#further-reading}
|
||||
|
||||
- https://docusaurus.io/docs/docusaurus-core#translate
|
||||
- https://docusaurus.io/docs/docusaurus-core#translate-imperative
|
BIN
website/versioned_docs/version-3.3.2/api/misc/logger/demo.png
Normal file
BIN
website/versioned_docs/version-3.3.2/api/misc/logger/demo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
|
@ -0,0 +1,71 @@
|
|||
---
|
||||
sidebar_position: 2
|
||||
slug: /api/misc/@docusaurus/logger
|
||||
---
|
||||
|
||||
# 📦 logger
|
||||
|
||||
An encapsulated logger for semantically formatting console messages.
|
||||
|
||||
Authors of packages in the Docusaurus ecosystem are encouraged to use this package to provide unified log formats.
|
||||
|
||||
## APIs
|
||||
|
||||
It exports a single object as default export: `logger`. `logger` has the following properties:
|
||||
|
||||
- Some useful colors.
|
||||
- `red`
|
||||
- `yellow`
|
||||
- `green`
|
||||
- `bold`
|
||||
- `dim`
|
||||
- Formatters. These functions all have the signature `(msg: unknown) => string`. Note that their implementations are not guaranteed. You should only care about their semantics.
|
||||
- `path`: formats a file path.
|
||||
- `url`: formats a URL.
|
||||
- `name`: formats an identifier.
|
||||
- `code`: formats a code snippet.
|
||||
- `subdue`: subdues the text.
|
||||
- `num`: formats a number.
|
||||
- The `interpolate` function. It is a template literal tag. The syntax can be found below.
|
||||
- Logging functions. All logging functions can both be used as normal functions (similar to the `console.log` family, but only accepts one parameter) or template literal tags.
|
||||
- `info`: prints information.
|
||||
- `warn`: prints a warning that should be paid attention to.
|
||||
- `error`: prints an error (not necessarily halting the program) that signals significant problems.
|
||||
- `success`: prints a success message.
|
||||
- The `report` function. It takes a `ReportingSeverity` value (`ignore`, `log`, `warn`, `throw`) and reports a message according to the severity.
|
||||
|
||||
:::warning A word on the `error` formatter
|
||||
|
||||
Beware that an `error` message, even when it doesn't hang the program, is likely going to cause confusion. When users inspect logs and find an `[ERROR]`, even when the build succeeds, they will assume something is going wrong. Use it sparingly.
|
||||
|
||||
Docusaurus only uses `logger.error` when printing messages immediately before throwing an error, or when user has set the reporting severity of `onBrokenLink`, etc. to `"error"`.
|
||||
|
||||
In addition, `warn` and `error` will color the **entire** message for better attention. If you are printing large blocks of help text about an error, better use `logger.info`.
|
||||
|
||||
:::
|
||||
|
||||
### Using the template literal tag
|
||||
|
||||
The template literal tag evaluates the template and expressions embedded. `interpolate` returns a new string, while other logging functions prints it. Below is a typical usage:
|
||||
|
||||
```js
|
||||
import logger from '@docusaurus/logger';
|
||||
|
||||
logger.info`Hello name=${name}! You have number=${money} dollars. Here are the ${
|
||||
items.length > 1 ? 'items' : 'item'
|
||||
} on the shelf: ${items}
|
||||
To buy anything, enter code=${'buy x'} where code=${'x'} is the item's name; to quit, press code=${'Ctrl + C'}.`;
|
||||
```
|
||||
|
||||
An embedded expression is optionally preceded by a flag in the form `[a-z]+=` (a few lowercase letters, followed by an equals sign, directly preceding the embedded expression). If the expression is not preceded by any flag, it's printed out as-is. Otherwise, it's formatted with one of the formatters:
|
||||
|
||||
- `path=`: `path`
|
||||
- `url=`: `url`
|
||||
- `name=`: `name`
|
||||
- `code=`: `code`
|
||||
- `subdue=`: `subdue`
|
||||
- `number=`: `num`
|
||||
|
||||
If the expression is an array, it's formatted by `` `\n- ${array.join('\n- ')}\n` `` (note it automatically gets a leading line end). Each member is formatted by itself and the bullet is not formatted. So you would see the above message printed as:
|
||||
|
||||

|
|
@ -0,0 +1,144 @@
|
|||
# Plugin Method References
|
||||
|
||||
:::warning
|
||||
|
||||
This section is a work in progress. Anchor links or even URLs are not guaranteed to be stable.
|
||||
|
||||
:::
|
||||
|
||||
Plugin APIs are shared by themes and plugins—themes are loaded just like plugins.
|
||||
|
||||
## Plugin module {#plugin-module}
|
||||
|
||||
Every plugin is imported as a module. The module is expected to have the following members:
|
||||
|
||||
- A **default export**: the constructor function for the plugin.
|
||||
- **Named exports**: the [static methods](./static-methods.mdx) called before plugins are initialized.
|
||||
|
||||
## Plugin constructor {#plugin-constructor}
|
||||
|
||||
The plugin module's default export is a constructor function with the signature `(context: LoadContext, options: PluginOptions) => Plugin | Promise<Plugin>`.
|
||||
|
||||
### `context` {#context}
|
||||
|
||||
`context` is plugin-agnostic, and the same object will be passed into all plugins used for a Docusaurus website. The `context` object contains the following fields:
|
||||
|
||||
```ts
|
||||
type LoadContext = {
|
||||
siteDir: string;
|
||||
generatedFilesDir: string;
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
baseUrl: string;
|
||||
};
|
||||
```
|
||||
|
||||
### `options` {#options}
|
||||
|
||||
`options` are the [second optional parameter when the plugins are used](../../using-plugins.mdx#configuring-plugins). `options` are plugin-specific and are specified by users when they use them in `docusaurus.config.js`. If there's a [`validateOptions`](./static-methods.mdx#validateOptions) function exported, the `options` will be validated and normalized beforehand.
|
||||
|
||||
Alternatively, if a preset contains the plugin, the preset will then be in charge of passing the correct options into the plugin. It is up to the individual plugin to define what options it takes.
|
||||
|
||||
## Example {#example}
|
||||
|
||||
Here's a mental model for a presumptuous plugin implementation.
|
||||
|
||||
```js
|
||||
// A JavaScript function that returns an object.
|
||||
// `context` is provided by Docusaurus. Example: siteConfig can be accessed from context.
|
||||
// `opts` is the user-defined options.
|
||||
export default async function myPlugin(context, opts) {
|
||||
return {
|
||||
// A compulsory field used as the namespace for directories to cache
|
||||
// the intermediate data for each plugin.
|
||||
// If you're writing your own local plugin, you will want it to
|
||||
// be unique in order not to potentially conflict with imported plugins.
|
||||
// A good way will be to add your own project name within.
|
||||
name: 'docusaurus-my-project-cool-plugin',
|
||||
|
||||
async loadContent() {
|
||||
// The loadContent hook is executed after siteConfig and env has been loaded.
|
||||
// You can return a JavaScript object that will be passed to contentLoaded hook.
|
||||
},
|
||||
|
||||
async contentLoaded({content, actions}) {
|
||||
// The contentLoaded hook is done after loadContent hook is done.
|
||||
// `actions` are set of functional API provided by Docusaurus (e.g. addRoute)
|
||||
},
|
||||
|
||||
async postBuild(props) {
|
||||
// After docusaurus <build> finish.
|
||||
},
|
||||
|
||||
// TODO
|
||||
async postStart(props) {
|
||||
// docusaurus <start> finish
|
||||
},
|
||||
|
||||
// TODO
|
||||
afterDevServer(app, server) {
|
||||
// https://webpack.js.org/configuration/dev-server/#devserverbefore
|
||||
},
|
||||
|
||||
// TODO
|
||||
beforeDevServer(app, server) {
|
||||
// https://webpack.js.org/configuration/dev-server/#devserverafter
|
||||
},
|
||||
|
||||
configureWebpack(config, isServer, utils, content) {
|
||||
// Modify internal webpack config. If returned value is an Object, it
|
||||
// will be merged into the final config using webpack-merge;
|
||||
// If the returned value is a function, it will receive the config as the 1st argument and an isServer flag as the 2nd argument.
|
||||
},
|
||||
|
||||
getPathsToWatch() {
|
||||
// Paths to watch.
|
||||
},
|
||||
|
||||
getThemePath() {
|
||||
// Returns the path to the directory where the theme components can
|
||||
// be found.
|
||||
},
|
||||
|
||||
getClientModules() {
|
||||
// Return an array of paths to the modules that are to be imported
|
||||
// in the client bundle. These modules are imported globally before
|
||||
// React even renders the initial UI.
|
||||
},
|
||||
|
||||
extendCli(cli) {
|
||||
// Register an extra command to enhance the CLI of Docusaurus
|
||||
},
|
||||
|
||||
injectHtmlTags({content}) {
|
||||
// Inject head and/or body HTML tags.
|
||||
},
|
||||
|
||||
async getTranslationFiles({content}) {
|
||||
// Return translation files
|
||||
},
|
||||
|
||||
translateContent({content, translationFiles}) {
|
||||
// translate the plugin content here
|
||||
},
|
||||
|
||||
translateThemeConfig({themeConfig, translationFiles}) {
|
||||
// translate the site themeConfig here
|
||||
},
|
||||
|
||||
async getDefaultCodeTranslationMessages() {
|
||||
// return default theme translations here
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function validateOptions({options, validate}) {
|
||||
const validatedOptions = validate(myValidationSchema, options);
|
||||
return validatedOptions;
|
||||
}
|
||||
|
||||
export function validateThemeConfig({themeConfig, validate}) {
|
||||
const validatedThemeConfig = validate(myValidationSchema, options);
|
||||
return validatedThemeConfig;
|
||||
}
|
||||
```
|
|
@ -0,0 +1,2 @@
|
|||
label: Plugin method references
|
||||
position: 1
|
|
@ -0,0 +1,132 @@
|
|||
---
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# Extending infrastructure
|
||||
|
||||
Docusaurus has some infrastructure like hot reloading, CLI, and swizzling, that can be extended by external plugins.
|
||||
|
||||
## `getPathsToWatch()` {#getPathsToWatch}
|
||||
|
||||
Specifies the paths to watch for plugins and themes. The paths are watched by the dev server so that the plugin lifecycles are reloaded when contents in the watched paths change. Note that the plugins and themes modules are initially called with `context` and `options` from Node, which you may use to find the necessary directory information about the site.
|
||||
|
||||
Use this for files that are consumed server-side, because theme files are automatically watched by Webpack dev server.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
import path from 'path';
|
||||
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// highlight-start
|
||||
getPathsToWatch() {
|
||||
const contentPath = path.resolve(context.siteDir, options.path);
|
||||
return [`${contentPath}/**/*.{ts,tsx}`];
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `extendCli(cli)` {#extendCli}
|
||||
|
||||
Register an extra command to enhance the CLI of Docusaurus. `cli` is a [commander](https://www.npmjs.com/package/commander/v/5.1.0) object.
|
||||
|
||||
:::warning
|
||||
|
||||
The commander version matters! We use commander v5, and make sure you are referring to the right version documentation for available APIs.
|
||||
|
||||
:::
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// highlight-start
|
||||
extendCli(cli) {
|
||||
cli
|
||||
.command('roll')
|
||||
.description('Roll a random number between 1 and 1000')
|
||||
.action(() => {
|
||||
console.log(Math.floor(Math.random() * 1000 + 1));
|
||||
});
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `getThemePath()` {#getThemePath}
|
||||
|
||||
Returns the path to the directory where the theme components can be found. When your users call `swizzle`, `getThemePath` is called and its returned path is used to find your theme components. Relative paths are resolved against the folder containing the entry point.
|
||||
|
||||
For example, your `getThemePath` can be:
|
||||
|
||||
```js title="my-theme/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'my-theme',
|
||||
// highlight-start
|
||||
getThemePath() {
|
||||
return './theme';
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `getTypeScriptThemePath()` {#getTypeScriptThemePath}
|
||||
|
||||
Similar to `getThemePath()`, it should return the path to the directory where the source code of TypeScript theme components can be found. This path is purely for swizzling TypeScript theme components, and theme components under this path will **not** be resolved by Webpack. Therefore, it is not a replacement for `getThemePath()`. Typically, you can make the path returned by `getTypeScriptThemePath()` be your source directory, and make the path returned by `getThemePath()` be the compiled JavaScript output.
|
||||
|
||||
:::tip
|
||||
|
||||
For TypeScript theme authors: you are strongly advised to make your compiled output as human-readable as possible. Only strip type annotations and don't transpile any syntaxes, because they will be handled by Webpack's Babel loader based on the targeted browser versions.
|
||||
|
||||
You should also format these files with Prettier. Remember—JS files can and will be directly consumed by your users.
|
||||
|
||||
:::
|
||||
|
||||
Example:
|
||||
|
||||
```js title="my-theme/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'my-theme',
|
||||
// highlight-start
|
||||
getThemePath() {
|
||||
// Where compiled JavaScript output lives
|
||||
return '../lib/theme';
|
||||
},
|
||||
getTypeScriptThemePath() {
|
||||
// Where TypeScript source code lives
|
||||
return '../src/theme';
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `getSwizzleComponentList()` {#getSwizzleComponentList}
|
||||
|
||||
**This is a static method, not attached to any plugin instance.**
|
||||
|
||||
Returns a list of stable components that are considered safe for swizzling. These components will be swizzlable without `--danger`. All components are considered unstable by default. If an empty array is returned, all components are considered unstable. If `undefined` is returned, all components are considered stable.
|
||||
|
||||
```js title="my-theme/src/index.js"
|
||||
export function getSwizzleComponentList() {
|
||||
return [
|
||||
'CodeBlock',
|
||||
'DocSidebar',
|
||||
'Footer',
|
||||
'NotFound',
|
||||
'SearchBar',
|
||||
'hooks/useTheme',
|
||||
'prism-include-languages',
|
||||
];
|
||||
}
|
||||
```
|
|
@ -0,0 +1,121 @@
|
|||
---
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# I18n lifecycles
|
||||
|
||||
Plugins use these lifecycles to load i18n-related data.
|
||||
|
||||
## `getTranslationFiles({content})` {#getTranslationFiles}
|
||||
|
||||
Plugins declare the JSON translation files they want to use.
|
||||
|
||||
Returns translation files `{path: string, content: ChromeI18nJSON}`:
|
||||
|
||||
- `path`: relative to the plugin localized folder `i18n/[locale]/[pluginName]`. Extension `.json` should be omitted to remain generic.
|
||||
- `content`: using the Chrome i18n JSON format.
|
||||
|
||||
These files will be written by the [`write-translations` CLI](../../cli.mdx#docusaurus-write-translations-sitedir) to the plugin i18n subfolder, and will be read in the appropriate locale before calling [`translateContent()`](#translateContent) and [`translateThemeConfig()`](#translateThemeConfig)
|
||||
|
||||
Example:
|
||||
|
||||
```js title="my-plugin.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'my-plugin',
|
||||
// highlight-start
|
||||
async getTranslationFiles({content}) {
|
||||
return [
|
||||
{
|
||||
path: 'sidebar-labels',
|
||||
content: {
|
||||
someSidebarLabel: {
|
||||
message: 'Some Sidebar Label',
|
||||
description: 'A label used in my plugin in the sidebar',
|
||||
},
|
||||
someLabelFromContent: content.myLabel,
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `translateContent({content,translationFiles})` {#translateContent}
|
||||
|
||||
Translate the plugin content, using the localized translation files.
|
||||
|
||||
Returns the localized plugin content.
|
||||
|
||||
The `contentLoaded()` lifecycle will be called with the localized plugin content returned by `translateContent()`.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="my-plugin.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'my-plugin',
|
||||
// highlight-start
|
||||
translateContent({content, translationFiles}) {
|
||||
const myTranslationFile = translationFiles.find(
|
||||
(f) => f.path === 'myTranslationFile',
|
||||
);
|
||||
return {
|
||||
...content,
|
||||
someContentLabel: myTranslationFile.someContentLabel.message,
|
||||
};
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `translateThemeConfig({themeConfig,translationFiles})` {#translateThemeConfig}
|
||||
|
||||
Translate the site `themeConfig` labels, using the localized translation files.
|
||||
|
||||
Returns the localized `themeConfig`.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="my-plugin.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'my-theme',
|
||||
// highlight-start
|
||||
translateThemeConfig({themeConfig, translationFiles}) {
|
||||
const myTranslationFile = translationFiles.find(
|
||||
(f) => f.path === 'myTranslationFile',
|
||||
);
|
||||
return {
|
||||
...themeConfig,
|
||||
someThemeConfigLabel: myTranslationFile.someThemeConfigLabel.message,
|
||||
};
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `async getDefaultCodeTranslationMessages()` {#getDefaultCodeTranslationMessages}
|
||||
|
||||
Themes using the `<Translate>` API can provide default code translation messages.
|
||||
|
||||
It should return messages in `Record<string, string>`, where keys are translation IDs and values are messages (without the description) localized using the site's current locale.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="my-plugin.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'my-theme',
|
||||
// highlight-start
|
||||
async getDefaultCodeTranslationMessages() {
|
||||
return readJsonFile(`${context.i18n.currentLocale}.json`);
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
|
@ -0,0 +1,492 @@
|
|||
---
|
||||
sidebar_position: 1
|
||||
toc_max_heading_level: 4
|
||||
---
|
||||
|
||||
# Lifecycle APIs
|
||||
|
||||
During the build, plugins are loaded in parallel to fetch their own contents and render them to routes. Plugins may also configure webpack or post-process the generated files.
|
||||
|
||||
## `async loadContent()` {#loadContent}
|
||||
|
||||
Plugins should use this lifecycle to fetch from data sources (filesystem, remote API, headless CMS, etc.) or do some server processing. The return value is the content it needs.
|
||||
|
||||
For example, this plugin below returns a random integer between 1 and 10 as content.
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// highlight-start
|
||||
async loadContent() {
|
||||
return 1 + Math.floor(Math.random() * 10);
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `async contentLoaded({content, actions})` {#contentLoaded}
|
||||
|
||||
The data that was loaded in `loadContent` will be consumed in `contentLoaded`. It can be rendered to routes, registered as global data, etc.
|
||||
|
||||
### `content` {#content}
|
||||
|
||||
`contentLoaded` will be called _after_ `loadContent` is done. The return value of `loadContent()` will be passed to `contentLoaded` as `content`.
|
||||
|
||||
### `actions` {#actions}
|
||||
|
||||
`actions` contain three functions:
|
||||
|
||||
#### `addRoute(config: RouteConfig): void` {#addRoute}
|
||||
|
||||
Create a route to add to the website.
|
||||
|
||||
```ts
|
||||
export type RouteConfig = {
|
||||
/**
|
||||
* With leading slash. Trailing slash will be normalized by config.
|
||||
*/
|
||||
path: string;
|
||||
/**
|
||||
* Component used to render this route, a path that the bundler can `require`.
|
||||
*/
|
||||
component: string;
|
||||
/**
|
||||
* Props. Each entry should be `[propName]: pathToPropModule` (created with
|
||||
* `createData`)
|
||||
*/
|
||||
modules?: RouteModules;
|
||||
/**
|
||||
* The route context will wrap the `component`. Use `useRouteContext` to
|
||||
* retrieve what's declared here. Note that all custom route context declared
|
||||
* here will be namespaced under {@link RouteContext.data}.
|
||||
*/
|
||||
context?: RouteModules;
|
||||
/**
|
||||
* Nested routes config, useful for "layout routes" having subroutes.
|
||||
*/
|
||||
routes?: RouteConfig[];
|
||||
/**
|
||||
* React router config option: `exact` routes would not match subroutes.
|
||||
*/
|
||||
exact?: boolean;
|
||||
/**
|
||||
* React router config option: `strict` routes are sensitive to the presence
|
||||
* of a trailing slash.
|
||||
*/
|
||||
strict?: boolean;
|
||||
/**
|
||||
* Used to sort routes.
|
||||
* Higher-priority routes will be matched first.
|
||||
*/
|
||||
priority?: number;
|
||||
/**
|
||||
* Optional route metadata
|
||||
*/
|
||||
metadata?: RouteMetadata;
|
||||
/**
|
||||
* Extra props; will be available on the client side.
|
||||
*/
|
||||
[propName: string]: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin authors can assign extra metadata to the created routes
|
||||
* It is only available on the Node.js side, and not sent to the browser
|
||||
* Optional: plugin authors are encouraged but not required to provide it
|
||||
*
|
||||
* Some plugins might use this data to provide additional features.
|
||||
* This is the case of the sitemap plugin to provide support for "lastmod".
|
||||
* See also: https://github.com/facebook/docusaurus/pull/9954
|
||||
*/
|
||||
export type RouteMetadata = {
|
||||
/**
|
||||
* The source code file path that led to the creation of the current route
|
||||
* In official content plugins, this is usually a Markdown or React file
|
||||
* This path is expected to be relative to the site directory
|
||||
*/
|
||||
sourceFilePath?: string;
|
||||
/**
|
||||
* The last updated date of this route
|
||||
* This is generally read from the Git history of the sourceFilePath
|
||||
* but can also be provided through other means (usually front matter)
|
||||
*
|
||||
* This has notably been introduced for adding "lastmod" support to the
|
||||
* sitemap plugin, see https://github.com/facebook/docusaurus/pull/9954
|
||||
*/
|
||||
lastUpdatedAt?: number;
|
||||
};
|
||||
|
||||
type RouteModules = {
|
||||
[module: string]: Module | RouteModules | RouteModules[];
|
||||
};
|
||||
|
||||
type Module =
|
||||
| {
|
||||
path: string;
|
||||
__import?: boolean;
|
||||
query?: ParsedUrlQueryInput;
|
||||
}
|
||||
| string;
|
||||
```
|
||||
|
||||
#### `createData(name: string, data: any): Promise<string>` {#createData}
|
||||
|
||||
A declarative callback to create static data (generally JSON or string) which can later be provided to your routes as props. Takes the file name and data to be stored, and returns the actual data file's path.
|
||||
|
||||
For example, this plugin below creates a `/friends` page which displays `Your friends are: Yangshun, Sebastien`:
|
||||
|
||||
```jsx title="website/src/components/Friends.js"
|
||||
import React from 'react';
|
||||
|
||||
export default function FriendsComponent({friends}) {
|
||||
return <div>Your friends are {friends.join(',')}</div>;
|
||||
}
|
||||
```
|
||||
|
||||
```js title="docusaurus-friends-plugin/src/index.js"
|
||||
export default function friendsPlugin(context, options) {
|
||||
return {
|
||||
name: 'docusaurus-friends-plugin',
|
||||
// highlight-start
|
||||
async contentLoaded({content, actions}) {
|
||||
const {createData, addRoute} = actions;
|
||||
// Create friends.json
|
||||
const friends = ['Yangshun', 'Sebastien'];
|
||||
const friendsJsonPath = await createData(
|
||||
'friends.json',
|
||||
JSON.stringify(friends),
|
||||
);
|
||||
|
||||
// Add the '/friends' routes, and ensure it receives the friends props
|
||||
addRoute({
|
||||
path: '/friends',
|
||||
component: '@site/src/components/Friends.js',
|
||||
modules: {
|
||||
// propName -> JSON file path
|
||||
friends: friendsJsonPath,
|
||||
},
|
||||
exact: true,
|
||||
});
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
#### `setGlobalData(data: any): void` {#setGlobalData}
|
||||
|
||||
This function permits one to create some global plugin data that can be read from any page, including the pages created by other plugins, and your theme layout.
|
||||
|
||||
This data becomes accessible to your client-side/theme code through the [`useGlobalData`](../../docusaurus-core.mdx#useGlobalData) and [`usePluginData`](../../docusaurus-core.mdx#usePluginData) hooks.
|
||||
|
||||
:::warning
|
||||
|
||||
Global data is... global: its size affects the loading time of all pages of your site, so try to keep it small. Prefer `createData` and page-specific data whenever possible.
|
||||
|
||||
:::
|
||||
|
||||
For example, this plugin below creates a `/friends` page which displays `Your friends are: Yangshun, Sebastien`:
|
||||
|
||||
```jsx title="website/src/components/Friends.js"
|
||||
import React from 'react';
|
||||
import {usePluginData} from '@docusaurus/useGlobalData';
|
||||
|
||||
export default function FriendsComponent() {
|
||||
const {friends} = usePluginData('docusaurus-friends-plugin');
|
||||
return <div>Your friends are {friends.join(',')}</div>;
|
||||
}
|
||||
```
|
||||
|
||||
```js title="docusaurus-friends-plugin/src/index.js"
|
||||
export default function friendsPlugin(context, options) {
|
||||
return {
|
||||
name: 'docusaurus-friends-plugin',
|
||||
// highlight-start
|
||||
async contentLoaded({content, actions}) {
|
||||
const {setGlobalData, addRoute} = actions;
|
||||
// Create friends global data
|
||||
setGlobalData({friends: ['Yangshun', 'Sebastien']});
|
||||
|
||||
// Add the '/friends' routes
|
||||
addRoute({
|
||||
path: '/friends',
|
||||
component: '@site/src/components/Friends.js',
|
||||
exact: true,
|
||||
});
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `configureWebpack(config, isServer, utils, content)` {#configureWebpack}
|
||||
|
||||
Modifies the internal webpack config. If the return value is a JavaScript object, it will be merged into the final config using [`webpack-merge`](https://github.com/survivejs/webpack-merge). If it is a function, it will be called and receive `config` as the first argument and an `isServer` flag as the second argument.
|
||||
|
||||
:::warning
|
||||
|
||||
The API of `configureWebpack` will be modified in the future to accept an object (`configureWebpack({config, isServer, utils, content})`)
|
||||
|
||||
:::
|
||||
|
||||
### `config` {#config}
|
||||
|
||||
`configureWebpack` is called with `config` generated according to client/server build. You may treat this as the base config to be merged with.
|
||||
|
||||
### `isServer` {#isServer}
|
||||
|
||||
`configureWebpack` will be called both in server build and in client build. The server build receives `true` and the client build receives `false` as `isServer`.
|
||||
|
||||
### `utils` {#utils}
|
||||
|
||||
`configureWebpack` also receives an util object:
|
||||
|
||||
- `getStyleLoaders(isServer: boolean, cssOptions: {[key: string]: any}): Loader[]`
|
||||
- `getJSLoader(isServer: boolean, cacheOptions?: {}): Loader | null`
|
||||
|
||||
You may use them to return your webpack configuration conditionally.
|
||||
|
||||
For example, this plugin below modify the webpack config to transpile `.foo` files.
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'custom-docusaurus-plugin',
|
||||
// highlight-start
|
||||
configureWebpack(config, isServer, utils) {
|
||||
const {getJSLoader} = utils;
|
||||
return {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.foo$/,
|
||||
use: [getJSLoader(isServer), 'my-custom-webpack-loader'],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### `content` {#content-1}
|
||||
|
||||
`configureWebpack` will be called both with the content loaded by the plugin.
|
||||
|
||||
### Merge strategy {#merge-strategy}
|
||||
|
||||
We merge the Webpack configuration parts of plugins into the global Webpack config using [webpack-merge](https://github.com/survivejs/webpack-merge).
|
||||
|
||||
It is possible to specify the merge strategy. For example, if you want a webpack rule to be prepended instead of appended:
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'custom-docusaurus-plugin',
|
||||
configureWebpack(config, isServer, utils) {
|
||||
return {
|
||||
// highlight-start
|
||||
mergeStrategy: {'module.rules': 'prepend'},
|
||||
module: {rules: [myRuleToPrepend]},
|
||||
// highlight-end
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
Read the [webpack-merge strategy doc](https://github.com/survivejs/webpack-merge#merging-with-strategies) for more details.
|
||||
|
||||
### Configuring dev server {#configuring-dev-server}
|
||||
|
||||
The dev server can be configured through returning a `devServer` field.
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'custom-docusaurus-plugin',
|
||||
configureWebpack(config, isServer, utils) {
|
||||
return {
|
||||
// highlight-start
|
||||
devServer: {
|
||||
open: '/docs', // Opens localhost:3000/docs instead of localhost:3000/
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `configurePostCss(options)` {#configurePostCss}
|
||||
|
||||
Modifies [`postcssOptions` of `postcss-loader`](https://webpack.js.org/loaders/postcss-loader/#postcssoptions) during the generation of the client bundle.
|
||||
|
||||
Should return the mutated `postcssOptions`.
|
||||
|
||||
By default, `postcssOptions` looks like this:
|
||||
|
||||
```js
|
||||
const postcssOptions = {
|
||||
ident: 'postcss',
|
||||
plugins: [require('autoprefixer')],
|
||||
};
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// highlight-start
|
||||
configurePostCss(postcssOptions) {
|
||||
// Appends new PostCSS plugin.
|
||||
postcssOptions.plugins.push(require('postcss-import'));
|
||||
return postcssOptions;
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `postBuild(props)` {#postBuild}
|
||||
|
||||
Called when a (production) build finishes.
|
||||
|
||||
```ts
|
||||
interface Props {
|
||||
siteDir: string;
|
||||
generatedFilesDir: string;
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
baseUrl: string;
|
||||
headTags: string;
|
||||
preBodyTags: string;
|
||||
postBodyTags: string;
|
||||
routesPaths: string[];
|
||||
plugins: Plugin<any>[];
|
||||
content: Content;
|
||||
}
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// highlight-start
|
||||
async postBuild({siteConfig = {}, routesPaths = [], outDir}) {
|
||||
// Print out to console all the rendered routes.
|
||||
routesPaths.map((route) => {
|
||||
console.log(route);
|
||||
});
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## `injectHtmlTags({content})` {#injectHtmlTags}
|
||||
|
||||
Inject head and/or body HTML tags to Docusaurus generated HTML.
|
||||
|
||||
`injectHtmlTags` will be called both with the content loaded by the plugin.
|
||||
|
||||
```ts
|
||||
function injectHtmlTags(): {
|
||||
headTags?: HtmlTags;
|
||||
preBodyTags?: HtmlTags;
|
||||
postBodyTags?: HtmlTags;
|
||||
};
|
||||
|
||||
type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[];
|
||||
|
||||
type HtmlTagObject = {
|
||||
/**
|
||||
* Attributes of the HTML tag
|
||||
* E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
|
||||
*/
|
||||
attributes?: {
|
||||
[attributeName: string]: string | boolean;
|
||||
};
|
||||
/**
|
||||
* The tag name e.g. `div`, `script`, `link`, `meta`
|
||||
*/
|
||||
tagName: string;
|
||||
/**
|
||||
* The inner HTML
|
||||
*/
|
||||
innerHTML?: string;
|
||||
};
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus-plugin/src/index.js"
|
||||
export default function (context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
loadContent: async () => {
|
||||
return {remoteHeadTags: await fetchHeadTagsFromAPI()};
|
||||
},
|
||||
// highlight-start
|
||||
injectHtmlTags({content}) {
|
||||
return {
|
||||
headTags: [
|
||||
{
|
||||
tagName: 'link',
|
||||
attributes: {
|
||||
rel: 'preconnect',
|
||||
href: 'https://www.github.com',
|
||||
},
|
||||
},
|
||||
...content.remoteHeadTags,
|
||||
],
|
||||
preBodyTags: [
|
||||
{
|
||||
tagName: 'script',
|
||||
attributes: {
|
||||
charset: 'utf-8',
|
||||
src: '/noflash.js',
|
||||
},
|
||||
},
|
||||
],
|
||||
postBodyTags: [`<div> This is post body </div>`],
|
||||
};
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
Tags will be added as follows:
|
||||
|
||||
- `headTags` will be inserted before the closing `</head>` tag after scripts added by config.
|
||||
- `preBodyTags` will be inserted after the opening `<body>` tag before any child elements.
|
||||
- `postBodyTags` will be inserted before the closing `</body>` tag after all child elements.
|
||||
|
||||
## `getClientModules()` {#getClientModules}
|
||||
|
||||
Returns an array of paths to the [client modules](../../advanced/client.mdx#client-modules) that are to be imported into the client bundle.
|
||||
|
||||
As an example, to make your theme load a `customCss` or `customJs` file path from `options` passed in by the user:
|
||||
|
||||
```js title="my-theme/src/index.js"
|
||||
export default function (context, options) {
|
||||
const {customCss, customJs} = options || {};
|
||||
return {
|
||||
name: 'name-of-my-theme',
|
||||
// highlight-start
|
||||
getClientModules() {
|
||||
return [customCss, customJs];
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
}
|
||||
```
|
|
@ -0,0 +1,83 @@
|
|||
---
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
# Static methods
|
||||
|
||||
Static methods are not part of the plugin instance—they are attached to the constructor function. These methods are used to validate and normalize the plugin options and theme config, which are then used as constructor parameters to initialize the plugin instance.
|
||||
|
||||
## `validateOptions({options, validate})` {#validateOptions}
|
||||
|
||||
Returns validated and normalized options for the plugin. This method is called before the plugin is initialized. You must return the options since they will be passed to the plugin during initialization.
|
||||
|
||||
### `options` {#options}
|
||||
|
||||
`validateOptions` is called with `options` passed to plugin for validation and normalization.
|
||||
|
||||
### `validate` {#validate}
|
||||
|
||||
`validateOptions` is called with `validate` function which takes a **[Joi](https://www.npmjs.com/package/joi)** schema and options as the arguments, returns validated and normalized options. `validate` will automatically handle error and validation config.
|
||||
|
||||
:::tip
|
||||
|
||||
[Joi](https://www.npmjs.com/package/joi) is recommended for validation and normalization of options.
|
||||
|
||||
To avoid mixing Joi versions, use `import {Joi} from '@docusaurus/utils-validation'`
|
||||
|
||||
:::
|
||||
|
||||
If you don't use **[Joi](https://www.npmjs.com/package/joi)** for validation you can throw an Error in case of invalid options and return options in case of success.
|
||||
|
||||
```js title="my-plugin/src/index.js"
|
||||
export default function myPlugin(context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// rest of methods
|
||||
};
|
||||
}
|
||||
|
||||
// highlight-start
|
||||
export function validateOptions({options, validate}) {
|
||||
const validatedOptions = validate(myValidationSchema, options);
|
||||
return validatedOptions;
|
||||
}
|
||||
// highlight-end
|
||||
```
|
||||
|
||||
## `validateThemeConfig({themeConfig, validate})` {#validateThemeConfig}
|
||||
|
||||
Return validated and normalized configuration for the theme.
|
||||
|
||||
### `themeConfig` {#themeConfig}
|
||||
|
||||
`validateThemeConfig` is called with `themeConfig` provided in `docusaurus.config.js` for validation and normalization.
|
||||
|
||||
### `validate` {#validate-1}
|
||||
|
||||
`validateThemeConfig` is called with `validate` function which takes a **[Joi](https://www.npmjs.com/package/joi)** schema and `themeConfig` as the arguments, returns validated and normalized options. `validate` will automatically handle error and validation config.
|
||||
|
||||
:::tip
|
||||
|
||||
[Joi](https://www.npmjs.com/package/joi) is recommended for validation and normalization of theme config.
|
||||
|
||||
To avoid mixing Joi versions, use `import {Joi} from '@docusaurus/utils-validation'`
|
||||
|
||||
:::
|
||||
|
||||
If you don't use **[Joi](https://www.npmjs.com/package/joi)** for validation you can throw an Error in case of invalid options.
|
||||
|
||||
```js title="my-theme/src/index.js"
|
||||
export default function myPlugin(context, options) {
|
||||
return {
|
||||
name: 'docusaurus-plugin',
|
||||
// rest of methods
|
||||
};
|
||||
}
|
||||
|
||||
// highlight-start
|
||||
export function validateThemeConfig({themeConfig, validate}) {
|
||||
const validatedThemeConfig = validate(myValidationSchema, options);
|
||||
return validatedThemeConfig;
|
||||
}
|
||||
// highlight-end
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
label: Plugins
|
||||
position: 2
|
||||
link:
|
||||
type: doc
|
||||
id: api/plugins/plugins-overview # Dogfood using a "qualified id"
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
sidebar_position: 0
|
||||
id: plugins-overview
|
||||
sidebar_label: Plugins overview
|
||||
slug: /api/plugins
|
||||
---
|
||||
|
||||
# Docusaurus plugins
|
||||
|
||||
We provide official Docusaurus plugins.
|
||||
|
||||
## Content plugins {#content-plugins}
|
||||
|
||||
These plugins are responsible for loading your site's content, and creating pages for your theme to render.
|
||||
|
||||
- [@docusaurus/plugin-content-docs](./plugin-content-docs.mdx)
|
||||
- [@docusaurus/plugin-content-blog](./plugin-content-blog.mdx)
|
||||
- [@docusaurus/plugin-content-pages](./plugin-content-pages.mdx)
|
||||
|
||||
## Behavior plugins {#behavior-plugins}
|
||||
|
||||
These plugins will add a useful behavior to your Docusaurus site.
|
||||
|
||||
- [@docusaurus/plugin-debug](./plugin-debug.mdx)
|
||||
- [@docusaurus/plugin-sitemap](./plugin-sitemap.mdx)
|
||||
- [@docusaurus/plugin-pwa](./plugin-pwa.mdx)
|
||||
- [@docusaurus/plugin-client-redirects](./plugin-client-redirects.mdx)
|
||||
- [@docusaurus/plugin-ideal-image](./plugin-ideal-image.mdx)
|
||||
- [@docusaurus/plugin-google-analytics](./plugin-google-analytics.mdx)
|
||||
- [@docusaurus/plugin-google-gtag](./plugin-google-gtag.mdx)
|
|
@ -0,0 +1,127 @@
|
|||
---
|
||||
sidebar_position: 4
|
||||
slug: /api/plugins/@docusaurus/plugin-client-redirects
|
||||
---
|
||||
|
||||
# 📦 plugin-client-redirects
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
Docusaurus Plugin to generate **client-side redirects**.
|
||||
|
||||
This plugin will write additional HTML pages to your static site that redirect the user to your existing Docusaurus pages with JavaScript.
|
||||
|
||||
:::warning production only
|
||||
|
||||
This plugin is always inactive in development and **only active in production** because it works on the build output.
|
||||
|
||||
:::
|
||||
|
||||
:::warning
|
||||
|
||||
It is better to use server-side redirects whenever possible.
|
||||
|
||||
Before using this plugin, you should look if your hosting provider doesn't offer this feature.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-client-redirects
|
||||
```
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `fromExtensions` | `string[]` | `[]` | The extensions to be removed from the route after redirecting. |
|
||||
| `toExtensions` | `string[]` | `[]` | The extensions to be appended to the route after redirecting. |
|
||||
| `redirects` | <code>[RedirectRule](#RedirectRule)[]</code> | `[]` | The list of redirect rules. |
|
||||
| `createRedirects` | <code>[CreateRedirectsFn](#CreateRedirectsFn)</code> | `undefined` | A callback to create a redirect rule. Docusaurus query this callback against every path it has created, and use its return value to output more paths. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
This plugin will also read the [`siteConfig.onDuplicateRoutes`](../docusaurus.config.js.mdx#onDuplicateRoutes) config to adjust its logging level when multiple files will be emitted to the same location.
|
||||
|
||||
:::
|
||||
|
||||
### Types {#types}
|
||||
|
||||
#### `RedirectRule` {#RedirectRule}
|
||||
|
||||
```ts
|
||||
type RedirectRule = {
|
||||
to: string;
|
||||
from: string | string[];
|
||||
};
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
The idea of "from" and "to" is central in this plugin. "From" means a path that you want to _create_, i.e. an extra HTML file that will be written; "to" means a path to want to redirect _to_, usually a route that Docusaurus already knows about.
|
||||
|
||||
This is why you can have multiple "from" for the same "to": we will create multiple HTML files that all redirect to the same destination. On the other hand, one "from" can never have more than one "to": the written HTML file needs to have a determinate destination.
|
||||
|
||||
:::
|
||||
|
||||
#### `CreateRedirectsFn` {#CreateRedirectsFn}
|
||||
|
||||
```ts
|
||||
// The parameter `path` is a route that Docusaurus has already created. It can
|
||||
// be seen as the "to", and your return value is the "from". Returning a falsy
|
||||
// value will not create any redirect pages for this particular path.
|
||||
type CreateRedirectsFn = (path: string) => string[] | string | null | undefined;
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
Here's an example configuration:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-client-redirects',
|
||||
// highlight-start
|
||||
{
|
||||
fromExtensions: ['html', 'htm'], // /myPage.html -> /myPage
|
||||
toExtensions: ['exe', 'zip'], // /myAsset -> /myAsset.zip (if latter exists)
|
||||
redirects: [
|
||||
// /docs/oldDoc -> /docs/newDoc
|
||||
{
|
||||
to: '/docs/newDoc',
|
||||
from: '/docs/oldDoc',
|
||||
},
|
||||
// Redirect from multiple old paths to the new path
|
||||
{
|
||||
to: '/docs/newDoc2',
|
||||
from: ['/docs/oldDocFrom2019', '/docs/legacyDocFrom2016'],
|
||||
},
|
||||
],
|
||||
createRedirects(existingPath) {
|
||||
if (existingPath.includes('/community')) {
|
||||
// Redirect from /docs/team/X to /community/X and /docs/support/X to /community/X
|
||||
return [
|
||||
existingPath.replace('/community', '/docs/team'),
|
||||
existingPath.replace('/community', '/docs/support'),
|
||||
];
|
||||
}
|
||||
return undefined; // Return a falsy value: no redirect created
|
||||
},
|
||||
},
|
||||
// highlight-end
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
|
@ -0,0 +1,307 @@
|
|||
---
|
||||
sidebar_position: 2
|
||||
slug: /api/plugins/@docusaurus/plugin-content-blog
|
||||
---
|
||||
|
||||
# 📦 plugin-content-blog
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
Provides the [Blog](blog.mdx) feature and is the default blog plugin for Docusaurus.
|
||||
|
||||
:::warning some features production only
|
||||
|
||||
The [feed feature](../../blog.mdx#feed) works by extracting the build output, and is **only active in production**.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-content-blog
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `path` | `string` | `'blog'` | Path to the blog content directory on the file system, relative to site dir. |
|
||||
| `editUrl` | <code>string \| [EditUrlFn](#EditUrlFn)</code> | `undefined` | Base URL to edit your site. The final URL is computed by `editUrl + relativePostPath`. Using a function allows more nuanced control for each file. Omitting this variable entirely will disable edit links. |
|
||||
| `editLocalizedFiles` | `boolean` | `false` | The edit URL will target the localized file, instead of the original unlocalized file. Ignored when `editUrl` is a function. |
|
||||
| `blogTitle` | `string` | `'Blog'` | Blog page title for better SEO. |
|
||||
| `blogDescription` | `string` | `'Blog'` | Blog page meta description for better SEO. |
|
||||
| `blogSidebarCount` | <code>number \| 'ALL'</code> | `5` | Number of blog post elements to show in the blog sidebar. `'ALL'` to show all blog posts; `0` to disable. |
|
||||
| `blogSidebarTitle` | `string` | `'Recent posts'` | Title of the blog sidebar. |
|
||||
| `routeBasePath` | `string` | `'blog'` | URL route for the blog section of your site. **DO NOT** include a trailing slash. Use `/` to put the blog at root path. |
|
||||
| `tagsBasePath` | `string` | `'tags'` | URL route for the tags section of your blog. Will be appended to `routeBasePath`. |
|
||||
| `pageBasePath` | `string` | `'page'` | URL route for the pages section of your blog. Will be appended to `routeBasePath`. |
|
||||
| `archiveBasePath` | <code>string \| null</code> | `'archive'` | URL route for the archive section of your blog. Will be appended to `routeBasePath`. **DO NOT** include a trailing slash. Use `null` to disable generation of archive. |
|
||||
| `include` | `string[]` | `['**/*.{md,mdx}']` | Array of glob patterns matching Markdown files to be built, relative to the content path. |
|
||||
| `exclude` | `string[]` | _See example configuration_ | Array of glob patterns matching Markdown files to be excluded. Serves as refinement based on the `include` option. |
|
||||
| `postsPerPage` | <code>number \| 'ALL'</code> | `10` | Number of posts to show per page in the listing page. Use `'ALL'` to display all posts on one listing page. |
|
||||
| `blogListComponent` | `string` | `'@theme/BlogListPage'` | Root component of the blog listing page. |
|
||||
| `blogPostComponent` | `string` | `'@theme/BlogPostPage'` | Root component of each blog post page. |
|
||||
| `blogTagsListComponent` | `string` | `'@theme/BlogTagsListPage'` | Root component of the tags list page. |
|
||||
| `blogTagsPostsComponent` | `string` | `'@theme/BlogTagsPostsPage'` | Root component of the "posts containing tag" page. |
|
||||
| `blogArchiveComponent` | `string` | `'@theme/BlogArchivePage'` | Root component of the blog archive page. |
|
||||
| `remarkPlugins` | `any[]` | `[]` | Remark plugins passed to MDX. |
|
||||
| `rehypePlugins` | `any[]` | `[]` | Rehype plugins passed to MDX. |
|
||||
| `beforeDefaultRemarkPlugins` | `any[]` | `[]` | Custom Remark plugins passed to MDX before the default Docusaurus Remark plugins. |
|
||||
| `beforeDefaultRehypePlugins` | `any[]` | `[]` | Custom Rehype plugins passed to MDX before the default Docusaurus Rehype plugins. |
|
||||
| `truncateMarker` | `RegExp` | `/<!--\s*truncate\s*-->/` \| `\{\/\*\s*truncate\s*\*\/\}/` | Truncate marker marking where the summary ends. |
|
||||
| `showReadingTime` | `boolean` | `true` | Show estimated reading time for the blog post. |
|
||||
| `readingTime` | `ReadingTimeFn` | The default reading time | A callback to customize the reading time number displayed. |
|
||||
| `authorsMapPath` | `string` | `'authors.yml'` | Path to the authors map file, relative to the blog content directory. |
|
||||
| `feedOptions` | _See below_ | `{type: ['rss', 'atom']}` | Blog feed. |
|
||||
| `feedOptions.type` | <code>[FeedType](#FeedType) \| [FeedType](#FeedType)[] \| 'all' \| null</code> | **Required** | Type of feed to be generated. Use `null` to disable generation. |
|
||||
| `feedOptions.createFeedItems` | <code>[CreateFeedItemsFn](#CreateFeedItemsFn) \| undefined</code> | `undefined` | An optional function which can be used to transform and / or filter the items in the feed. |
|
||||
| `feedOptions.limit` | `number \| null \| false` | `20` | Limits the feed to the specified number of posts, `false` or `null` for all entries. Defaults to `20`. |
|
||||
| `feedOptions.title` | `string` | `siteConfig.title` | Title of the feed. |
|
||||
| `feedOptions.description` | `string` | <code>\`$\{siteConfig.title} Blog\`</code> | Description of the feed. |
|
||||
| `feedOptions.copyright` | `string` | `undefined` | Copyright message. |
|
||||
| `feedOptions.language` | `string` (See [documentation](http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes) for possible values) | `undefined` | Language metadata of the feed. |
|
||||
| `sortPosts` | <code>'descending' \| 'ascending' </code> | `'descending'` | Governs the direction of blog post sorting. |
|
||||
| `processBlogPosts` | <code>[ProcessBlogPostsFn](#ProcessBlogPostsFn)</code> | `undefined` | An optional function which can be used to transform blog posts (filter, modify, delete, etc...). |
|
||||
| `showLastUpdateAuthor` | `boolean` | `false` | Whether to display the author who last updated the blog post. |
|
||||
| `showLastUpdateTime` | `boolean` | `false` | Whether to display the last date the blog post was updated. This requires access to git history during the build, so will not work correctly with shallow clones (a common default for CI systems). With GitHub `actions/checkout`, use`fetch-depth: 0`. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Types {#types}
|
||||
|
||||
#### `EditUrlFn` {#EditUrlFn}
|
||||
|
||||
```ts
|
||||
type EditUrlFunction = (params: {
|
||||
blogDirPath: string;
|
||||
blogPath: string;
|
||||
permalink: string;
|
||||
locale: string;
|
||||
}) => string | undefined;
|
||||
```
|
||||
|
||||
#### `ReadingTimeFn` {#ReadingTimeFn}
|
||||
|
||||
```ts
|
||||
type ReadingTimeOptions = {
|
||||
wordsPerMinute: number;
|
||||
wordBound: (char: string) => boolean;
|
||||
};
|
||||
|
||||
type ReadingTimeCalculator = (params: {
|
||||
content: string;
|
||||
frontMatter?: BlogPostFrontMatter & Record<string, unknown>;
|
||||
options?: ReadingTimeOptions;
|
||||
}) => number;
|
||||
|
||||
type ReadingTimeFn = (params: {
|
||||
content: string;
|
||||
frontMatter: BlogPostFrontMatter & Record<string, unknown>;
|
||||
defaultReadingTime: ReadingTimeCalculator;
|
||||
}) => number | undefined;
|
||||
```
|
||||
|
||||
#### `FeedType` {#FeedType}
|
||||
|
||||
```ts
|
||||
type FeedType = 'rss' | 'atom' | 'json';
|
||||
```
|
||||
|
||||
#### `CreateFeedItemsFn` {#CreateFeedItemsFn}
|
||||
|
||||
```ts
|
||||
type CreateFeedItemsFn = (params: {
|
||||
blogPosts: BlogPost[];
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
defaultCreateFeedItemsFn: CreateFeedItemsFn;
|
||||
}) => Promise<BlogFeedItem[]>;
|
||||
```
|
||||
|
||||
#### `ProcessBlogPostsFn` {#ProcessBlogPostsFn}
|
||||
|
||||
```ts
|
||||
type ProcessBlogPostsFn = (params: {
|
||||
blogPosts: BlogPost[];
|
||||
}) => Promise<void | BlogPost[]>;
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: blog
|
||||
// Plugin Options: @docusaurus/plugin-content-blog
|
||||
|
||||
const config = {
|
||||
path: 'blog',
|
||||
// Simple use-case: string editUrl
|
||||
// editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
|
||||
// Advanced use-case: functional editUrl
|
||||
editUrl: ({locale, blogDirPath, blogPath, permalink}) =>
|
||||
`https://github.com/facebook/docusaurus/edit/main/website/${blogDirPath}/${blogPath}`,
|
||||
editLocalizedFiles: false,
|
||||
blogTitle: 'Blog title',
|
||||
blogDescription: 'Blog',
|
||||
blogSidebarCount: 5,
|
||||
blogSidebarTitle: 'All our posts',
|
||||
routeBasePath: 'blog',
|
||||
include: ['**/*.{md,mdx}'],
|
||||
exclude: [
|
||||
'**/_*.{js,jsx,ts,tsx,md,mdx}',
|
||||
'**/_*/**',
|
||||
'**/*.test.{js,jsx,ts,tsx}',
|
||||
'**/__tests__/**',
|
||||
],
|
||||
postsPerPage: 10,
|
||||
blogListComponent: '@theme/BlogListPage',
|
||||
blogPostComponent: '@theme/BlogPostPage',
|
||||
blogTagsListComponent: '@theme/BlogTagsListPage',
|
||||
blogTagsPostsComponent: '@theme/BlogTagsPostsPage',
|
||||
remarkPlugins: [require('./my-remark-plugin')],
|
||||
rehypePlugins: [],
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
truncateMarker: /<!--\s*(truncate)\s*-->/,
|
||||
showReadingTime: true,
|
||||
feedOptions: {
|
||||
type: '',
|
||||
title: '',
|
||||
description: '',
|
||||
copyright: '',
|
||||
language: undefined,
|
||||
createFeedItems: async (params) => {
|
||||
const {blogPosts, defaultCreateFeedItems, ...rest} = params;
|
||||
return defaultCreateFeedItems({
|
||||
// keep only the 10 most recent blog posts in the feed
|
||||
blogPosts: blogPosts.filter((item, index) => index < 10),
|
||||
...rest,
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## Markdown front matter {#markdown-front-matter}
|
||||
|
||||
Markdown documents can use the following Markdown [front matter](../../guides/markdown-features/markdown-features-intro.mdx#front-matter) metadata fields, enclosed by a line `---` on either side.
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `authors` | `Authors` | `undefined` | List of blog post authors (or unique author). Read the [`authors` guide](../../blog.mdx#blog-post-authors) for more explanations. Prefer `authors` over the `author_*` front matter fields, even for single author blog posts. |
|
||||
| `author` | `string` | `undefined` | ⚠️ Prefer using `authors`. The blog post author's name. |
|
||||
| `author_url` | `string` | `undefined` | ⚠️ Prefer using `authors`. The URL that the author's name will be linked to. This could be a GitHub, Twitter, Facebook profile URL, etc. |
|
||||
| `author_image_url` | `string` | `undefined` | ⚠️ Prefer using `authors`. The URL to the author's thumbnail image. |
|
||||
| `author_title` | `string` | `undefined` | ⚠️ Prefer using `authors`. A description of the author. |
|
||||
| `title` | `string` | Markdown title | The blog post title. |
|
||||
| `date` | `string` | File name or file creation time | The blog post creation date. If not specified, this can be extracted from the file or folder name, e.g, `2021-04-15-blog-post.mdx`, `2021-04-15-blog-post/index.mdx`, `2021/04/15/blog-post.mdx`. Otherwise, it is the Markdown file creation time. |
|
||||
| `tags` | `Tag[]` | `undefined` | A list of strings or objects of two string fields `label` and `permalink` to tag to your post. |
|
||||
| `draft` | `boolean` | `false` | Draft blog posts will only be available during development. |
|
||||
| `unlisted` | `boolean` | `false` | Unlisted blog posts will be available in both development and production. They will be "hidden" in production, not indexed, excluded from sitemaps, and can only be accessed by users having a direct link. |
|
||||
| `hide_table_of_contents` | `boolean` | `false` | Whether to hide the table of contents to the right. |
|
||||
| `toc_min_heading_level` | `number` | `2` | The minimum heading level shown in the table of contents. Must be between 2 and 6 and lower or equal to the max value. |
|
||||
| `toc_max_heading_level` | `number` | `3` | The max heading level shown in the table of contents. Must be between 2 and 6. |
|
||||
| `keywords` | `string[]` | `undefined` | Keywords meta tag, which will become the `<meta name="keywords" content="keyword1,keyword2,..."/>` in `<head>`, used by search engines. |
|
||||
| `description` | `string` | The first line of Markdown content | The description of your document, which will become the `<meta name="description" content="..."/>` and `<meta property="og:description" content="..."/>` in `<head>`, used by search engines. |
|
||||
| `image` | `string` | `undefined` | Cover or thumbnail image that will be used as the `<meta property="og:image" content="..."/>` in the `<head>`, enhancing link previews on social media and messaging platforms. |
|
||||
| `slug` | `string` | File path | Allows to customize the blog post URL (`/<routeBasePath>/<slug>`). Support multiple patterns: `slug: my-blog-post`, `slug: /my/path/to/blog/post`, slug: `/`. |
|
||||
| `last_update` | `FrontMatterLastUpdate` | `undefined` | Allows overriding the last update author/date. Date can be any [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse). |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
```ts
|
||||
type FrontMatterLastUpdate = {date?: string; author?: string};
|
||||
|
||||
type Tag = string | {label: string; permalink: string};
|
||||
|
||||
// An author key references an author from the global plugin authors.yml file
|
||||
type AuthorKey = string;
|
||||
|
||||
type Author = {
|
||||
key?: AuthorKey;
|
||||
name: string;
|
||||
title?: string;
|
||||
url?: string;
|
||||
image_url?: string;
|
||||
};
|
||||
|
||||
// The front matter authors field allows various possible shapes
|
||||
type Authors = AuthorKey | Author | (AuthorKey | Author)[];
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```md
|
||||
---
|
||||
title: Welcome Docusaurus
|
||||
authors:
|
||||
- slorber
|
||||
- yangshun
|
||||
- name: Joel Marcey
|
||||
title: Co-creator of Docusaurus 1
|
||||
url: https://github.com/JoelMarcey
|
||||
image_url: https://github.com/JoelMarcey.png
|
||||
tags: [hello, docusaurus-v2]
|
||||
description: This is my first post on Docusaurus.
|
||||
image: https://i.imgur.com/mErPwqL.png
|
||||
hide_table_of_contents: false
|
||||
---
|
||||
|
||||
A Markdown blog post
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.mdx) first.
|
||||
|
||||
### Translation files location {#translation-files-location}
|
||||
|
||||
- **Base path**: `website/i18n/[locale]/docusaurus-plugin-content-blog`
|
||||
- **Multi-instance path**: `website/i18n/[locale]/docusaurus-plugin-content-blog-[pluginId]`
|
||||
- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.mdx#docusaurus-write-translations-sitedir)
|
||||
- **Markdown files**: `website/i18n/[locale]/docusaurus-plugin-content-blog`
|
||||
|
||||
### Example file-system structure {#example-file-system-structure}
|
||||
|
||||
```bash
|
||||
website/i18n/[locale]/docusaurus-plugin-content-blog
|
||||
│
|
||||
│ # translations for website/blog
|
||||
├── authors.yml
|
||||
├── first-blog-post.md
|
||||
├── second-blog-post.md
|
||||
│
|
||||
│ # translations for the plugin options that will be rendered
|
||||
└── options.json
|
||||
```
|
|
@ -0,0 +1,368 @@
|
|||
---
|
||||
sidebar_position: 1
|
||||
slug: /api/plugins/@docusaurus/plugin-content-docs
|
||||
---
|
||||
|
||||
# 📦 plugin-content-docs
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
Provides the [Docs](../../guides/docs/docs-introduction.mdx) functionality and is the default docs plugin for Docusaurus.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-content-docs
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `path` | `string` | `'docs'` | Path to the docs content directory on the file system, relative to site directory. |
|
||||
| `editUrl` | <code>string \| [EditUrlFunction](#EditUrlFunction)</code> | `undefined` | Base URL to edit your site. The final URL is computed by `editUrl + relativeDocPath`. Using a function allows more nuanced control for each file. Omitting this variable entirely will disable edit links. |
|
||||
| `editLocalizedFiles` | `boolean` | `false` | The edit URL will target the localized file, instead of the original unlocalized file. Ignored when `editUrl` is a function. |
|
||||
| `editCurrentVersion` | `boolean` | `false` | The edit URL will always target the current version doc instead of older versions. Ignored when `editUrl` is a function. |
|
||||
| `routeBasePath` | `string` | `'docs'` | URL route for the docs section of your site. **DO NOT** include a trailing slash. Use `/` for shipping docs without base path. |
|
||||
| `tagsBasePath` | `string` | `'tags'` | URL route for the tags list page of your site. It is prepended to the `routeBasePath`. |
|
||||
| `include` | `string[]` | `['**/*.{md,mdx}']` | Array of glob patterns matching Markdown files to be built, relative to the content path. |
|
||||
| `exclude` | `string[]` | _See example configuration_ | Array of glob patterns matching Markdown files to be excluded. Serves as refinement based on the `include` option. |
|
||||
| `sidebarPath` | <code>false \| string</code> | `undefined` | Path to sidebar configuration. Use `false` to disable sidebars, or `undefined` to create a fully autogenerated sidebar. |
|
||||
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. See also [Collapsible categories](/docs/sidebar/items#collapsible-categories) |
|
||||
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. See also [Expanded categories by default](/docs/sidebar/items#expanded-categories-by-default) |
|
||||
| `sidebarItemsGenerator` | <code>[SidebarGenerator](#SidebarGenerator)</code> | _Omitted_ | Function used to replace the sidebar items of type `'autogenerated'` with real sidebar items (docs, categories, links...). See also [Customize the sidebar items generator](/docs/sidebar/autogenerated#customize-the-sidebar-items-generator) |
|
||||
| `numberPrefixParser` | <code>boolean \| [PrefixParser](#PrefixParser)</code> | _Omitted_ | Custom parsing logic to extract number prefixes from file names. Use `false` to disable this behavior and leave the docs untouched, and `true` to use the default parser. See also [Using number prefixes](/docs/sidebar/autogenerated#using-number-prefixes) |
|
||||
| `docsRootComponent` | `string` | `'@theme/DocsRoot'` | Parent component of all the docs plugin pages (including all versions). Stays mounted when navigation between docs pages and versions. |
|
||||
| `docVersionRootComponent` | `string` | `'@theme/DocVersionLayout'` | Parent component of all docs pages of an individual version (doc pages with sidebars, tags pages). Stays mounted when navigation between pages of that specific version. |
|
||||
| `docRootComponent` | `string` | `'@theme/DocPage'` | Parent component of all doc pages with sidebars (regular docs pages, category generated index pages). Stays mounted when navigation between such pages. |
|
||||
| `docItemComponent` | `string` | `'@theme/DocItem'` | Main doc container, with TOC, pagination, etc. |
|
||||
| `docTagsListComponent` | `string` | `'@theme/DocTagsListPage'` | Root component of the tags list page |
|
||||
| `docTagDocListComponent` | `string` | `'@theme/DocTagDocListPage'` | Root component of the "docs containing tag X" page. |
|
||||
| `docCategoryGeneratedIndexComponent` | `string` | `'@theme/DocCategoryGeneratedIndexPage'` | Root component of the generated category index page. |
|
||||
| `remarkPlugins` | `any[]` | `[]` | Remark plugins passed to MDX. |
|
||||
| `rehypePlugins` | `any[]` | `[]` | Rehype plugins passed to MDX. |
|
||||
| `beforeDefaultRemarkPlugins` | `any[]` | `[]` | Custom Remark plugins passed to MDX before the default Docusaurus Remark plugins. |
|
||||
| `beforeDefaultRehypePlugins` | `any[]` | `[]` | Custom Rehype plugins passed to MDX before the default Docusaurus Rehype plugins. |
|
||||
| `showLastUpdateAuthor` | `boolean` | `false` | Whether to display the author who last updated the doc. |
|
||||
| `showLastUpdateTime` | `boolean` | `false` | Whether to display the last date the doc was updated. This requires access to git history during the build, so will not work correctly with shallow clones (a common default for CI systems). With GitHub `actions/checkout`, use`fetch-depth: 0`. |
|
||||
| `breadcrumbs` | `boolean` | `true` | Enable or disable the breadcrumbs on doc pages. |
|
||||
| `disableVersioning` | `boolean` | `false` | Explicitly disable versioning even when multiple versions exist. This will make the site only include the current version. Will error if `includeCurrentVersion: false` and `disableVersioning: true`. |
|
||||
| `includeCurrentVersion` | `boolean` | `true` | Include the current version of your docs. |
|
||||
| `lastVersion` | `string` | First version in `versions.json` | The version navigated to in priority and displayed by default for docs navbar items. |
|
||||
| `onlyIncludeVersions` | `string[]` | All versions available | Only include a subset of all available versions. |
|
||||
| `versions` | <code>[VersionsConfig](#VersionsConfig)</code> | `{}` | Independent customization of each version's properties. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Types {#types}
|
||||
|
||||
#### `EditUrlFunction` {#EditUrlFunction}
|
||||
|
||||
```ts
|
||||
type EditUrlFunction = (params: {
|
||||
version: string;
|
||||
versionDocsDirPath: string;
|
||||
docPath: string;
|
||||
permalink: string;
|
||||
locale: string;
|
||||
}) => string | undefined;
|
||||
```
|
||||
|
||||
#### `PrefixParser` {#PrefixParser}
|
||||
|
||||
```ts
|
||||
type PrefixParser = (filename: string) => {
|
||||
filename: string;
|
||||
numberPrefix?: number;
|
||||
};
|
||||
```
|
||||
|
||||
#### `SidebarGenerator` {#SidebarGenerator}
|
||||
|
||||
```ts
|
||||
type SidebarGenerator = (generatorArgs: {
|
||||
/** The sidebar item with type "autogenerated" to be transformed. */
|
||||
item: {type: 'autogenerated'; dirName: string};
|
||||
/** Useful metadata for the version this sidebar belongs to. */
|
||||
version: {contentPath: string; versionName: string};
|
||||
/** All the docs of that version (unfiltered). */
|
||||
docs: {
|
||||
id: string;
|
||||
title: string;
|
||||
frontMatter: DocFrontMatter & Record<string, unknown>;
|
||||
source: string;
|
||||
sourceDirName: string;
|
||||
sidebarPosition?: number | undefined;
|
||||
}[];
|
||||
/** Number prefix parser configured for this plugin. */
|
||||
numberPrefixParser: PrefixParser;
|
||||
/** The default category index matcher which you can override. */
|
||||
isCategoryIndex: CategoryIndexMatcher;
|
||||
/**
|
||||
* key is the path relative to the doc content directory, value is the
|
||||
* category metadata file's content.
|
||||
*/
|
||||
categoriesMetadata: {[filePath: string]: CategoryMetadata};
|
||||
/**
|
||||
* Useful to re-use/enhance the default sidebar generation logic from
|
||||
* Docusaurus.
|
||||
*/
|
||||
defaultSidebarItemsGenerator: SidebarGenerator;
|
||||
// Returns an array of sidebar items — same as what you can declare in
|
||||
// sidebars.js, except for shorthands. See https://docusaurus.io/docs/sidebar/items
|
||||
}) => Promise<SidebarItem[]>;
|
||||
|
||||
type CategoryIndexMatcher = (param: {
|
||||
/** The file name, without extension */
|
||||
fileName: string;
|
||||
/**
|
||||
* The list of directories, from lowest level to highest.
|
||||
* If there's no dir name, directories is ['.']
|
||||
*/
|
||||
directories: string[];
|
||||
/** The extension, with a leading dot */
|
||||
extension: string;
|
||||
}) => boolean;
|
||||
```
|
||||
|
||||
#### `VersionsConfig` {#VersionsConfig}
|
||||
|
||||
```ts
|
||||
type VersionConfig = {
|
||||
/**
|
||||
* The base path of the version, will be appended to `baseUrl` +
|
||||
* `routeBasePath`.
|
||||
*/
|
||||
path?: string;
|
||||
/** The label of the version to be used in badges, dropdowns, etc. */
|
||||
label?: string;
|
||||
/** The banner to show at the top of a doc of that version. */
|
||||
banner?: 'none' | 'unreleased' | 'unmaintained';
|
||||
/** Show a badge with the version label at the top of each doc. */
|
||||
badge?: boolean;
|
||||
/** Prevents search engines from indexing this version */
|
||||
noIndex?: boolean;
|
||||
/** Add a custom class name to the <html> element of each doc */
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type VersionsConfig = {[versionName: string]: VersionConfig};
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: docs
|
||||
// Plugin Options: @docusaurus/plugin-content-docs
|
||||
|
||||
const config = {
|
||||
path: 'docs',
|
||||
breadcrumbs: true,
|
||||
// Simple use-case: string editUrl
|
||||
// editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
|
||||
// Advanced use-case: functional editUrl
|
||||
editUrl: ({versionDocsDirPath, docPath}) =>
|
||||
`https://github.com/facebook/docusaurus/edit/main/website/${versionDocsDirPath}/${docPath}`,
|
||||
editLocalizedFiles: false,
|
||||
editCurrentVersion: false,
|
||||
routeBasePath: 'docs',
|
||||
include: ['**/*.md', '**/*.mdx'],
|
||||
exclude: [
|
||||
'**/_*.{js,jsx,ts,tsx,md,mdx}',
|
||||
'**/_*/**',
|
||||
'**/*.test.{js,jsx,ts,tsx}',
|
||||
'**/__tests__/**',
|
||||
],
|
||||
sidebarPath: 'sidebars.js',
|
||||
async sidebarItemsGenerator({
|
||||
defaultSidebarItemsGenerator,
|
||||
numberPrefixParser,
|
||||
item,
|
||||
version,
|
||||
docs,
|
||||
isCategoryIndex,
|
||||
}) {
|
||||
// Use the provided data to generate a custom sidebar slice
|
||||
return [
|
||||
{type: 'doc', id: 'intro'},
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Tutorials',
|
||||
items: [
|
||||
{type: 'doc', id: 'tutorial1'},
|
||||
{type: 'doc', id: 'tutorial2'},
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
numberPrefixParser(filename) {
|
||||
// Implement your own logic to extract a potential number prefix
|
||||
const numberPrefix = findNumberPrefix(filename);
|
||||
// Prefix found: return it with the cleaned filename
|
||||
if (numberPrefix) {
|
||||
return {
|
||||
numberPrefix,
|
||||
filename: filename.replace(prefix, ''),
|
||||
};
|
||||
}
|
||||
// No number prefix found
|
||||
return {numberPrefix: undefined, filename};
|
||||
},
|
||||
docsRootComponent: '@theme/DocsRoot',
|
||||
docVersionRootComponent: '@theme/DocVersionRoot',
|
||||
docRootComponent: '@theme/DocRoot',
|
||||
docItemComponent: '@theme/DocItem',
|
||||
remarkPlugins: [require('./my-remark-plugin')],
|
||||
rehypePlugins: [],
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
showLastUpdateAuthor: false,
|
||||
showLastUpdateTime: false,
|
||||
disableVersioning: false,
|
||||
includeCurrentVersion: true,
|
||||
lastVersion: undefined,
|
||||
versions: {
|
||||
current: {
|
||||
label: 'Android SDK v2.0.0 (WIP)',
|
||||
path: 'android-2.0.0',
|
||||
banner: 'none',
|
||||
},
|
||||
'1.0.0': {
|
||||
label: 'Android SDK v1.0.0',
|
||||
path: 'android-1.0.0',
|
||||
banner: 'unmaintained',
|
||||
},
|
||||
},
|
||||
onlyIncludeVersions: ['current', '1.0.0', '2.0.0'],
|
||||
};
|
||||
```
|
||||
|
||||
## Markdown front matter {#markdown-front-matter}
|
||||
|
||||
Markdown documents can use the following Markdown [front matter](../../guides/markdown-features/markdown-features-intro.mdx#front-matter) metadata fields, enclosed by a line `---` on either side.
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `id` | `string` | file path (including folders, without the extension) | A unique document ID. |
|
||||
| `title` | `string` | Markdown title or `id` | The text title of your document. Used for the page metadata and as a fallback value in multiple places (sidebar, next/previous buttons...). Automatically added at the top of your doc if it does not contain any Markdown title. |
|
||||
| `pagination_label` | `string` | `sidebar_label` or `title` | The text used in the document next/previous buttons for this document. |
|
||||
| `sidebar_label` | `string` | `title` | The text shown in the document sidebar for this document. |
|
||||
| `sidebar_position` | `number` | Default ordering | Controls the position of a doc inside the generated sidebar slice when using `autogenerated` sidebar items. See also [Autogenerated sidebar metadata](/docs/sidebar/autogenerated#autogenerated-sidebar-metadata). |
|
||||
| `sidebar_class_name` | `string` | `undefined` | Gives the corresponding sidebar label a special class name when using autogenerated sidebars. |
|
||||
| `sidebar_custom_props` | `object` | `undefined` | Assign [custom props](../../guides/docs/sidebar/index.mdx#passing-custom-props) to the sidebar item referencing this doc |
|
||||
| `displayed_sidebar` | `string` | `undefined` | Force the display of a given sidebar when browsing the current document. Read the [multiple sidebars guide](../../guides/docs/sidebar/multiple-sidebars.mdx) for details. |
|
||||
| `hide_title` | `boolean` | `false` | Whether to hide the title at the top of the doc. It only hides a title declared through the front matter, and have no effect on a Markdown title at the top of your document. |
|
||||
| `hide_table_of_contents` | `boolean` | `false` | Whether to hide the table of contents to the right. |
|
||||
| `toc_min_heading_level` | `number` | `2` | The minimum heading level shown in the table of contents. Must be between 2 and 6 and lower or equal to the max value. |
|
||||
| `toc_max_heading_level` | `number` | `3` | The max heading level shown in the table of contents. Must be between 2 and 6. |
|
||||
| `pagination_next` | <code>string \| null</code> | Next doc in the sidebar | The ID of the documentation you want the "Next" pagination to link to. Use `null` to disable showing "Next" for this page. |
|
||||
| `pagination_prev` | <code>string \| null</code> | Previous doc in the sidebar | The ID of the documentation you want the "Previous" pagination to link to. Use `null` to disable showing "Previous" for this page. |
|
||||
| `parse_number_prefixes` | `boolean` | `numberPrefixParser` plugin option | Whether number prefix parsing is disabled on this doc. See also [Using number prefixes](/docs/sidebar/autogenerated#using-number-prefixes). |
|
||||
| `custom_edit_url` | <code>string \| null</code> | Computed using the `editUrl` plugin option | The URL for editing this document. Use `null` to disable showing "Edit this page" for this page. |
|
||||
| `keywords` | `string[]` | `undefined` | Keywords meta tag for the document page, for search engines. |
|
||||
| `description` | `string` | The first line of Markdown content | The description of your document, which will become the `<meta name="description" content="..."/>` and `<meta property="og:description" content="..."/>` in `<head>`, used by search engines. |
|
||||
| `image` | `string` | `undefined` | Cover or thumbnail image that will be used as the `<meta property="og:image" content="..."/>` in the `<head>`, enhancing link previews on social media and messaging platforms. |
|
||||
| `slug` | `string` | File path | Allows to customize the document URL (`/<routeBasePath>/<slug>`). Support multiple patterns: `slug: my-doc`, `slug: /my/path/myDoc`, `slug: /`. |
|
||||
| `tags` | `Tag[]` | `undefined` | A list of strings or objects of two string fields `label` and `permalink` to tag to your docs. |
|
||||
| `draft` | `boolean` | `false` | Draft documents will only be available during development. |
|
||||
| `unlisted` | `boolean` | `false` | Unlisted documents will be available in both development and production. They will be "hidden" in production, not indexed, excluded from sitemaps, and can only be accessed by users having a direct link. |
|
||||
| `last_update` | `FrontMatterLastUpdate` | `undefined` | Allows overriding the last update author/date. Date can be any [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse). |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
```ts
|
||||
type FrontMatterLastUpdate = {date?: string; author?: string};
|
||||
|
||||
type Tag = string | {label: string; permalink: string};
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```md
|
||||
---
|
||||
id: doc-markdown
|
||||
title: Docs Markdown Features
|
||||
hide_title: false
|
||||
hide_table_of_contents: false
|
||||
sidebar_label: Markdown
|
||||
sidebar_position: 3
|
||||
pagination_label: Markdown features
|
||||
custom_edit_url: https://github.com/facebook/docusaurus/edit/main/docs/api-doc-markdown.md
|
||||
description: How do I find you when I cannot solve this problem
|
||||
keywords:
|
||||
- docs
|
||||
- docusaurus
|
||||
image: https://i.imgur.com/mErPwqL.png
|
||||
slug: /myDoc
|
||||
last_update:
|
||||
date: 1/1/2000
|
||||
author: custom author name
|
||||
---
|
||||
|
||||
# Markdown Features
|
||||
|
||||
My Document Markdown content
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.mdx) first.
|
||||
|
||||
### Translation files location {#translation-files-location}
|
||||
|
||||
- **Base path**: `website/i18n/[locale]/docusaurus-plugin-content-docs`
|
||||
- **Multi-instance path**: `website/i18n/[locale]/docusaurus-plugin-content-docs-[pluginId]`
|
||||
- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.mdx#docusaurus-write-translations-sitedir)
|
||||
- **Markdown files**: `website/i18n/[locale]/docusaurus-plugin-content-docs/[versionName]`
|
||||
|
||||
### Example file-system structure {#example-file-system-structure}
|
||||
|
||||
```bash
|
||||
website/i18n/[locale]/docusaurus-plugin-content-docs
|
||||
│
|
||||
│ # translations for website/docs
|
||||
├── current
|
||||
│ ├── api
|
||||
│ │ └── config.md
|
||||
│ └── getting-started.md
|
||||
├── current.json
|
||||
│
|
||||
│ # translations for website/versioned_docs/version-1.0.0
|
||||
├── version-1.0.0
|
||||
│ ├── api
|
||||
│ │ └── config.md
|
||||
│ └── getting-started.md
|
||||
└── version-1.0.0.json
|
||||
```
|
|
@ -0,0 +1,157 @@
|
|||
---
|
||||
sidebar_position: 3
|
||||
slug: /api/plugins/@docusaurus/plugin-content-pages
|
||||
---
|
||||
|
||||
# 📦 plugin-content-pages
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
The default pages plugin for Docusaurus. The classic template ships with this plugin with default configurations. This plugin provides [creating pages](guides/creating-pages.mdx) functionality.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-content-pages
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `path` | `string` | `'src/pages'` | Path to data on filesystem relative to site dir. Components in this directory will be automatically converted to pages. |
|
||||
| `editUrl` | <code>string \| [EditUrlFn](#EditUrlFn)</code> | `undefined` | **Only for Markdown pages**. Base URL to edit your site. The final URL is computed by `editUrl + relativePostPath`. Using a function allows more nuanced control for each file. Omitting this variable entirely will disable edit links. |
|
||||
| `editLocalizedFiles` | `boolean` | `false` | **Only for Markdown pages**. The edit URL will target the localized file, instead of the original unlocalized file. Ignored when `editUrl` is a function. |
|
||||
| `routeBasePath` | `string` | `'/'` | URL route for the pages section of your site. **DO NOT** include a trailing slash. |
|
||||
| `include` | `string[]` | `['**/*.{js,jsx,ts,tsx,md,mdx}']` | Matching files will be included and processed. |
|
||||
| `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. |
|
||||
| `mdxPageComponent` | `string` | `'@theme/MDXPage'` | Component used by each MDX page. |
|
||||
| `remarkPlugins` | `[]` | `any[]` | Remark plugins passed to MDX. |
|
||||
| `rehypePlugins` | `[]` | `any[]` | Rehype plugins passed to MDX. |
|
||||
| `beforeDefaultRemarkPlugins` | `any[]` | `[]` | Custom Remark plugins passed to MDX before the default Docusaurus Remark plugins. |
|
||||
| `beforeDefaultRehypePlugins` | `any[]` | `[]` | Custom Rehype plugins passed to MDX before the default Docusaurus Rehype plugins. |
|
||||
| `showLastUpdateAuthor` | `boolean` | `false` | **Only for Markdown pages**. Whether to display the author who last updated the page. |
|
||||
| `showLastUpdateTime` | `boolean` | `false` | **Only for Markdown pages**. Whether to display the last date the page post was updated. This requires access to git history during the build, so will not work correctly with shallow clones (a common default for CI systems). With GitHub `actions/checkout`, use`fetch-depth: 0`. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Types {#types}
|
||||
|
||||
#### `EditUrlFn` {#EditUrlFn}
|
||||
|
||||
```ts
|
||||
type EditUrlFunction = (params: {
|
||||
blogDirPath: string;
|
||||
blogPath: string;
|
||||
permalink: string;
|
||||
locale: string;
|
||||
}) => string | undefined;
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: pages
|
||||
// Plugin Options: @docusaurus/plugin-content-pages
|
||||
|
||||
const config = {
|
||||
path: 'src/pages',
|
||||
routeBasePath: '',
|
||||
include: ['**/*.{js,jsx,ts,tsx,md,mdx}'],
|
||||
exclude: [
|
||||
'**/_*.{js,jsx,ts,tsx,md,mdx}',
|
||||
'**/_*/**',
|
||||
'**/*.test.{js,jsx,ts,tsx}',
|
||||
'**/__tests__/**',
|
||||
],
|
||||
mdxPageComponent: '@theme/MDXPage',
|
||||
remarkPlugins: [require('./my-remark-plugin')],
|
||||
rehypePlugins: [],
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
};
|
||||
```
|
||||
|
||||
## Markdown front matter {#markdown-front-matter}
|
||||
|
||||
Markdown pages can use the following Markdown [front matter](../../guides/markdown-features/markdown-features-intro.mdx#front-matter) metadata fields, enclosed by a line `---` on either side.
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `title` | `string` | Markdown title | The blog post title. |
|
||||
| `description` | `string` | The first line of Markdown content | The description of your page, which will become the `<meta name="description" content="..."/>` and `<meta property="og:description" content="..."/>` in `<head>`, used by search engines. |
|
||||
| `keywords` | `string[]` | `undefined` | Keywords meta tag, which will become the `<meta name="keywords" content="keyword1,keyword2,..."/>` in `<head>`, used by search engines. |
|
||||
| `image` | `string` | `undefined` | Cover or thumbnail image that will be used as the `<meta property="og:image" content="..."/>` in the `<head>`, enhancing link previews on social media and messaging platforms. |
|
||||
| `wrapperClassName` | `string` | | Class name to be added to the wrapper element to allow targeting specific page content. |
|
||||
| `hide_table_of_contents` | `boolean` | `false` | Whether to hide the table of contents to the right. |
|
||||
| `draft` | `boolean` | `false` | Draft pages will only be available during development. |
|
||||
| `unlisted` | `boolean` | `false` | Unlisted pages will be available in both development and production. They will be "hidden" in production, not indexed, excluded from sitemaps, and can only be accessed by users having a direct link. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```md
|
||||
---
|
||||
title: Markdown Page
|
||||
description: Markdown page SEO description
|
||||
wrapperClassName: markdown-page
|
||||
hide_table_of_contents: false
|
||||
draft: true
|
||||
---
|
||||
|
||||
Markdown page content
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.mdx) first.
|
||||
|
||||
### Translation files location {#translation-files-location}
|
||||
|
||||
- **Base path**: `website/i18n/[locale]/docusaurus-plugin-content-pages`
|
||||
- **Multi-instance path**: `website/i18n/[locale]/docusaurus-plugin-content-pages-[pluginId]`
|
||||
- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.mdx#docusaurus-write-translations-sitedir)
|
||||
- **Markdown files**: `website/i18n/[locale]/docusaurus-plugin-content-pages`
|
||||
|
||||
### Example file-system structure {#example-file-system-structure}
|
||||
|
||||
```bash
|
||||
website/i18n/[locale]/docusaurus-plugin-content-pages
|
||||
│
|
||||
│ # translations for website/src/pages
|
||||
├── first-markdown-page.md
|
||||
└── second-markdown-page.md
|
||||
```
|
|
@ -0,0 +1,108 @@
|
|||
---
|
||||
sidebar_position: 5
|
||||
slug: /api/plugins/@docusaurus/plugin-debug
|
||||
---
|
||||
|
||||
# 📦 plugin-debug
|
||||
|
||||
```mdx-code-block
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
```
|
||||
|
||||
The debug plugin will display useful debug information at [`http://localhost:3000/__docusaurus/debug`](http://localhost:3000/__docusaurus/debug).
|
||||
|
||||
It is mostly useful for plugin authors, that will be able to inspect more easily the content of the `.docusaurus` folder (like the creates routes), but also be able to inspect data structures that are never written to disk, like the plugin data loaded through the `contentLoaded` lifecycle.
|
||||
|
||||
:::info
|
||||
|
||||
If you use the plugin via the classic preset, the preset will **enable the plugin in development and disable it in production** by default (`debug: undefined`) to avoid exposing potentially sensitive information. You can use `debug: true` to always enable it or `debug: false` to always disable it.
|
||||
|
||||
If you use a standalone plugin, you may need to achieve the same effect by checking the environment:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
// highlight-next-line
|
||||
process.env.NODE_ENV === 'production' && '@docusaurus/plugin-debug',
|
||||
].filter(Boolean),
|
||||
};
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
:::note
|
||||
|
||||
If you report a bug, we will probably ask you to have this plugin turned on in the production, so that we can inspect your deployment config more easily.
|
||||
|
||||
If you don't have any sensitive information, you can keep it on in production [like we do](/__docusaurus/debug).
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-debug
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
This plugin currently has no options.
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs groupId="api-config-ex">
|
||||
<TabItem value="preset" label="Preset options">
|
||||
```
|
||||
|
||||
If you use a preset, configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic):
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
// highlight-next-line
|
||||
debug: true, // This will enable the plugin in production
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="plugin" label="Plugin Options">
|
||||
```
|
||||
|
||||
If you are using a standalone plugin, provide options directly to the plugin:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// highlight-next-line
|
||||
plugins: ['@docusaurus/plugin-debug'],
|
||||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
|
@ -0,0 +1,77 @@
|
|||
---
|
||||
sidebar_position: 6
|
||||
slug: /api/plugins/@docusaurus/plugin-google-analytics
|
||||
---
|
||||
|
||||
# 📦 plugin-google-analytics
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
The default [Google Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/) plugin. It is a JavaScript library for measuring how users interact with your website **in the production build**. If you are using Google Analytics 4 you might need to consider using [plugin-google-gtag](./plugin-google-gtag.mdx) instead.
|
||||
|
||||
:::danger Deprecated
|
||||
|
||||
This plugin is **deprecated**, and will become useless on July 1, 2023.
|
||||
|
||||
Google is [moving away from Universal Analytics](https://blog.google/products/marketingplatform/analytics/prepare-for-future-with-google-analytics-4/).
|
||||
|
||||
If you are still using this plugin with a `UA-*` tracking id, you should create a Google Analytics 4 account as soon as possible, and use [`@docusaurus/plugin-google-gtag`](./plugin-google-gtag.mdx) instead of this plugin. More details [here](https://github.com/facebook/docusaurus/issues/7221).
|
||||
|
||||
:::
|
||||
|
||||
:::warning production only
|
||||
|
||||
This plugin is always inactive in development and **only active in production** to avoid polluting the analytics statistics.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-google-analytics
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `trackingID` | `string` | **Required** | The tracking ID of your analytics service. |
|
||||
| `anonymizeIP` | `boolean` | `false` | Whether the IP should be anonymized when sending requests. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: googleAnalytics
|
||||
// Plugin Options: @docusaurus/plugin-google-analytics
|
||||
|
||||
const config = {
|
||||
trackingID: 'UA-141789564-1',
|
||||
anonymizeIP: true,
|
||||
};
|
||||
```
|
|
@ -0,0 +1,73 @@
|
|||
---
|
||||
sidebar_position: 7
|
||||
slug: /api/plugins/@docusaurus/plugin-google-gtag
|
||||
---
|
||||
|
||||
# 📦 plugin-google-gtag
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
The default [Global Site Tag (gtag.js)](https://developers.google.com/analytics/devguides/collection/gtagjs/) plugin. It is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform. This section describes how to configure a Docusaurus site to enable global site tag for Google Analytics.
|
||||
|
||||
:::tip
|
||||
|
||||
You can use [Google's Tag Assistant](https://tagassistant.google.com/) tool to check if your gtag is set up correctly!
|
||||
|
||||
:::
|
||||
|
||||
:::warning production only
|
||||
|
||||
This plugin is always inactive in development and **only active in production** to avoid polluting the analytics statistics.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-google-gtag
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `trackingID` | <code>string \| string[]</code> | **Required** | The tracking ID of your gtag service. It is possible to provide multiple ids. |
|
||||
| `anonymizeIP` | `boolean` | `false` | Whether the IP should be anonymized when sending requests. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: gtag
|
||||
// Plugin Options: @docusaurus/plugin-google-gtag
|
||||
|
||||
const config = {
|
||||
trackingID: 'G-999X9XX9XX',
|
||||
anonymizeIP: true,
|
||||
};
|
||||
```
|
|
@ -0,0 +1,71 @@
|
|||
---
|
||||
sidebar_position: 8
|
||||
slug: /api/plugins/@docusaurus/plugin-google-tag-manager
|
||||
---
|
||||
|
||||
# 📦 plugin-google-tag-manager
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
A plugin for adding [Google Tag Manager (gtm.js)](https://developers.google.com/tag-platform/tag-manager) to a Docusaurus site. Use this plugin in conjunction with the standard [gtag plugin](./plugin-google-gtag.mdx) for in-depth analysis of how users are using your site.
|
||||
|
||||
:::tip
|
||||
|
||||
You can use [Google's Tag Assistant](https://tagassistant.google.com/) tool to check if tag manager is set up correctly!
|
||||
|
||||
:::
|
||||
|
||||
:::warning production only
|
||||
|
||||
This plugin is always inactive in development and **only active in production** to avoid polluting the analytics statistics.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-google-tag-manager
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `containerId` | `string` | **Required** | Your Tag Manager container Id (usually starts with `GTM-`). |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: googleTagManager
|
||||
// Plugin Options: @docusaurus/plugin-google-tag-manager
|
||||
|
||||
const config = {
|
||||
containerId: 'GTM-12345',
|
||||
};
|
||||
```
|
|
@ -0,0 +1,92 @@
|
|||
---
|
||||
sidebar_position: 8
|
||||
slug: /api/plugins/@docusaurus/plugin-ideal-image
|
||||
---
|
||||
|
||||
# 📦 plugin-ideal-image
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder).
|
||||
|
||||
:::info
|
||||
|
||||
By default, the plugin is **inactive in development** so you could always view full-scale images. If you want to debug the ideal image behavior, you could set the [`disableInDev`](#disableInDev) option to `false`.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-ideal-image
|
||||
```
|
||||
|
||||
## Usage {#usage}
|
||||
|
||||
This plugin supports the PNG and JPG formats only.
|
||||
|
||||
```jsx
|
||||
import Image from '@theme/IdealImage';
|
||||
import thumbnail from './path/to/img.png';
|
||||
|
||||
// your React code
|
||||
<Image img={thumbnail} />
|
||||
|
||||
// or
|
||||
<Image img={require('./path/to/img.png')} />
|
||||
```
|
||||
|
||||
:::warning
|
||||
|
||||
This plugin registers a [Webpack loader](https://webpack.js.org/loaders/) that changes the type of imported/require images:
|
||||
|
||||
- Before: `string`
|
||||
- After: `{preSrc: string, src: import("@theme/IdealImage").SrcImage}`
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `name` | `string` | `ideal-img/[name].[hash:hex:7].[width].[ext]` | Filename template for output files. |
|
||||
| `sizes` | `number[]` | _original size_ | Specify all widths you want to use. If a specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up). |
|
||||
| `size` | `number` | _original size_ | Specify one width you want to use; if the specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up) |
|
||||
| `min` | `number` | | As an alternative to manually specifying `sizes`, you can specify `min`, `max` and `steps`, and the sizes will be generated for you. |
|
||||
| `max` | `number` | | See `min` above |
|
||||
| `steps` | `number` | `4` | Configure the number of images generated between `min` and `max` (inclusive) |
|
||||
| `quality` | `number` | `85` | JPEG compression quality |
|
||||
| `disableInDev` | `boolean` | `true` | You can test ideal image behavior in dev mode by setting this to `false`. **Tip**: use [network throttling](https://www.browserstack.com/guide/how-to-perform-network-throttling-in-chrome) in your browser to simulate slow networks. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
Here's an example configuration:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-ideal-image',
|
||||
// highlight-start
|
||||
{
|
||||
quality: 70,
|
||||
max: 1030, // max resized image's size.
|
||||
min: 640, // min resized image's size. if original is lower, use that size.
|
||||
steps: 2, // the max number of images generated between min and max (inclusive)
|
||||
disableInDev: false,
|
||||
},
|
||||
// highlight-end
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
303
website/versioned_docs/version-3.3.2/api/plugins/plugin-pwa.mdx
Normal file
303
website/versioned_docs/version-3.3.2/api/plugins/plugin-pwa.mdx
Normal file
|
@ -0,0 +1,303 @@
|
|||
---
|
||||
sidebar_position: 9
|
||||
slug: /api/plugins/@docusaurus/plugin-pwa
|
||||
---
|
||||
|
||||
# 📦 plugin-pwa
|
||||
|
||||
Docusaurus Plugin to add PWA support using [Workbox](https://developers.google.com/web/tools/workbox). This plugin generates a [Service Worker](https://developers.google.com/web/fundamentals/primers/service-workers) in production build only, and allows you to create fully PWA-compliant documentation site with offline and installation support.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-pwa
|
||||
```
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Create a [PWA manifest](https://web.dev/add-manifest/) at `./static/manifest.json`.
|
||||
|
||||
Modify `docusaurus.config.js` with a minimal PWA config, like:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-pwa',
|
||||
{
|
||||
debug: true,
|
||||
offlineModeActivationStrategies: [
|
||||
'appInstalled',
|
||||
'standalone',
|
||||
'queryString',
|
||||
],
|
||||
pwaHead: [
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'icon',
|
||||
href: '/img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'manifest',
|
||||
href: '/manifest.json', // your PWA manifest
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'theme-color',
|
||||
content: 'rgb(37, 194, 160)',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## Progressive Web App {#progressive-web-app}
|
||||
|
||||
Having a service worker installed is not enough to make your application a PWA. You'll need to at least include a [Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest) and have the correct tags in `<head>` ([Options > pwaHead](#pwahead)).
|
||||
|
||||
After deployment, you can use [Lighthouse](https://developers.google.com/web/tools/lighthouse) to run an audit on your site.
|
||||
|
||||
For a more exhaustive list of what it takes for your site to be a PWA, refer to the [PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist)
|
||||
|
||||
## App installation support {#app-installation-support}
|
||||
|
||||
If your browser supports it, you should be able to install a Docusaurus site as an app.
|
||||
|
||||

|
||||
|
||||
:::note
|
||||
|
||||
App installation requires the HTTPS protocol and a valid manifest.
|
||||
|
||||
:::
|
||||
|
||||
## Offline mode (precaching) {#offline-mode-precaching}
|
||||
|
||||
We enable users to browse a Docusaurus site offline, by using service-worker precaching.
|
||||
|
||||
The [workbox-precaching](https://developers.google.com/web/tools/workbox/modules/workbox-precaching) page explains the idea:
|
||||
|
||||
> One feature of service workers is the ability to save a set of files to the cache when the service worker is installing. This is often referred to as "precaching", since you are caching content ahead of the service worker being used.
|
||||
>
|
||||
> The main reason for doing this is that it gives developers control over the cache, meaning they can determine when and how long a file is cached as well as serve it to the browser without going to the network, meaning it can be used to create web apps that work offline.
|
||||
>
|
||||
> Workbox takes a lot of the heavy lifting out of precaching by simplifying the API and ensuring assets are downloaded efficiently.
|
||||
|
||||
By default, offline mode is enabled when the site is installed as an app. See the `offlineModeActivationStrategies` option for details.
|
||||
|
||||
After the site has been precached, the service worker will serve cached responses for later visits. When a new build is deployed along with a new service worker, the new one will begin installing and eventually move to a waiting state. During this waiting state, a reload popup will show and ask the user to reload the page for new content. Until the user either clears the application cache or clicks the `reload` button on the popup, the service worker will continue serving the old content.
|
||||
|
||||
:::warning
|
||||
|
||||
Offline mode / precaching requires downloading all the static assets of the site ahead of time, and can consume unnecessary bandwidth. It may not be a good idea to activate it for all kind of sites.
|
||||
|
||||
:::
|
||||
|
||||
## Options {#options}
|
||||
|
||||
### `debug` {#debug}
|
||||
|
||||
- Type: `boolean`
|
||||
- Default: `false`
|
||||
|
||||
Turn debug mode on:
|
||||
|
||||
- Workbox logs
|
||||
- Additional Docusaurus logs
|
||||
- Unoptimized SW file output
|
||||
- Source maps
|
||||
|
||||
### `offlineModeActivationStrategies` {#offlinemodeactivationstrategies}
|
||||
|
||||
- Type: `('appInstalled' | 'mobile' | 'saveData'| 'queryString' | 'always')[]`
|
||||
- Default: `['appInstalled', 'queryString', 'standalone']`
|
||||
|
||||
Strategies used to turn the offline mode on:
|
||||
|
||||
- `appInstalled`: activates for users having installed the site as an app (not 100% reliable)
|
||||
- `standalone`: activates for users running the app as standalone (often the case once a PWA is installed)
|
||||
- `queryString`: activates if queryString contains `offlineMode=true` (convenient for PWA debugging)
|
||||
- `mobile`: activates for mobile users (`width <= 996px`)
|
||||
- `saveData`: activates for users with `navigator.connection.saveData === true`
|
||||
- `always`: activates for all users
|
||||
|
||||
:::warning
|
||||
|
||||
Use this carefully: some users may not like to be forced to use the offline mode.
|
||||
|
||||
:::
|
||||
|
||||
:::danger
|
||||
|
||||
It is not possible to detect if a page is rendered as a PWA in a reliable manner.
|
||||
|
||||
The `appinstalled` event has been [removed from the specification](https://github.com/w3c/manifest/pull/836), and the [`navigator.getInstalledRelatedApps()`](https://web.dev/get-installed-related-apps/) API is only supported in recent Chrome versions and require `related_applications` declared in the manifest.
|
||||
|
||||
The [`standalone` strategy](https://petelepage.com/blog/2019/07/is-my-pwa-installed/) is a nice fallback to activate the offline mode (at least when running the installed app).
|
||||
|
||||
:::
|
||||
|
||||
### `injectManifestConfig` {#injectmanifestconfig}
|
||||
|
||||
[Workbox options](https://developer.chrome.com/docs/workbox/reference/workbox-build/#type-InjectManifestOptions) to pass to `workbox.injectManifest()`. This gives you control over which assets will be precached, and be available offline.
|
||||
|
||||
- Type: `InjectManifestOptions`
|
||||
- Default: `{}`
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-pwa',
|
||||
{
|
||||
injectManifestConfig: {
|
||||
manifestTransforms: [
|
||||
//...
|
||||
],
|
||||
modifyURLPrefix: {
|
||||
//...
|
||||
},
|
||||
// We already add regular static assets (HTML, images...) to be available offline
|
||||
// You can add more files according to your needs
|
||||
globPatterns: ['**/*.{pdf,docx,xlsx}'],
|
||||
// ...
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `pwaHead` {#pwahead}
|
||||
|
||||
- Type: `({ tagName: string; [attributeName: string]: string })[]`
|
||||
- Default: `[]`
|
||||
|
||||
Array of objects containing `tagName` and key-value pairs for attributes to inject into the `<head>` tag. Technically you can inject any head tag through this, but it's ideally used for tags to make your site PWA compliant. Here's a list of tag to make your app fully compliant:
|
||||
|
||||
```js
|
||||
export default {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-pwa',
|
||||
{
|
||||
pwaHead: [
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'icon',
|
||||
href: '/img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'manifest',
|
||||
href: '/manifest.json',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'theme-color',
|
||||
content: 'rgb(37, 194, 160)',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'apple-mobile-web-app-capable',
|
||||
content: 'yes',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'apple-mobile-web-app-status-bar-style',
|
||||
content: '#000',
|
||||
},
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'apple-touch-icon',
|
||||
href: '/img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'link',
|
||||
rel: 'mask-icon',
|
||||
href: '/img/docusaurus.svg',
|
||||
color: 'rgb(37, 194, 160)',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'msapplication-TileImage',
|
||||
content: '/img/docusaurus.png',
|
||||
},
|
||||
{
|
||||
tagName: 'meta',
|
||||
name: 'msapplication-TileColor',
|
||||
content: '#000',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `swCustom` {#swcustom}
|
||||
|
||||
- Type: `string | undefined`
|
||||
- Default: `undefined`
|
||||
|
||||
Useful for additional Workbox rules. You can do whatever a service worker can do here, and use the full power of workbox libraries. The code is transpiled, so you can use modern ES6+ syntax here.
|
||||
|
||||
For example, to cache files from external routes:
|
||||
|
||||
```js
|
||||
import {registerRoute} from 'workbox-routing';
|
||||
import {StaleWhileRevalidate} from 'workbox-strategies';
|
||||
|
||||
// default fn export receiving some useful params
|
||||
export default function swCustom(params) {
|
||||
const {
|
||||
debug, // :boolean
|
||||
offlineMode, // :boolean
|
||||
} = params;
|
||||
|
||||
// Cache responses from external resources
|
||||
registerRoute((context) => {
|
||||
return [
|
||||
/graph\.facebook\.com\/.*\/picture/,
|
||||
/netlify\.com\/img/,
|
||||
/avatars1\.githubusercontent/,
|
||||
].some((regex) => context.url.href.match(regex));
|
||||
}, new StaleWhileRevalidate());
|
||||
}
|
||||
```
|
||||
|
||||
The module should have a `default` function export, and receives some params.
|
||||
|
||||
### `swRegister` {#swregister}
|
||||
|
||||
- Type: `string | false`
|
||||
- Default: `'docusaurus-plugin-pwa/src/registerSW.js'`
|
||||
|
||||
Adds an entry before the Docusaurus app so that registration can happen before the app runs. The default `registerSW.js` file is enough for simple registration.
|
||||
|
||||
Passing `false` will disable registration entirely.
|
||||
|
||||
## Manifest example {#manifest-example}
|
||||
|
||||
The Docusaurus site manifest can serve as an inspiration:
|
||||
|
||||
```mdx-code-block
|
||||
import CodeBlock from '@theme/CodeBlock';
|
||||
|
||||
<CodeBlock className="language-json">
|
||||
{JSON.stringify(require('@site/static/manifest.json'),null,2)}
|
||||
</CodeBlock>
|
||||
```
|
||||
|
||||
## Customizing reload popup {#customizing-reload-popup}
|
||||
|
||||
The `@theme/PwaReloadPopup` component is rendered when a new service worker is waiting to be installed, and we suggest a reload to the user. You can [swizzle](../../swizzling.mdx) this component and implement your own UI. It will receive an `onReload` callback as props, which should be called when the `reload` button is clicked. This will tell the service worker to install the waiting service worker and reload the page.
|
||||
|
||||
The default theme includes an implementation for the reload popup and uses [Infima Alerts](https://infima.dev/docs/components/alert).
|
||||
|
||||

|
||||
|
||||
Your component can render `null`, but this is not recommended: users won't have a way to get up-to-date content.
|
|
@ -0,0 +1,110 @@
|
|||
---
|
||||
sidebar_position: 10
|
||||
slug: /api/plugins/@docusaurus/plugin-sitemap
|
||||
---
|
||||
|
||||
# 📦 plugin-sitemap
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
This plugin creates sitemaps for your site so that search engine crawlers can crawl your site more accurately.
|
||||
|
||||
:::warning production only
|
||||
|
||||
This plugin is always inactive in development and **only active in production** because it works on the build output.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-sitemap
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency.
|
||||
|
||||
You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic).
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `lastmod` | `'date' \| 'datetime' \| null` | `null` | `date` is YYYY-MM-DD. `datetime` is a ISO 8601 datetime. `null` is disabled. See [sitemap docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions). |
|
||||
| `changefreq` | `string \| null` | `'weekly'` | See [sitemap docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions) |
|
||||
| `priority` | `number \| null` | `0.5` | See [sitemap docs](https://www.sitemaps.org/protocol.html#xmlTagDefinitions) |
|
||||
| `ignorePatterns` | `string[]` | `[]` | A list of glob patterns; matching route paths will be filtered from the sitemap. Note that you may need to include the base URL in here. |
|
||||
| `filename` | `string` | `sitemap.xml` | The path to the created sitemap file, relative to the output directory. Useful if you have two plugin instances outputting two files. |
|
||||
| `createSitemapItems` | <code>[CreateSitemapItemsFn](#CreateSitemapItemsFn) \| undefined</code> | `undefined` | An optional function which can be used to transform and / or filter the items in the sitemap. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Types {#types}
|
||||
|
||||
#### `CreateSitemapItemsFn` {#CreateSitemapItemsFn}
|
||||
|
||||
```ts
|
||||
type CreateSitemapItemsFn = (params: {
|
||||
siteConfig: DocusaurusConfig;
|
||||
routes: RouteConfig[];
|
||||
defaultCreateSitemapItems: CreateSitemapItemsFn;
|
||||
}) => Promise<SitemapItem[]>;
|
||||
```
|
||||
|
||||
:::info
|
||||
|
||||
This plugin also respects some site config:
|
||||
|
||||
- [`noIndex`](../docusaurus.config.js.mdx#noIndex): results in no sitemap generated
|
||||
- [`trailingSlash`](../docusaurus.config.js.mdx#trailingSlash): determines if the URLs in the sitemap have trailing slashes
|
||||
|
||||
:::
|
||||
|
||||
:::note About `lastmod`
|
||||
|
||||
The `lastmod` option will only output a sitemap `<lastmod>` tag if plugins provide [route metadata](../plugin-methods/lifecycle-apis.mdx#addRoute) attributes `sourceFilePath` and/or `lastUpdatedAt`.
|
||||
|
||||
All the official content plugins provide the metadata for routes backed by a content file (Markdown, MDX or React page components), but it is possible third-party plugin authors do not provide this information, and the plugin will not be able to output a `<lastmod>` tag for their routes.
|
||||
|
||||
:::
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: sitemap
|
||||
// Plugin Options: @docusaurus/plugin-sitemap
|
||||
|
||||
const config = {
|
||||
lastmod: 'date',
|
||||
changefreq: 'weekly',
|
||||
priority: 0.5,
|
||||
ignorePatterns: ['/tags/**'],
|
||||
filename: 'sitemap.xml',
|
||||
createSitemapItems: async (params) => {
|
||||
const {defaultCreateSitemapItems, ...rest} = params;
|
||||
const items = await defaultCreateSitemapItems(rest);
|
||||
return items.filter((item) => !item.url.includes('/page/'));
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
You can find your sitemap at `/sitemap.xml`.
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
sidebar_position: 11
|
||||
slug: /api/plugins/@docusaurus/plugin-vercel-analytics
|
||||
---
|
||||
|
||||
# 📦 plugin-vercel-analytics
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
[Vercel Analytics](https://vercel.com/docs/analytics) provides comprehensive insights into your website's visitors, tracking top pages, referrers, and demographics like location, operating systems, and browser info.
|
||||
|
||||
:::warning production only
|
||||
|
||||
This plugin is always inactive in development and **only active in production** (`docusaurus build`) to avoid polluting the analytics statistics.
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-vercel-analytics
|
||||
```
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `mode` | `string` | `'auto'` | Override the automatic environment detection. Read the [official docs](https://vercel.com/docs/analytics/package#mode) for details. |
|
||||
| `debug` | `boolean` | `undefined` | Enable browser console logging of analytics events. Read the [official docs](https://vercel.com/docs/analytics/package#debug) for details. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this plugin through plugin options.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: [
|
||||
[
|
||||
'vercel-analytics',
|
||||
{
|
||||
debug: true,
|
||||
mode: 'auto',
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
label: Themes
|
||||
position: 3
|
||||
link:
|
||||
type: doc
|
||||
id: themes-overview # Dogfood using a "local id"
|
34
website/versioned_docs/version-3.3.2/api/themes/overview.mdx
Normal file
34
website/versioned_docs/version-3.3.2/api/themes/overview.mdx
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
sidebar_position: 0
|
||||
id: themes-overview
|
||||
sidebar_label: Themes overview
|
||||
slug: /api/themes
|
||||
---
|
||||
|
||||
# Docusaurus themes
|
||||
|
||||
We provide official Docusaurus themes.
|
||||
|
||||
## Main themes {#main-themes}
|
||||
|
||||
The main themes implement the user interface for the [docs](../plugins/plugin-content-docs.mdx), [blog](../plugins/plugin-content-blog.mdx) and [pages](../plugins/plugin-content-pages.mdx) plugins.
|
||||
|
||||
- [@docusaurus/theme-classic](./theme-classic.mdx)
|
||||
- 🚧 other themes are planned
|
||||
|
||||
:::warning
|
||||
|
||||
The goal is to have all themes share the exact same features, user-experience and configuration.
|
||||
|
||||
Only the UI design and underlying styling framework should change, and you should be able to change theme easily.
|
||||
|
||||
We are not there yet: only the classic theme is production ready.
|
||||
|
||||
:::
|
||||
|
||||
## Enhancement themes {#enhancement-themes}
|
||||
|
||||
These themes will enhance the existing main themes with additional user-interface related features.
|
||||
|
||||
- [@docusaurus/theme-live-codeblock](./theme-live-codeblock.mdx)
|
||||
- [@docusaurus/theme-search-algolia](./theme-search-algolia.mdx)
|
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
sidebar_position: 2
|
||||
slug: /api/themes/@docusaurus/theme-classic
|
||||
---
|
||||
|
||||
# 📦 theme-classic
|
||||
|
||||
import APITable from '@site/src/components/APITable';
|
||||
|
||||
The classic theme for Docusaurus.
|
||||
|
||||
You can refer to the [theme configuration page](theme-configuration.mdx) for more details on the configuration.
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/theme-classic
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Accepted fields:
|
||||
|
||||
```mdx-code-block
|
||||
<APITable>
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `customCss` | <code>string[] \| string</code> | `[]` | Stylesheets to be imported globally as [client modules](../../advanced/client.mdx#client-modules). Relative paths are resolved against the site directory. |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
Most configuration for the theme is done in `themeConfig`, which can be found in [theme configuration](./theme-configuration.mdx).
|
||||
|
||||
:::
|
||||
|
||||
### Example configuration {#ex-config}
|
||||
|
||||
You can configure this theme through preset options or plugin options.
|
||||
|
||||
:::tip
|
||||
|
||||
Most Docusaurus users configure this plugin through the preset options.
|
||||
|
||||
:::
|
||||
|
||||
```js config-tabs
|
||||
// Preset Options: theme
|
||||
// Plugin Options: @docusaurus/theme-classic
|
||||
|
||||
const config = {
|
||||
customCss: './src/css/custom.css',
|
||||
};
|
||||
```
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
sidebar_position: 3
|
||||
slug: /api/themes/@docusaurus/theme-live-codeblock
|
||||
---
|
||||
|
||||
# 📦 theme-live-codeblock
|
||||
|
||||
This theme provides a `@theme/CodeBlock` component that is powered by react-live. You can read more on [interactive code editor](../../guides/markdown-features/markdown-features-code-blocks.mdx#interactive-code-editor) documentation.
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/theme-live-codeblock
|
||||
```
|
||||
|
||||
### Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
plugins: ['@docusaurus/theme-live-codeblock'],
|
||||
themeConfig: {
|
||||
liveCodeBlock: {
|
||||
/**
|
||||
* The position of the live playground, above or under the editor
|
||||
* Possible values: "top" | "bottom"
|
||||
*/
|
||||
playgroundPosition: 'bottom',
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
sidebar_position: 5
|
||||
slug: /api/themes/@docusaurus/theme-mermaid
|
||||
---
|
||||
|
||||
# 📦 theme-mermaid
|
||||
|
||||
This theme provides a `@theme/Mermaid` component that is powered by [mermaid](https://mermaid-js.github.io/). You can read more on [diagrams](../../guides/markdown-features/markdown-features-diagrams.mdx) documentation.
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/theme-mermaid
|
||||
```
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
themes: ['@docusaurus/theme-mermaid'],
|
||||
// In order for Mermaid code blocks in Markdown to work,
|
||||
// you also need to enable the Remark plugin with this option
|
||||
markdown: {
|
||||
mermaid: true,
|
||||
},
|
||||
};
|
||||
```
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
sidebar_position: 4
|
||||
slug: /api/themes/@docusaurus/theme-search-algolia
|
||||
---
|
||||
|
||||
# 📦 theme-search-algolia
|
||||
|
||||
This theme provides a `@theme/SearchBar` component that integrates with Algolia DocSearch easily. Combined with `@docusaurus/theme-classic`, it provides a very easy search integration. You can read more on [search](../../search.mdx) documentation.
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/theme-search-algolia
|
||||
```
|
||||
|
||||
This theme also adds search page available at `/search` (as swizzlable `SearchPage` component) path with OpenSearch support. You can change this default path via `themeConfig.algolia.searchPagePath`. Use `false` to disable search page.
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency.
|
||||
|
||||
:::
|
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
Binary file not shown.
Binary file not shown.
674
website/versioned_docs/version-3.3.2/blog.mdx
Normal file
674
website/versioned_docs/version-3.3.2/blog.mdx
Normal file
|
@ -0,0 +1,674 @@
|
|||
---
|
||||
description: Deploy a full-featured blog in no time with Docusaurus.
|
||||
---
|
||||
|
||||
# Blog
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
The blog feature enables you to deploy a full-featured blog in no time.
|
||||
|
||||
:::info
|
||||
|
||||
Check the [Blog Plugin API Reference documentation](./api/plugins/plugin-content-blog.mdx) for an exhaustive list of options.
|
||||
|
||||
:::
|
||||
|
||||
## Initial setup {#initial-setup}
|
||||
|
||||
To set up your site's blog, start by creating a `blog` directory.
|
||||
|
||||
Then, add an item link to your blog within `docusaurus.config.js`:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
themeConfig: {
|
||||
// ...
|
||||
navbar: {
|
||||
items: [
|
||||
// ...
|
||||
// highlight-next-line
|
||||
{to: 'blog', label: 'Blog', position: 'left'}, // or position: 'right'
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## Adding posts {#adding-posts}
|
||||
|
||||
To publish in the blog, create a Markdown file within the blog directory.
|
||||
|
||||
For example, create a file at `website/blog/2019-09-05-hello-docusaurus.md`:
|
||||
|
||||
```md title="website/blog/2019-09-05-hello-docusaurus.md"
|
||||
---
|
||||
title: Welcome Docusaurus
|
||||
description: This is my first post on Docusaurus.
|
||||
slug: welcome-docusaurus-v2
|
||||
authors:
|
||||
- name: Joel Marcey
|
||||
title: Co-creator of Docusaurus 1
|
||||
url: https://github.com/JoelMarcey
|
||||
image_url: https://github.com/JoelMarcey.png
|
||||
- name: Sébastien Lorber
|
||||
title: Docusaurus maintainer
|
||||
url: https://sebastienlorber.com
|
||||
image_url: https://github.com/slorber.png
|
||||
tags: [hello, docusaurus-v2]
|
||||
image: https://i.imgur.com/mErPwqL.png
|
||||
hide_table_of_contents: false
|
||||
---
|
||||
|
||||
Welcome to this blog. This blog is created with [**Docusaurus 2**](https://docusaurus.io/).
|
||||
|
||||
<!-- truncate -->
|
||||
|
||||
This is my first post on Docusaurus 2.
|
||||
|
||||
A whole bunch of exploration to follow.
|
||||
```
|
||||
|
||||
The [front matter](./guides/markdown-features/markdown-features-intro.mdx#front-matter) is useful to add more metadata to your blog post, for example, author information, but Docusaurus will be able to infer all necessary metadata without the front matter. For all possible fields, see [the API documentation](api/plugins/plugin-content-blog.mdx#markdown-front-matter).
|
||||
|
||||
## Blog list {#blog-list}
|
||||
|
||||
The blog's index page (by default, it is at `/blog`) is the _blog list page_, where all blog posts are collectively displayed.
|
||||
|
||||
Use the `<!--truncate-->` marker in your blog post to represent what will be shown as the summary when viewing all published blog posts. Anything above `<!--truncate-->` will be part of the summary. Note that the portion above the truncate marker must be standalone renderable Markdown. For example:
|
||||
|
||||
```md title="website/blog/my-post.md" {7}
|
||||
---
|
||||
title: Markdown blog truncation example
|
||||
---
|
||||
|
||||
All these will be part of the blog post summary.
|
||||
|
||||
<!-- truncate -->
|
||||
|
||||
But anything from here on down will not be.
|
||||
```
|
||||
|
||||
For files using the `.mdx` extension, use a [MDX](https://mdxjs.com/) comment `{/* truncate */}` instead:
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```md title="website/blog/my-post.mdx" {7}
|
||||
---
|
||||
title: MDX blog truncation Example
|
||||
---
|
||||
|
||||
All these will be part of the blog post summary.
|
||||
|
||||
{/* truncate */}
|
||||
|
||||
But anything from here on down will not be.
|
||||
```
|
||||
|
||||
By default, 10 posts are shown on each blog list page, but you can control pagination with the `postsPerPage` option in the plugin configuration. If you set `postsPerPage: 'ALL'`, pagination will be disabled and all posts will be displayed on the first page. You can also add a meta description to the blog list page for better SEO:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
// highlight-start
|
||||
blogTitle: 'Docusaurus blog!',
|
||||
blogDescription: 'A Docusaurus powered blog!',
|
||||
postsPerPage: 'ALL',
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## Blog sidebar {#blog-sidebar}
|
||||
|
||||
The blog sidebar displays recent blog posts. The default number of items shown is 5, but you can customize with the `blogSidebarCount` option in the plugin configuration. By setting `blogSidebarCount: 0`, the sidebar will be completely disabled, with the container removed as well. This will increase the width of the main container. Specially, if you have set `blogSidebarCount: 'ALL'`, _all_ posts will be displayed.
|
||||
|
||||
You can also alter the sidebar heading text with the `blogSidebarTitle` option. For example, if you have set `blogSidebarCount: 'ALL'`, instead of the default "Recent posts", you may rather make it say "All posts":
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
// highlight-start
|
||||
blogSidebarTitle: 'All posts',
|
||||
blogSidebarCount: 'ALL',
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## Blog post date {#blog-post-date}
|
||||
|
||||
Docusaurus will extract a `YYYY-MM-DD` date from many patterns such as `YYYY-MM-DD-my-blog-post-title.md` or `YYYY/MM/DD/my-blog-post-title.md`. This enables you to easily group blog posts by year, by month, or to use a flat structure.
|
||||
|
||||
<details>
|
||||
<summary>Supported date extraction patterns</summary>
|
||||
|
||||
| Pattern | Example |
|
||||
| --- | --- |
|
||||
| Single file | `2021-05-28-my-blog-post-title.md` |
|
||||
| MDX file | `2021-05-28-my-blog-post-title.mdx` |
|
||||
| Single folder + `index.md` | `2021-05-28-my-blog-post-title/index.md` |
|
||||
| Folder named by date | `2021-05-28/my-blog-post-title.md` |
|
||||
| Nested folders by date | `2021/05/28/my-blog-post-title.md` |
|
||||
| Partially nested folders by date | `2021/05-28-my-blog-post-title.md` |
|
||||
| Nested folders + `index.md` | `2021/05/28/my-blog-post-title/index.md` |
|
||||
| Date in the middle of path | `category/2021/05-28-my-blog-post-title.md` |
|
||||
|
||||
Docusaurus can extract the date from the posts using any of the naming patterns above. It is advisable to choose one pattern and apply it to all posts to avoid confusion.
|
||||
|
||||
</details>
|
||||
|
||||
:::tip
|
||||
|
||||
Using a folder can be convenient to co-locate blog post images alongside the Markdown file.
|
||||
|
||||
:::
|
||||
|
||||
This naming convention is optional, and you can also provide the date as front matter. Since the front matter follows YAML syntax where the datetime notation is supported, you can use front matter if you need more fine-grained publish dates. For example, if you have multiple posts published on the same day, you can order them according to the time of the day:
|
||||
|
||||
```md title="earlier-post.md"
|
||||
---
|
||||
date: 2021-09-13T10:00
|
||||
---
|
||||
```
|
||||
|
||||
```md title="later-post.md"
|
||||
---
|
||||
date: 2021-09-13T18:00
|
||||
---
|
||||
```
|
||||
|
||||
## Blog post authors {#blog-post-authors}
|
||||
|
||||
Use the `authors` front matter field to declare blog post authors. An author should have at least a `name` or an `image_url`. Docusaurus uses information like `url`, `email`, and `title`, but any other information is allowed.
|
||||
|
||||
### Inline authors {#inline-authors}
|
||||
|
||||
Blog post authors can be declared directly inside the front matter:
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs groupId="author-front-matter">
|
||||
<TabItem value="single" label="Single author">
|
||||
```
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
authors:
|
||||
name: Joel Marcey
|
||||
title: Co-creator of Docusaurus 1
|
||||
url: https://github.com/JoelMarcey
|
||||
image_url: https://github.com/JoelMarcey.png
|
||||
email: jimarcey@gmail.com
|
||||
---
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="multiple" label="Multiple authors">
|
||||
```
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
authors:
|
||||
- name: Joel Marcey
|
||||
title: Co-creator of Docusaurus 1
|
||||
url: https://github.com/JoelMarcey
|
||||
image_url: https://github.com/JoelMarcey.png
|
||||
email: jimarcey@gmail.com
|
||||
- name: Sébastien Lorber
|
||||
title: Docusaurus maintainer
|
||||
url: https://sebastienlorber.com
|
||||
image_url: https://github.com/slorber.png
|
||||
---
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
This option works best to get started, or for casual, irregular authors.
|
||||
|
||||
:::
|
||||
|
||||
:::info
|
||||
|
||||
Prefer using the `authors` front matter, but the legacy `author_*` front matter remains supported:
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
author: Joel Marcey
|
||||
author_title: Co-creator of Docusaurus 1
|
||||
author_url: https://github.com/JoelMarcey
|
||||
author_image_url: https://github.com/JoelMarcey.png
|
||||
---
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
### Global authors {#global-authors}
|
||||
|
||||
For regular blog post authors, it can be tedious to maintain authors' information inlined in each blog post.
|
||||
|
||||
It is possible to declare those authors globally in a configuration file:
|
||||
|
||||
```yml title="website/blog/authors.yml"
|
||||
jmarcey:
|
||||
name: Joel Marcey
|
||||
title: Co-creator of Docusaurus 1
|
||||
url: https://github.com/JoelMarcey
|
||||
image_url: https://github.com/JoelMarcey.png
|
||||
email: jimarcey@gmail.com
|
||||
|
||||
slorber:
|
||||
name: Sébastien Lorber
|
||||
title: Docusaurus maintainer
|
||||
url: https://sebastienlorber.com
|
||||
image_url: https://github.com/slorber.png
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
Use the `authorsMapPath` plugin option to configure the path. JSON is also supported.
|
||||
|
||||
:::
|
||||
|
||||
In blog posts front matter, you can reference the authors declared in the global configuration file:
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs groupId="author-front-matter">
|
||||
<TabItem value="single" label="Single author">
|
||||
```
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
authors: jmarcey
|
||||
---
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="multiple" label="Multiple authors">
|
||||
```
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
authors: [jmarcey, slorber]
|
||||
---
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
:::info
|
||||
|
||||
The `authors` system is very flexible and can suit more advanced use-case:
|
||||
|
||||
<details>
|
||||
<summary>Mix inline authors and global authors</summary>
|
||||
|
||||
You can use global authors most of the time, and still use inline authors:
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
authors:
|
||||
- jmarcey
|
||||
- slorber
|
||||
- name: Inline Author name
|
||||
title: Inline Author Title
|
||||
url: https://github.com/inlineAuthor
|
||||
image_url: https://github.com/inlineAuthor
|
||||
---
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Local override of global authors</summary>
|
||||
|
||||
You can customize the global author's data on per-blog-post basis:
|
||||
|
||||
```md title="my-blog-post.md"
|
||||
---
|
||||
authors:
|
||||
- key: jmarcey
|
||||
title: Joel Marcey's new title
|
||||
- key: slorber
|
||||
name: Sébastien Lorber's new name
|
||||
---
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Localize the author's configuration file</summary>
|
||||
|
||||
The configuration file can be localized, just create a localized copy of it at:
|
||||
|
||||
```bash
|
||||
website/i18n/[locale]/docusaurus-plugin-content-blog/authors.yml
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
:::
|
||||
|
||||
An author, either declared through front matter or through the authors map, needs to have a name or an avatar, or both. If all authors of a post don't have names, Docusaurus will display their avatars compactly. See [this test post](/tests/blog/2022/01/20/image-only-authors) for the effect.
|
||||
|
||||
:::warning Feed generation
|
||||
|
||||
[RSS feeds](#feed) require the author's email to be set for the author to appear in the feed.
|
||||
|
||||
:::
|
||||
|
||||
## Reading time {#reading-time}
|
||||
|
||||
Docusaurus generates a reading time estimation for each blog post based on word count. We provide an option to customize this.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
// highlight-start
|
||||
showReadingTime: true, // When set to false, the "x min read" won't be shown
|
||||
readingTime: ({content, frontMatter, defaultReadingTime}) =>
|
||||
defaultReadingTime({content, options: {wordsPerMinute: 300}}),
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
The `readingTime` callback receives three parameters: the blog content text as a string, front matter as a record of string keys and their values, and the default reading time function. It returns a number (reading time in minutes) or `undefined` (disable reading time for this page).
|
||||
|
||||
The default reading time is able to accept additional options: `wordsPerMinute` as a number (default: 300), and `wordBound` as a function from string to boolean. If the string passed to `wordBound` should be a word bound (spaces, tabs, and line breaks by default), the function should return `true`.
|
||||
|
||||
:::tip
|
||||
|
||||
Use the callback for all your customization needs:
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="disable-per-post" label="Per-post disabling">
|
||||
```
|
||||
|
||||
**Disable reading time on one page:**
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
showReadingTime: true,
|
||||
// highlight-start
|
||||
readingTime: ({content, frontMatter, defaultReadingTime}) =>
|
||||
frontMatter.hide_reading_time
|
||||
? undefined
|
||||
: defaultReadingTime({content}),
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```md "my-blog-post.md"
|
||||
---
|
||||
hide_reading_time: true
|
||||
---
|
||||
|
||||
This page will no longer display the reading time stats!
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="passing-options" label="Passing options">
|
||||
```
|
||||
|
||||
**Pass options to the default reading time function:**
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
// highlight-start
|
||||
readingTime: ({content, defaultReadingTime}) =>
|
||||
defaultReadingTime({content, options: {wordsPerMinute: 100}}),
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="using-custom-algo" label="Using custom algorithms">
|
||||
```
|
||||
|
||||
**Use a custom implementation of reading time:**
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
import myReadingTime from './myReadingTime';
|
||||
|
||||
export default {
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
// highlight-next-line
|
||||
readingTime: ({content}) => myReadingTime(content),
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Feed {#feed}
|
||||
|
||||
You can generate RSS / Atom / JSON feed by passing `feedOptions`. By default, RSS and Atom feeds are generated. To disable feed generation, set `feedOptions.type` to `null`.
|
||||
|
||||
```ts
|
||||
type FeedType = 'rss' | 'atom' | 'json';
|
||||
|
||||
type BlogOptions = {
|
||||
feedOptions?: {
|
||||
type?: FeedType | 'all' | FeedType[] | null;
|
||||
title?: string;
|
||||
description?: string;
|
||||
copyright: string;
|
||||
language?: string; // possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
|
||||
limit?: number | false | null; // defaults to 20
|
||||
/** Allow control over the construction of BlogFeedItems */
|
||||
createFeedItems?: (params: {
|
||||
blogPosts: BlogPost[];
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
defaultCreateFeedItems: (params: {
|
||||
blogPosts: BlogPost[];
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
}) => Promise<BlogFeedItem[]>;
|
||||
}) => Promise<BlogFeedItem[]>;
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Example usage:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
blog: {
|
||||
// highlight-start
|
||||
feedOptions: {
|
||||
type: 'all',
|
||||
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`,
|
||||
createFeedItems: async (params) => {
|
||||
const {blogPosts, defaultCreateFeedItems, ...rest} = params;
|
||||
return defaultCreateFeedItems({
|
||||
// keep only the 10 most recent blog posts in the feed
|
||||
blogPosts: blogPosts.filter((item, index) => index < 10),
|
||||
...rest,
|
||||
});
|
||||
},
|
||||
},
|
||||
// highlight-end
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
The feeds can be found at:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="RSS">
|
||||
|
||||
```text
|
||||
https://example.com/blog/rss.xml
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="Atom">
|
||||
|
||||
```text
|
||||
https://example.com/blog/atom.xml
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="JSON">
|
||||
|
||||
```text
|
||||
https://example.com/blog/feed.json
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Advanced topics {#advanced-topics}
|
||||
|
||||
### Blog-only mode {#blog-only-mode}
|
||||
|
||||
You can run your Docusaurus site without a dedicated landing page and instead have your blog's post list page as the index page. Set the `routeBasePath` to be `'/'` to serve the blog through the root route `example.com/` instead of the subroute `example.com/blog/`.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
// highlight-next-line
|
||||
docs: false, // Optional: disable the docs plugin
|
||||
blog: {
|
||||
// highlight-next-line
|
||||
routeBasePath: '/', // Serve the blog at the site's root
|
||||
/* other blog options */
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
:::warning
|
||||
|
||||
Don't forget to delete the existing homepage at `./src/pages/index.js` or else there will be two files mapping to the same route!
|
||||
|
||||
:::
|
||||
|
||||
:::warning
|
||||
|
||||
If you disable the docs plugin, don't forget to delete references to the docs plugin elsewhere in your configuration file. Notably, make sure to remove the docs-related navbar items.
|
||||
|
||||
:::
|
||||
|
||||
:::tip
|
||||
|
||||
There's also a "Docs-only mode" for those who only want to use the docs. Read [Docs-only mode](./guides/docs/docs-introduction.mdx) for detailed instructions or a more elaborate explanation of `routeBasePath`.
|
||||
|
||||
:::
|
||||
|
||||
### Multiple blogs {#multiple-blogs}
|
||||
|
||||
By default, the classic theme assumes only one blog per website and hence includes only one instance of the blog plugin. If you would like to have multiple blogs on a single website, it's possible too! You can add another blog by specifying another blog plugin in the `plugins` option for `docusaurus.config.js`.
|
||||
|
||||
Set the `routeBasePath` to the URL route that you want your second blog to be accessed on. Note that the `routeBasePath` here has to be different from the first blog or else there could be a collision of paths! Also, set `path` to the path to the directory containing your second blog's entries.
|
||||
|
||||
As documented for [multi-instance plugins](./using-plugins.mdx#multi-instance-plugins-and-plugin-ids), you need to assign a unique ID to the plugins.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-content-blog',
|
||||
{
|
||||
/**
|
||||
* Required for any multi-instance plugin
|
||||
*/
|
||||
id: 'second-blog',
|
||||
/**
|
||||
* URL route for the blog section of your site.
|
||||
* *DO NOT* include a trailing slash.
|
||||
*/
|
||||
routeBasePath: 'my-second-blog',
|
||||
/**
|
||||
* Path to data on filesystem relative to site dir.
|
||||
*/
|
||||
path: './my-second-blog',
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
As an example, we host a second blog [here](/tests/blog).
|
106
website/versioned_docs/version-3.3.2/browser-support.mdx
Normal file
106
website/versioned_docs/version-3.3.2/browser-support.mdx
Normal file
|
@ -0,0 +1,106 @@
|
|||
---
|
||||
description: How to keep a reasonable bundle size while ensuring sufficient browser support.
|
||||
---
|
||||
|
||||
# Browser support
|
||||
|
||||
Docusaurus allows sites to define the list of supported browsers through a [browserslist configuration](https://github.com/browserslist/browserslist).
|
||||
|
||||
## Purpose {#purpose}
|
||||
|
||||
Websites need to balance between backward compatibility and bundle size. As old browsers do not support modern APIs or syntax, more code is needed to implement the same functionality.
|
||||
|
||||
For example, you may use the [optional chaining syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining):
|
||||
|
||||
```js
|
||||
const value = obj?.prop?.val;
|
||||
```
|
||||
|
||||
...which unfortunately is only recognized by browser versions released after 2020. To be compatible with earlier browser versions, when building your site for production, our JS loader will transpile your code to a more verbose syntax:
|
||||
|
||||
```js
|
||||
var _obj, _obj$prop;
|
||||
|
||||
const value =
|
||||
(_obj = obj) === null || _obj === void 0
|
||||
? void 0
|
||||
: (_obj$prop = _obj.prop) === null || _obj$prop === void 0
|
||||
? void 0
|
||||
: _obj$prop.val;
|
||||
```
|
||||
|
||||
However, this penalizes all other users with increased site load time because the 29-character line now becomes 168 characters—a 6-fold increase! (In practice, it will be better because the names used will be shorter.) As a tradeoff, the JS loader only transpiles the syntax to the degree that's supported by all browser versions defined in the browser list.
|
||||
|
||||
The browser list by default is provided through the `package.json` file as a root `browserslist` field.
|
||||
|
||||
:::warning
|
||||
|
||||
On old browsers, the compiled output will use unsupported (too recent) JS syntax, causing React to fail to initialize and end up with a static website with only HTML/CSS and no JS.
|
||||
|
||||
:::
|
||||
|
||||
## Default values {#default-values}
|
||||
|
||||
Websites initialized with the default classic template has the following in `package.json`:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"name": "docusaurus",
|
||||
// ...
|
||||
// highlight-start
|
||||
"browserslist": {
|
||||
"production": [">0.5%", "not dead", "not op_mini all"],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
// highlight-end
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Explained in natural language, the browsers supported in production are those:
|
||||
|
||||
- With more than 0.5% of market share; _and_
|
||||
- Has official support or updates in the past 24 months (the opposite of "dead"); _and_
|
||||
- Is not Opera Mini.
|
||||
|
||||
And browsers used in development are:
|
||||
|
||||
- The latest version of Chrome _or_ Firefox _or_ Safari.
|
||||
|
||||
You can "evaluate" any config with the `browserslist` CLI to obtain the actual list:
|
||||
|
||||
```bash
|
||||
npx browserslist --env="production"
|
||||
```
|
||||
|
||||
The output is all browsers supported in production. Below is the output in January 2022:
|
||||
|
||||
```text
|
||||
and_chr 96
|
||||
and_uc 12.12
|
||||
chrome 96
|
||||
chrome 95
|
||||
chrome 94
|
||||
edge 96
|
||||
firefox 95
|
||||
firefox 94
|
||||
ie 11
|
||||
ios_saf 15.2
|
||||
ios_saf 15.0-15.1
|
||||
ios_saf 14.5-14.8
|
||||
ios_saf 14.0-14.4
|
||||
ios_saf 12.2-12.5
|
||||
opera 82
|
||||
opera 81
|
||||
safari 15.1
|
||||
safari 14.1
|
||||
safari 13.1
|
||||
```
|
||||
|
||||
## Read more {#read-more}
|
||||
|
||||
You may wish to visit the [browserslist documentation](https://github.com/browserslist/browserslist/blob/main/README.md) for more specifications, especially the accepted [query values](https://github.com/browserslist/browserslist/blob/main/README.md#queries) and [best practices](https://github.com/browserslist/browserslist/blob/main/README.md#best-practices).
|
190
website/versioned_docs/version-3.3.2/cli.mdx
Normal file
190
website/versioned_docs/version-3.3.2/cli.mdx
Normal file
|
@ -0,0 +1,190 @@
|
|||
---
|
||||
description: Docusaurus provides a set of scripts to help you generate, serve, and deploy your website.
|
||||
---
|
||||
|
||||
# CLI
|
||||
|
||||
Docusaurus provides a set of scripts to help you generate, serve, and deploy your website.
|
||||
|
||||
Once your website is bootstrapped, the website source will contain the Docusaurus scripts that you can invoke with your package manager:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
// ...
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
"start": "docusaurus start",
|
||||
"build": "docusaurus build",
|
||||
"swizzle": "docusaurus swizzle",
|
||||
"deploy": "docusaurus deploy",
|
||||
"clear": "docusaurus clear",
|
||||
"serve": "docusaurus serve",
|
||||
"write-translations": "docusaurus write-translations",
|
||||
"write-heading-ids": "docusaurus write-heading-ids"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Docusaurus CLI commands {#docusaurus-cli-commands}
|
||||
|
||||
Below is a list of Docusaurus CLI commands and their usages:
|
||||
|
||||
### `docusaurus start [siteDir]` {#docusaurus-start-sitedir}
|
||||
|
||||
Builds and serves a preview of your site locally with [Webpack Dev Server](https://webpack.js.org/configuration/dev-server).
|
||||
|
||||
#### Options {#options}
|
||||
|
||||
| Name | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `--port` | `3000` | Specifies the port of the dev server. |
|
||||
| `--host` | `localhost` | Specify a host to use. For example, if you want your server to be accessible externally, you can use `--host 0.0.0.0`. |
|
||||
| `--locale` | | Specify site locale to be used. |
|
||||
| `--hot-only` | `false` | Enables Hot Module Replacement without page refresh as a fallback in case of build failures. More information [here](https://webpack.js.org/configuration/dev-server/#devserverhotonly). |
|
||||
| `--no-open` | `false` | Do not open the page automatically in the browser. |
|
||||
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||
| `--poll [optionalIntervalMs]` | `false` | Use polling of files rather than watching for live reload as a fallback in environments where watching doesn't work. More information [here](https://webpack.js.org/configuration/watch/#watchoptionspoll). |
|
||||
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
|
||||
|
||||
:::info
|
||||
|
||||
Please note that some functionality (for example, anchor links) will not work in development. The functionality will work as expected in production.
|
||||
|
||||
:::
|
||||
|
||||
:::info Development over network
|
||||
|
||||
When forwarding port 3000 from a remote server or VM (e.g. GitHub Codespaces), you can run the dev server on `0.0.0.0` to make it listen on the local IP.
|
||||
|
||||
```bash npm2yarn
|
||||
npm run start -- --host 0.0.0.0
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
#### Enabling HTTPS {#enabling-https}
|
||||
|
||||
There are multiple ways to obtain a certificate. We will use [mkcert](https://github.com/FiloSottile/mkcert) as an example.
|
||||
|
||||
1. Run `mkcert localhost` to generate `localhost.pem` + `localhost-key.pem`
|
||||
|
||||
2. Run `mkcert -install` to install the cert in your trust store, and restart your browser
|
||||
|
||||
3. Start the app with Docusaurus HTTPS env variables:
|
||||
|
||||
```bash
|
||||
HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem yarn start
|
||||
```
|
||||
|
||||
4. Open `https://localhost:3000/`
|
||||
|
||||
### `docusaurus build [siteDir]` {#docusaurus-build-sitedir}
|
||||
|
||||
Compiles your site for production.
|
||||
|
||||
#### Options {#options-1}
|
||||
|
||||
| Name | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `--dev` | | Builds the website in dev mode, including full React error messages. |
|
||||
| `--bundle-analyzer` | `false` | Analyze your bundle with the [webpack bundle analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer). |
|
||||
| `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. |
|
||||
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||
| `--locale` | | Build the site in the specified locale. If not specified, all known locales are built. |
|
||||
| `--no-minify` | `false` | Build website without minimizing JS/CSS bundles. |
|
||||
|
||||
:::info
|
||||
|
||||
For advanced minification of CSS bundle, we use the [advanced cssnano preset](https://github.com/cssnano/cssnano/tree/master/packages/cssnano-preset-advanced) (along with additional several PostCSS plugins) and [level 2 optimization of clean-css](https://github.com/jakubpawlowicz/clean-css#level-2-optimizations). If as a result of this advanced CSS minification you find broken CSS, build your website with the environment variable `USE_SIMPLE_CSS_MINIFIER=true` to minify CSS with the [default cssnano preset](https://github.com/cssnano/cssnano/tree/master/packages/cssnano-preset-default). **Please [fill out an issue](https://github.com/facebook/docusaurus/issues/new?labels=bug%2C+needs+triage&template=bug.md) if you experience CSS minification bugs.**
|
||||
|
||||
You can skip the HTML minification with the environment variable `SKIP_HTML_MINIFICATION=true`.
|
||||
|
||||
:::
|
||||
|
||||
### `docusaurus swizzle [themeName] [componentName] [siteDir]` {#docusaurus-swizzle}
|
||||
|
||||
[Swizzle](./swizzling.mdx) a theme component to customize it.
|
||||
|
||||
```bash npm2yarn
|
||||
npm run swizzle [themeName] [componentName] [siteDir]
|
||||
|
||||
# Example (leaving out the siteDir to indicate this directory)
|
||||
npm run swizzle @docusaurus/theme-classic Footer -- --eject
|
||||
```
|
||||
|
||||
The swizzle CLI is interactive and will guide you through the whole [swizzle process](./swizzling.mdx).
|
||||
|
||||
#### Options {#options-swizzle}
|
||||
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| `themeName` | The name of the theme to swizzle from. |
|
||||
| `componentName` | The name of the theme component to swizzle. |
|
||||
| `--list` | Display components available for swizzling |
|
||||
| `--eject` | [Eject](./swizzling.mdx#ejecting) the theme component |
|
||||
| `--wrap` | [Wrap](./swizzling.mdx#wrapping) the theme component |
|
||||
| `--danger` | Allow immediate swizzling of unsafe components |
|
||||
| `--typescript` | Swizzle the TypeScript variant component |
|
||||
| `--config` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||
|
||||
:::warning
|
||||
|
||||
Unsafe components have a higher risk of breaking changes due to internal refactorings.
|
||||
|
||||
:::
|
||||
|
||||
### `docusaurus deploy [siteDir]` {#docusaurus-deploy-sitedir}
|
||||
|
||||
Deploys your site with [GitHub Pages](https://pages.github.com/). Check out the docs on [deployment](deployment.mdx#deploying-to-github-pages) for more details.
|
||||
|
||||
#### Options {#options-3}
|
||||
|
||||
| Name | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `--locale` | | Deploy the site in the specified locale. If not specified, all known locales are deployed. |
|
||||
| `--out-dir` | `build` | The full path for the new output directory, relative to the current workspace. |
|
||||
| `--skip-build` | `false` | Deploy website without building it. This may be useful when using a custom deploy script. |
|
||||
| `--target-dir` | `.` | Path to the target directory to deploy to. |
|
||||
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||
|
||||
### `docusaurus serve [siteDir]` {#docusaurus-serve-sitedir}
|
||||
|
||||
Serve your built website locally.
|
||||
|
||||
| Name | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `--port` | `3000` | Use specified port |
|
||||
| `--dir` | `build` | The full path for the output directory, relative to the current workspace |
|
||||
| `--build` | `false` | Build website before serving |
|
||||
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||
| `--host` | `localhost` | Specify a host to use. For example, if you want your server to be accessible externally, you can use `--host 0.0.0.0`. |
|
||||
| `--no-open` | `false` locally, `true` in CI | Do not open a browser window to the server location. |
|
||||
|
||||
### `docusaurus clear [siteDir]` {#docusaurus-clear-sitedir}
|
||||
|
||||
Clear a Docusaurus site's generated assets, caches, build artifacts.
|
||||
|
||||
We recommend running this command before reporting bugs, after upgrading versions, or anytime you have issues with your Docusaurus site.
|
||||
|
||||
### `docusaurus write-translations [siteDir]` {#docusaurus-write-translations-sitedir}
|
||||
|
||||
Write the JSON translation files that you will have to translate.
|
||||
|
||||
By default, the files are written in `website/i18n/<defaultLocale>/...`.
|
||||
|
||||
| Name | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `--locale` | `<defaultLocale>` | Define which locale folder you want to write translations the JSON files in |
|
||||
| `--override` | `false` | Override existing translation messages |
|
||||
| `--config` | `undefined` | Path to Docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
|
||||
| `--messagePrefix` | `''` | Allows adding a prefix to each translation message, to help you highlight untranslated strings |
|
||||
|
||||
### `docusaurus write-heading-ids [siteDir] [files]` {#docusaurus-write-heading-ids-sitedir}
|
||||
|
||||
Add [explicit heading IDs](./guides/markdown-features/markdown-features-toc.mdx#heading-ids) to the Markdown documents of your site.
|
||||
|
||||
| Name | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `files` | All MD files used by plugins | The files that you want heading IDs to be written to. |
|
||||
| `--maintain-case` | `false` | Keep the headings' casing, otherwise make all lowercase. |
|
||||
| `--overwrite` | `false` | Overwrite existing heading IDs. |
|
286
website/versioned_docs/version-3.3.2/configuration.mdx
Normal file
286
website/versioned_docs/version-3.3.2/configuration.mdx
Normal file
|
@ -0,0 +1,286 @@
|
|||
---
|
||||
description: Configuring your site's behavior through docusaurus.config.js and more.
|
||||
---
|
||||
|
||||
# Configuration
|
||||
|
||||
import TOCInline from '@theme/TOCInline';
|
||||
|
||||
:::info
|
||||
|
||||
Check the [**`docusaurus.config.js` API reference**](api/docusaurus.config.js.mdx) for an exhaustive list of options.
|
||||
|
||||
:::
|
||||
|
||||
Docusaurus has a unique take on configurations. We encourage you to congregate information about your site into one place. We guard the fields of this file and facilitate making this data object accessible across your site.
|
||||
|
||||
Keeping a well-maintained `docusaurus.config.js` helps you, your collaborators, and your open source contributors to be able to focus on documentation while still being able to customize the site.
|
||||
|
||||
## Syntax to declare `docusaurus.config.js` {#syntax-to-declare-docusaurus-config}
|
||||
|
||||
The `docusaurus.config.js` file is run in Node.js and should export either:
|
||||
|
||||
- a **config object**
|
||||
- a **function** that creates the config object
|
||||
|
||||
:::info
|
||||
|
||||
The `docusaurus.config.js` file supports:
|
||||
|
||||
- [**ES Modules**](https://flaviocopes.com/es-modules/)
|
||||
- [**CommonJS**](https://flaviocopes.com/commonjs/)
|
||||
- [**TypeScript**](./typescript-support.mdx#typing-config)
|
||||
|
||||
Constraints:
|
||||
|
||||
- **Required:** use `export default /* your config*/` (or `module.exports` to export your Docusaurus config
|
||||
- **Optional:** use `import Lib from 'lib'` (or `require('lib')`) to import Node.js packages
|
||||
|
||||
:::
|
||||
|
||||
Docusaurus gives us the ability to declare its configuration in various **equivalent ways**, and all the following config examples lead to the exact same result:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
```
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
```
|
||||
|
||||
```ts title="docusaurus.config.ts"
|
||||
import type {Config} from '@docusaurus/types';
|
||||
|
||||
export default {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
} satisfies Config;
|
||||
```
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
const config = {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default function configCreator() {
|
||||
return {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default async function createConfigAsync() {
|
||||
return {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// your site config ...
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::tip Using ESM-only packages
|
||||
|
||||
Using an async config creator can be useful to import ESM-only modules (notably most Remark plugins). It is possible to import such modules thanks to dynamic imports:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default async function createConfigAsync() {
|
||||
// Use a dynamic import instead of require('esm-lib')
|
||||
// highlight-next-line
|
||||
const lib = await import('lib');
|
||||
|
||||
return {
|
||||
title: 'Docusaurus',
|
||||
url: 'https://docusaurus.io',
|
||||
// rest of your site config...
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## What goes into a `docusaurus.config.js`? {#what-goes-into-a-docusaurusconfigjs}
|
||||
|
||||
You should not have to write your `docusaurus.config.js` from scratch even if you are developing your site. All templates come with a `docusaurus.config.js` that includes defaults for the common options.
|
||||
|
||||
However, it can be helpful if you have a high-level understanding of how the configurations are designed and implemented.
|
||||
|
||||
The high-level overview of Docusaurus configuration can be categorized into:
|
||||
|
||||
<TOCInline toc={toc} minHeadingLevel={3} maxHeadingLevel={3} />
|
||||
|
||||
### Site metadata {#site-metadata}
|
||||
|
||||
Site metadata contains the essential global metadata such as `title`, `url`, `baseUrl`, and `favicon`.
|
||||
|
||||
They are used in several places such as your site's title and headings, browser tab icon, social sharing (Facebook, Twitter) information or even to generate the correct path to serve your static files.
|
||||
|
||||
### Deployment configurations {#deployment-configurations}
|
||||
|
||||
Deployment configurations such as `projectName`, `organizationName`, and optionally `deploymentBranch` are used when you deploy your site with the `deploy` command.
|
||||
|
||||
It is recommended to check the [deployment docs](deployment.mdx) for more information.
|
||||
|
||||
### Theme, plugin, and preset configurations {#theme-plugin-and-preset-configurations}
|
||||
|
||||
List the [themes](./using-plugins.mdx#using-themes), [plugins](./using-plugins.mdx), and [presets](./using-plugins.mdx#using-presets) for your site in the `themes`, `plugins`, and `presets` fields, respectively. These are typically npm packages:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
plugins: [
|
||||
'@docusaurus/plugin-content-blog',
|
||||
'@docusaurus/plugin-content-pages',
|
||||
],
|
||||
themes: ['@docusaurus/theme-classic'],
|
||||
};
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
Docusaurus supports [**module shorthands**](./using-plugins.mdx#module-shorthands), allowing you to simplify the above configuration as:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
plugins: ['content-blog', 'content-pages'],
|
||||
themes: ['classic'],
|
||||
};
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
They can also be loaded from local directories:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
import path from 'path';
|
||||
|
||||
export default {
|
||||
// ...
|
||||
themes: [path.resolve(__dirname, '/path/to/docusaurus-local-theme')],
|
||||
};
|
||||
```
|
||||
|
||||
To specify options for a plugin or theme, replace the name of the plugin or theme in the config file with an array containing the name and an options object:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
plugins: [
|
||||
[
|
||||
'content-blog',
|
||||
{
|
||||
path: 'blog',
|
||||
routeBasePath: 'blog',
|
||||
include: ['*.md', '*.mdx'],
|
||||
// ...
|
||||
},
|
||||
],
|
||||
'content-pages',
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
To specify options for a plugin or theme that is bundled in a preset, pass the options through the `presets` field. In this example, `docs` refers to `@docusaurus/plugin-content-docs` and `theme` refers to `@docusaurus/theme-classic`.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
presets: [
|
||||
[
|
||||
'@docusaurus/preset-classic',
|
||||
{
|
||||
docs: {
|
||||
sidebarPath: './sidebars.js',
|
||||
},
|
||||
theme: {
|
||||
customCss: ['./src/css/custom.css'],
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
The `presets: [['classic', {...}]]` shorthand works as well.
|
||||
|
||||
:::
|
||||
|
||||
For further help configuring themes, plugins, and presets, see [Using Plugins](./using-plugins.mdx).
|
||||
|
||||
### Custom configurations {#custom-configurations}
|
||||
|
||||
Docusaurus guards `docusaurus.config.js` from unknown fields. To add custom fields, define them in `customFields`.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
// highlight-start
|
||||
customFields: {
|
||||
image: '',
|
||||
keywords: [],
|
||||
},
|
||||
// highlight-end
|
||||
// ...
|
||||
};
|
||||
```
|
||||
|
||||
## Accessing configuration from components {#accessing-configuration-from-components}
|
||||
|
||||
Your configuration object will be made available to all the components of your site. And you may access them via React context as `siteConfig`.
|
||||
|
||||
Basic example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
const Hello = () => {
|
||||
// highlight-start
|
||||
const {siteConfig} = useDocusaurusContext();
|
||||
// highlight-end
|
||||
const {title, tagline} = siteConfig;
|
||||
|
||||
return <div>{`${title} · ${tagline}`}</div>;
|
||||
};
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you just want to use those fields on the client side, you could create your own JS files and import them as ES6 modules, there is no need to put them in `docusaurus.config.js`.
|
||||
|
||||
:::
|
||||
|
||||
## Customizing Babel Configuration {#customizing-babel-configuration}
|
||||
|
||||
For new Docusaurus projects, we automatically generated a `babel.config.js` in the project root.
|
||||
|
||||
```js title="babel.config.js"
|
||||
export default {
|
||||
presets: ['@docusaurus/core/lib/babel/preset'],
|
||||
};
|
||||
```
|
||||
|
||||
Most of the time, this configuration will work just fine. If you want to customize your Babel configuration (e.g. to add support for Flow), you can directly edit this file. For your changes to take effect, you need to restart the Docusaurus dev server.
|
853
website/versioned_docs/version-3.3.2/deployment.mdx
Normal file
853
website/versioned_docs/version-3.3.2/deployment.mdx
Normal file
|
@ -0,0 +1,853 @@
|
|||
---
|
||||
description: Deploy your Docusaurus app for production on a range of static site hosting services.
|
||||
---
|
||||
|
||||
# Deployment
|
||||
|
||||
To build the static files of your website for production, run:
|
||||
|
||||
```bash npm2yarn
|
||||
npm run build
|
||||
```
|
||||
|
||||
Once it finishes, the static files will be generated within the `build` directory.
|
||||
|
||||
:::note
|
||||
|
||||
The only responsibility of Docusaurus is to build your site and emit static files in `build`.
|
||||
|
||||
It is now up to you to choose how to host those static files.
|
||||
|
||||
:::
|
||||
|
||||
You can deploy your site to static site hosting services such as [Vercel](https://vercel.com/), [GitHub Pages](https://pages.github.com/), [Netlify](https://www.netlify.com/), [Render](https://render.com/docs/static-sites), and [Surge](https://surge.sh/help/getting-started-with-surge).
|
||||
|
||||
A Docusaurus site is statically rendered, and it can generally work without JavaScript!
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
The following parameters are required in `docusaurus.config.js` to optimize routing and serve files from the correct location:
|
||||
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| `url` | URL for your site. For a site deployed at `https://my-org.com/my-project/`, `url` is `https://my-org.com/`. |
|
||||
| `baseUrl` | Base URL for your project, with a trailing slash. For a site deployed at `https://my-org.com/my-project/`, `baseUrl` is `/my-project/`. |
|
||||
|
||||
## Testing your Build Locally {#testing-build-locally}
|
||||
|
||||
It is important to test your build locally before deploying it for production. Docusaurus provides a [`docusaurus serve`](cli.mdx#docusaurus-serve-sitedir) command for that:
|
||||
|
||||
```bash npm2yarn
|
||||
npm run serve
|
||||
```
|
||||
|
||||
By default, this will load your site at [`http://localhost:3000/`](http://localhost:3000/).
|
||||
|
||||
## Trailing slash configuration {#trailing-slashes}
|
||||
|
||||
Docusaurus has a [`trailingSlash` config](./api/docusaurus.config.js.mdx#trailingSlash) to allow customizing URLs/links and emitted filename patterns.
|
||||
|
||||
The default value generally works fine. Unfortunately, each static hosting provider has a **different behavior**, and deploying the exact same site to various hosts can lead to distinct results. Depending on your host, it can be useful to change this config.
|
||||
|
||||
:::tip
|
||||
|
||||
Use [slorber/trailing-slash-guide](https://github.com/slorber/trailing-slash-guide) to understand better the behavior of your host and configure `trailingSlash` appropriately.
|
||||
|
||||
:::
|
||||
|
||||
## Using environment variables {#using-environment-variables}
|
||||
|
||||
Putting potentially sensitive information in the environment is common practice. However, in a typical Docusaurus website, the `docusaurus.config.js` file is the only interface to the Node.js environment (see [our architecture overview](advanced/architecture.mdx)), while everything else (MDX pages, React components, etc.) are client side and do not have direct access to the `process` global variable. In this case, you can consider using [`customFields`](api/docusaurus.config.js.mdx#customFields) to pass environment variables to the client side.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
// If you are using dotenv (https://www.npmjs.com/package/dotenv)
|
||||
import 'dotenv/config';
|
||||
|
||||
export default {
|
||||
title: '...',
|
||||
url: process.env.URL, // You can use environment variables to control site specifics as well
|
||||
// highlight-start
|
||||
customFields: {
|
||||
// Put your custom environment here
|
||||
teamEmail: process.env.EMAIL,
|
||||
},
|
||||
// highlight-end
|
||||
};
|
||||
```
|
||||
|
||||
```jsx title="home.jsx"
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
export default function Home() {
|
||||
const {
|
||||
siteConfig: {customFields},
|
||||
} = useDocusaurusContext();
|
||||
return <div>Contact us through {customFields.teamEmail}!</div>;
|
||||
}
|
||||
```
|
||||
|
||||
## Choosing a hosting provider {#choosing-a-hosting-provider}
|
||||
|
||||
There are a few common hosting options:
|
||||
|
||||
- [Self hosting](#self-hosting) with an HTTP server like Apache2 or Nginx.
|
||||
- Jamstack providers (e.g. [Netlify](#deploying-to-netlify) and [Vercel](#deploying-to-vercel)). We will use them as references, but the same reasoning can apply to other providers.
|
||||
- [GitHub Pages](#deploying-to-github-pages) (by definition, it is also Jamstack, but we compare it separately).
|
||||
|
||||
If you are unsure of which one to choose, ask the following questions:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>
|
||||
How many resources (money, person-hours, etc.) am I willing to invest in this?
|
||||
</summary>
|
||||
|
||||
- 🔴 Self-hosting requires experience in networking as well as Linux and web server administration. It's the most difficult option, and would require the most time to manage successfully. Expense-wise, cloud services are almost never free, and purchasing/deploying an onsite server can be even more costly.
|
||||
- 🟢 Jamstack providers can help you set up a working website in almost no time and offer features like server-side redirects that are easily configurable. Many providers offer generous build-time quotas even for free plans that you would almost never exceed. However, free plans have limits, and you would need to pay once you hit those limits. Check the pricing page of your provider for details.
|
||||
- 🟡 The GitHub Pages deployment workflow can be tedious to set up. (Evidence: see the length of [Deploying to GitHub Pages](#deploying-to-github-pages)!) However, this service (including build and deployment) is always free for public repositories, and we have detailed instructions to help you make it work.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>How much server-side customization do I need?</summary>
|
||||
|
||||
- 🟢 With self-hosting, you have access to the entire server's configuration. You can configure the virtual host to serve different content based on the request URL, you can do complicated server-side redirects, you can implement authentication, and so on. If you need a lot of server-side features, self-host your website.
|
||||
- 🟡 Jamstack usually offers some server-side configuration (e.g. URL formatting (trailing slashes), server-side redirects, etc.).
|
||||
- 🔴 GitHub Pages doesn't expose server-side configuration besides enforcing HTTPS and setting CNAME records.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Do I need collaboration-friendly deployment workflows?</summary>
|
||||
|
||||
- 🟡 Self-hosted services can leverage continuous deployment functionality like Netlify, but more heavy-lifting is involved. Usually, you would designate a specific person to manage the deployment, and the workflow wouldn't be very git-based as opposed to the other two options.
|
||||
- 🟢 Netlify and Vercel have deploy previews for every pull request, which is useful for a team to review work before merging to production. You can also manage a team with different member access to the deployment.
|
||||
- 🟡 GitHub Pages cannot do deploy previews in a non-convoluted way. One repo can only be associated with one site deployment. On the other hand, you can control who has write access to the site's deployment.
|
||||
|
||||
</details>
|
||||
|
||||
There isn't a silver bullet. You need to weigh your needs and resources before making a choice.
|
||||
|
||||
## Self-Hosting {#self-hosting}
|
||||
|
||||
Docusaurus can be self-hosted using [`docusaurus serve`](cli.mdx#docusaurus-serve-sitedir). Change port using `--port` and `--host` to change host.
|
||||
|
||||
```bash npm2yarn
|
||||
npm run serve -- --build --port 80 --host 0.0.0.0
|
||||
```
|
||||
|
||||
:::warning
|
||||
|
||||
It is not the best option, compared to a static hosting provider / CDN.
|
||||
|
||||
:::
|
||||
|
||||
:::warning
|
||||
|
||||
In the following sections, we will introduce a few common hosting providers and how they should be configured to deploy Docusaurus sites most efficiently. Docusaurus is not affiliated with any of these services, and this information is provided for convenience only. Some of the write-ups are provided by third-parties, and recent API changes may not be reflected on our side. If you see outdated content, PRs are welcome.
|
||||
|
||||
Because we can only provide this content on a best-effort basis only, we have stopped accepting PRs adding new hosting options. You can, however, publish your writeup on a separate site (e.g. your blog, or the provider's official website), and ask us to include a link to your writeup.
|
||||
|
||||
:::
|
||||
|
||||
## Deploying to Netlify {#deploying-to-netlify}
|
||||
|
||||
To deploy your Docusaurus sites to [Netlify](https://www.netlify.com/), first make sure the following options are properly configured:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// highlight-start
|
||||
url: 'https://docusaurus-2.netlify.app', // Url to your site with no trailing slash
|
||||
baseUrl: '/', // Base directory of your site relative to your repo
|
||||
// highlight-end
|
||||
// ...
|
||||
};
|
||||
```
|
||||
|
||||
Then, [create your site with Netlify](https://app.netlify.com/start).
|
||||
|
||||
While you set up the site, specify the build commands and directories as follows:
|
||||
|
||||
- build command: `npm run build`
|
||||
- publish directory: `build`
|
||||
|
||||
If you did not configure these build options, you may still go to "Site settings" -> "Build & deploy" after your site is created.
|
||||
|
||||
Once properly configured with the above options, your site should deploy and automatically redeploy upon merging to your deploy branch, which defaults to `main`.
|
||||
|
||||
:::warning
|
||||
|
||||
Some Docusaurus sites put the `docs` folder outside of `website` (most likely former Docusaurus v1 sites):
|
||||
|
||||
```bash
|
||||
repo # git root
|
||||
├── docs # MD files
|
||||
└── website # Docusaurus root
|
||||
```
|
||||
|
||||
If you decide to use the `website` folder as Netlify's base directory, Netlify will not trigger builds when you update the `docs` folder, and you need to configure a [custom `ignore` command](https://docs.netlify.com/configure-builds/common-configurations/ignore-builds/):
|
||||
|
||||
```toml title="website/netlify.toml"
|
||||
[build]
|
||||
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../docs/"
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
:::warning
|
||||
|
||||
By default, Netlify adds trailing slashes to Docusaurus URLs.
|
||||
|
||||
It is recommended to disable the Netlify setting `Post Processing > Asset Optimization > Pretty Urls` to prevent lowercase URLs, unnecessary redirects, and 404 errors.
|
||||
|
||||
**Be very careful**: the `Disable asset optimization` global checkbox is broken and does not really disable the `Pretty URLs` setting in practice. Please make sure to **uncheck it independently**.
|
||||
|
||||
If you want to keep the `Pretty Urls` Netlify setting on, adjust the `trailingSlash` Docusaurus config appropriately.
|
||||
|
||||
Refer to [slorber/trailing-slash-guide](https://github.com/slorber/trailing-slash-guide) for more information.
|
||||
|
||||
:::
|
||||
|
||||
## Deploying to Vercel {#deploying-to-vercel}
|
||||
|
||||
Deploying your Docusaurus project to [Vercel](https://vercel.com/) will provide you with [various benefits](https://vercel.com/) in the areas of performance and ease of use.
|
||||
|
||||
To deploy your Docusaurus project with a [Vercel for Git Integration](https://vercel.com/docs/concepts/git), make sure it has been pushed to a Git repository.
|
||||
|
||||
Import the project into Vercel using the [Import Flow](https://vercel.com/import/git). During the import, you will find all relevant options preconfigured for you; however, you can choose to change any of these [options](https://vercel.com/docs/build-step#build-&-development-settings).
|
||||
|
||||
After your project has been imported, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/platform/deployments#preview), and all changes made to the [Production Branch](https://vercel.com/docs/git-integrations#production-branch) (usually "main" or "master") will result in a [Production Deployment](https://vercel.com/docs/platform/deployments#production).
|
||||
|
||||
## Deploying to GitHub Pages {#deploying-to-github-pages}
|
||||
|
||||
Docusaurus provides an easy way to publish to [GitHub Pages](https://pages.github.com/), which comes free with every GitHub repository.
|
||||
|
||||
### Overview {#github-pages-overview}
|
||||
|
||||
Usually, there are two repositories (at least two branches) involved in a publishing process: the branch containing the source files, and the branch containing the build output to be served with GitHub Pages. In the following tutorial, they will be referred to as **"source"** and **"deployment"**, respectively.
|
||||
|
||||
Each GitHub repository is associated with a GitHub Pages service. If the deployment repository is called `my-org/my-project` (where `my-org` is the organization name or username), the deployed site will appear at `https://my-org.github.io/my-project/`. If the deployment repository is called `my-org/my-org.github.io` (the _organization GitHub Pages repo_), the site will appear at `https://my-org.github.io/`.
|
||||
|
||||
:::info
|
||||
|
||||
In case you want to use your custom domain for GitHub Pages, create a `CNAME` file in the `static` directory. Anything within the `static` directory will be copied to the root of the `build` directory for deployment. When using a custom domain, you should be able to move back from `baseUrl: '/projectName/'` to `baseUrl: '/'`, and also set your `url` to your custom domain.
|
||||
|
||||
You may refer to GitHub Pages' documentation [User, Organization, and Project Pages](https://help.github.com/en/articles/user-organization-and-project-pages) for more details.
|
||||
|
||||
:::
|
||||
|
||||
GitHub Pages picks up deploy-ready files (the output from `docusaurus build`) from the default branch (`master` / `main`, usually) or the `gh-pages` branch, and either from the root or the `/docs` folder. You can configure that through `Settings > Pages` in your repository. This branch will be called the "deployment branch".
|
||||
|
||||
We provide a `docusaurus deploy` command that helps you deploy your site from the source branch to the deployment branch in one command: clone, build, and commit.
|
||||
|
||||
### `docusaurus.config.js` settings {#docusaurusconfigjs-settings}
|
||||
|
||||
First, modify your `docusaurus.config.js` and add the following params:
|
||||
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| `organizationName` | The GitHub user or organization that owns the deployment repository. |
|
||||
| `projectName` | The name of the deployment repository. |
|
||||
| `deploymentBranch` | The name of the deployment branch. It defaults to `'gh-pages'` for non-organization GitHub Pages repos (`projectName` not ending in `.github.io`). Otherwise, it needs to be explicit as a config field or environment variable. |
|
||||
|
||||
These fields also have their environment variable counterparts which have a higher priority: `ORGANIZATION_NAME`, `PROJECT_NAME`, and `DEPLOYMENT_BRANCH`.
|
||||
|
||||
:::warning
|
||||
|
||||
GitHub Pages adds a trailing slash to Docusaurus URLs by default. It is recommended to set a `trailingSlash` config (`true` or `false`, not `undefined`).
|
||||
|
||||
:::
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
export default {
|
||||
// ...
|
||||
url: 'https://endiliey.github.io', // Your website URL
|
||||
baseUrl: '/',
|
||||
// highlight-start
|
||||
projectName: 'endiliey.github.io',
|
||||
organizationName: 'endiliey',
|
||||
trailingSlash: false,
|
||||
// highlight-end
|
||||
// ...
|
||||
};
|
||||
```
|
||||
|
||||
:::warning
|
||||
|
||||
By default, GitHub Pages runs published files through [Jekyll](https://jekyllrb.com/). Since Jekyll will discard any files that begin with `_`, it is recommended that you disable Jekyll by adding an empty file named `.nojekyll` file to your `static` directory.
|
||||
|
||||
:::
|
||||
|
||||
### Environment settings {#environment-settings}
|
||||
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| `USE_SSH` | Set to `true` to use SSH instead of the default HTTPS for the connection to the GitHub repo. If the source repo URL is an SSH URL (e.g. `git@github.com:facebook/docusaurus.git`), `USE_SSH` is inferred to be `true`. |
|
||||
| `GIT_USER` | The username for a GitHub account that **has push access to the deployment repo**. For your own repositories, this will usually be your GitHub username. Required if not using SSH, and ignored otherwise. |
|
||||
| `GIT_PASS` | Personal access token of the git user (specified by `GIT_USER`), to facilitate non-interactive deployment (e.g. continuous deployment) |
|
||||
| `CURRENT_BRANCH` | The source branch. Usually, the branch will be `main` or `master`, but it could be any branch except for `gh-pages`. If nothing is set for this variable, then the current branch from which `docusaurus deploy` is invoked will be used. |
|
||||
| `GIT_USER_NAME` | The `git config user.name` value to use when pushing to the deployment repo |
|
||||
| `GIT_USER_EMAIL` | The `git config user.email` value to use when pushing to the deployment repo |
|
||||
|
||||
GitHub enterprise installations should work in the same manner as github.com; you only need to set the organization's GitHub Enterprise host as an environment variable:
|
||||
|
||||
| Name | Description |
|
||||
| ------------- | ----------------------------------------------- |
|
||||
| `GITHUB_HOST` | The domain name of your GitHub enterprise site. |
|
||||
| `GITHUB_PORT` | The port of your GitHub enterprise site. |
|
||||
|
||||
### Deploy {#deploy}
|
||||
|
||||
Finally, to deploy your site to GitHub Pages, run:
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="bash" label="Bash">
|
||||
```
|
||||
|
||||
```bash
|
||||
GIT_USER=<GITHUB_USERNAME> yarn deploy
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="windows" label="Windows">
|
||||
```
|
||||
|
||||
```batch
|
||||
cmd /C "set "GIT_USER=<GITHUB_USERNAME>" && yarn deploy"
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="powershell" label="PowerShell">
|
||||
```
|
||||
|
||||
```powershell
|
||||
cmd /C 'set "GIT_USER=<GITHUB_USERNAME>" && yarn deploy'
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
:::warning
|
||||
|
||||
Beginning in August 2021, GitHub requires every command-line sign-in to use the **personal access token** instead of the password. When GitHub prompts for your password, enter the PAT instead. See the [GitHub documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) for more information.
|
||||
|
||||
Alternatively, you can use SSH (`USE_SSH=true`) to log in.
|
||||
|
||||
:::
|
||||
|
||||
### Triggering deployment with GitHub Actions {#triggering-deployment-with-github-actions}
|
||||
|
||||
[GitHub Actions](https://help.github.com/en/actions) allow you to automate, customize, and execute your software development workflows right in your repository.
|
||||
|
||||
The workflow examples below assume your website source resides in the `main` branch of your repository (the _source branch_ is `main`), and your [publishing source](https://help.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site) is configured for [publishing with a custom GitHub Actions Workflow](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow).
|
||||
|
||||
Our goal is that:
|
||||
|
||||
1. When a new pull request is made to `main`, there's an action that ensures the site builds successfully, without actually deploying. This job will be called `test-deploy`.
|
||||
2. When a pull request is merged to the `main` branch or someone pushes to the `main` branch directly, it will be built and deployed to GitHub Pages. This job will be called `deploy`.
|
||||
|
||||
Here are two approaches to deploying your docs with GitHub Actions. Based on the location of your deployment repository, choose the relevant tab below:
|
||||
|
||||
- Source repo and deployment repo are the **same** repository.
|
||||
- The deployment repo is a **remote** repository, different from the source. Instructions for this scenario assume [publishing source](https://help.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site) is the `gh-pages` branch.
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="same" label="Same">
|
||||
```
|
||||
|
||||
While you can have both jobs defined in the same workflow file, the original `deploy` workflow will always be listed as skipped in the PR check suite status, which is not indicative of the actual status and provides no value to the review process. We therefore propose to manage them as separate workflows instead.
|
||||
|
||||
<details>
|
||||
<summary>GitHub action files</summary>
|
||||
|
||||
Add these two workflow files:
|
||||
|
||||
:::warning Tweak the parameters for your setup
|
||||
|
||||
These files assume you are using Yarn. If you use npm, change `cache: yarn`, `yarn install --frozen-lockfile`, `yarn build` to `cache: npm`, `npm ci`, `npm run build` accordingly.
|
||||
|
||||
If your Docusaurus project is not at the root of your repo, you may need to configure a [default working directory](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-set-the-default-shell-and-working-directory), and adjust the paths accordingly.
|
||||
|
||||
:::
|
||||
|
||||
```yml title=".github/workflows/deploy.yml"
|
||||
name: Deploy to GitHub Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
# Review gh actions docs if you want to further define triggers, paths, etc
|
||||
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Docusaurus
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
cache: yarn
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
- name: Build website
|
||||
run: yarn build
|
||||
|
||||
- name: Upload Build Artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: build
|
||||
|
||||
deploy:
|
||||
name: Deploy to GitHub Pages
|
||||
needs: build
|
||||
|
||||
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
|
||||
permissions:
|
||||
pages: write # to deploy to Pages
|
||||
id-token: write # to verify the deployment originates from an appropriate source
|
||||
|
||||
# Deploy to the github-pages environment
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
```
|
||||
|
||||
```yml title=".github/workflows/test-deploy.yml"
|
||||
name: Test deployment
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
# Review gh actions docs if you want to further define triggers, paths, etc
|
||||
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
|
||||
|
||||
jobs:
|
||||
test-deploy:
|
||||
name: Test deployment
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
cache: yarn
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
- name: Test build website
|
||||
run: yarn build
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="remote" label="Remote">
|
||||
```
|
||||
|
||||
A cross-repo publish is more difficult to set up because you need to push to another repo with permission checks. We will be using SSH to do the authentication.
|
||||
|
||||
1. Generate a new [SSH key](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent). Since this SSH key will be used in CI, make sure to not enter any passphrase.
|
||||
2. By default, your public key should have been created in `~/.ssh/id_rsa.pub`; otherwise, use the name you've provided in the previous step to add your key to [GitHub deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/).
|
||||
3. Copy the key to clipboard with `pbcopy < ~/.ssh/id_rsa.pub` and paste it as a [deploy key](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) in the deployment repository. Copy the file content if the command line doesn't work for you. Check the box for `Allow write access` before saving your deployment key.
|
||||
4. You'll need your private key as a [GitHub secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) to allow Docusaurus to run the deployment for you.
|
||||
5. Copy your private key with `pbcopy < ~/.ssh/id_rsa` and paste a GitHub secret with the name `GH_PAGES_DEPLOY` on your source repository. Copy the file content if the command line doesn't work for you. Save your secret.
|
||||
6. Create your [documentation workflow file](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#creating-a-workflow-file) in `.github/workflows/`. In this example, it's `deploy.yml`.
|
||||
|
||||
At this point, you should have:
|
||||
|
||||
- the source repo with the GitHub workflow set with the private SSH key as the GitHub Secret, and
|
||||
- your deployment repo set with the public SSH key in GitHub Deploy Keys.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>GitHub action file</summary>
|
||||
|
||||
:::warning
|
||||
|
||||
Please make sure that you replace `actions@github.com` with your GitHub email and `gh-actions` with your name.
|
||||
|
||||
This file assumes you are using Yarn. If you use npm, change `cache: yarn`, `yarn install --frozen-lockfile`, `yarn build` to `cache: npm`, `npm ci`, `npm run build` accordingly.
|
||||
|
||||
:::
|
||||
|
||||
```yml title=".github/workflows/deploy.yml"
|
||||
name: Deploy to GitHub Pages
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
test-deploy:
|
||||
if: github.event_name != 'push'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
cache: yarn
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
- name: Test build website
|
||||
run: yarn build
|
||||
deploy:
|
||||
if: github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
cache: yarn
|
||||
- uses: webfactory/ssh-agent@v0.5.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.GH_PAGES_DEPLOY }}
|
||||
- name: Deploy to GitHub Pages
|
||||
env:
|
||||
USE_SSH: true
|
||||
run: |
|
||||
git config --global user.email "actions@github.com"
|
||||
git config --global user.name "gh-actions"
|
||||
yarn install --frozen-lockfile
|
||||
yarn deploy
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Site not deployed properly?</summary>
|
||||
|
||||
After pushing to main, if you don't see your site published at the desired location (for example, it says "There isn't a GitHub Pages site here", or it's showing your repo's README.md file), try the following:
|
||||
|
||||
- Wait about three minutes and refresh. It may take a few minutes for GitHub pages to pick up the new files.
|
||||
- Check your repo's landing page for a little green tick next to the last commit's title, indicating the CI has passed. If you see a cross, it means the build or deployment failed, and you should check the log for more debugging information.
|
||||
- Click on the tick and make sure you see a "Deploy to GitHub Pages" workflow. Names like "pages build and deployment / deploy" are GitHub's default workflows, indicating your custom deployment workflow failed to be triggered at all. Make sure the YAML files are placed under the `.github/workflows` folder, and that the trigger condition is set correctly (e.g., if your default branch is "master" instead of "main", you need to change the `on.push` property).
|
||||
- Under your repo's Settings > Pages, make sure the "Source" (which is the source for the _deployment_ files, not "source" as in our terminology) is set to "gh-pages" + "/ (root)", since we are using `gh-pages` as the deployment branch.
|
||||
|
||||
If you are using a custom domain:
|
||||
|
||||
- Verify that you have the correct DNS records set up if you're using a custom domain. See [GitHub pages documentation on configuring custom domains](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/about-custom-domains-and-github-pages). Also, please be aware that it may take up to 24 hours for DNS changes to propagate through the internet.
|
||||
|
||||
</details>
|
||||
|
||||
### Triggering deployment with Travis CI {#triggering-deployment-with-travis-ci}
|
||||
|
||||
Continuous integration (CI) services are typically used to perform routine tasks whenever new commits are checked in to source control. These tasks can be any combination of running unit tests and integration tests, automating builds, publishing packages to npm, and deploying changes to your website. All you need to do to automate the deployment of your website is to invoke the `yarn deploy` script whenever your website is updated. The following section covers how to do just that using [Travis CI](https://travis-ci.com/), a popular continuous integration service provider.
|
||||
|
||||
1. Go to https://github.com/settings/tokens and generate a new [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/). When creating the token, grant it the `repo` scope so that it has the permissions it needs.
|
||||
2. Using your GitHub account, [add the Travis CI app](https://github.com/marketplace/travis-ci) to the repository you want to activate.
|
||||
3. Open your Travis CI dashboard. The URL looks like `https://travis-ci.com/USERNAME/REPO`, and navigate to the `More options > Setting > Environment Variables` section of your repository.
|
||||
4. Create a new environment variable named `GH_TOKEN` with your newly generated token as its value, then `GH_EMAIL` (your email address) and `GH_NAME` (your GitHub username).
|
||||
5. Create a `.travis.yml` on the root of your repository with the following:
|
||||
|
||||
```yml title=".travis.yml"
|
||||
language: node_js
|
||||
node_js:
|
||||
- 18
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
cache:
|
||||
yarn: true
|
||||
script:
|
||||
- git config --global user.name "${GH_NAME}"
|
||||
- git config --global user.email "${GH_EMAIL}"
|
||||
- echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
|
||||
- yarn install
|
||||
- GIT_USER="${GH_NAME}" yarn deploy
|
||||
```
|
||||
|
||||
Now, whenever a new commit lands in `main`, Travis CI will run your suite of tests and if everything passes, your website will be deployed via the `yarn deploy` script.
|
||||
|
||||
### Triggering deployment with Buddy {#triggering-deployment-with-buddy}
|
||||
|
||||
[Buddy](https://buddy.works/) is an easy-to-use CI/CD tool that allows you to automate the deployment of your portal to different environments, including GitHub Pages.
|
||||
|
||||
Follow these steps to create a pipeline that automatically deploys a new version of your website whenever you push changes to the selected branch of your project:
|
||||
|
||||
1. Go to https://github.com/settings/tokens and generate a new [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/). When creating the token, grant it the `repo` scope so that it has the permissions it needs.
|
||||
2. Sign in to your Buddy account and create a new project.
|
||||
3. Choose GitHub as your git hosting provider and select the repository with the code of your website.
|
||||
4. Using the left navigation panel, switch to the `Pipelines` view.
|
||||
5. Create a new pipeline. Define its name, set the trigger mode to `On push`, and select the branch that triggers the pipeline execution.
|
||||
6. Add a `Node.js` action.
|
||||
7. Add these commands in the action's terminal:
|
||||
|
||||
```bash
|
||||
GIT_USER=<GH_PERSONAL_ACCESS_TOKEN>
|
||||
git config --global user.email "<YOUR_GH_EMAIL>"
|
||||
git config --global user.name "<YOUR_GH_USERNAME>"
|
||||
yarn deploy
|
||||
```
|
||||
|
||||
After creating this simple pipeline, each new commit pushed to the branch you selected deploys your website to GitHub Pages using `yarn deploy`. Read [this guide](https://buddy.works/guides/react-docusaurus) to learn more about setting up a CI/CD pipeline for Docusaurus.
|
||||
|
||||
### Using Azure Pipelines {#using-azure-pipelines}
|
||||
|
||||
1. Sign Up at [Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) if you haven't already.
|
||||
2. Create an organization. Within the organization, create a project and connect your repository from GitHub.
|
||||
3. Go to https://github.com/settings/tokens and generate a new [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/) with the `repo` scope.
|
||||
4. In the project page (which looks like `https://dev.azure.com/ORG_NAME/REPO_NAME/_build`), create a new pipeline with the following text. Also, click on edit and add a new environment variable named `GH_TOKEN` with your newly generated token as its value, then `GH_EMAIL` (your email address) and `GH_NAME` (your GitHub username). Make sure to mark them as secret. Alternatively, you can also add a file named `azure-pipelines.yml` at your repository root.
|
||||
|
||||
```yml title="azure-pipelines.yml"
|
||||
trigger:
|
||||
- main
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- checkout: self
|
||||
persistCredentials: true
|
||||
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: '18'
|
||||
displayName: Install Node.js
|
||||
|
||||
- script: |
|
||||
git config --global user.name "${GH_NAME}"
|
||||
git config --global user.email "${GH_EMAIL}"
|
||||
git checkout -b main
|
||||
echo "machine github.com login ${GH_NAME} password ${GH_TOKEN}" > ~/.netrc
|
||||
yarn install
|
||||
GIT_USER="${GH_NAME}" yarn deploy
|
||||
env:
|
||||
GH_NAME: $(GH_NAME)
|
||||
GH_EMAIL: $(GH_EMAIL)
|
||||
GH_TOKEN: $(GH_TOKEN)
|
||||
displayName: Install and build
|
||||
```
|
||||
|
||||
### Using Drone {#using-drone}
|
||||
|
||||
1. Create a new SSH key that will be the [deploy key](https://docs.github.com/en/free-pro-team@latest/developers/overview/managing-deploy-keys#deploy-keys) for your project.
|
||||
2. Name your private and public keys to be specific and so that it does not overwrite your other [SSH keys](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).
|
||||
3. Go to `https://github.com/USERNAME/REPO/settings/keys` and add a new deploy key by pasting in the public key you just generated.
|
||||
4. Open your Drone.io dashboard and log in. The URL looks like `https://cloud.drone.io/USERNAME/REPO`.
|
||||
5. Click on the repository, click on activate repository, and add a secret called `git_deploy_private_key` with your private key value that you just generated.
|
||||
6. Create a `.drone.yml` on the root of your repository with the below text.
|
||||
|
||||
```yml title=".drone.yml"
|
||||
kind: pipeline
|
||||
type: docker
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
||||
- name: Website
|
||||
image: node
|
||||
commands:
|
||||
- mkdir -p $HOME/.ssh
|
||||
- ssh-keyscan -t rsa github.com >> $HOME/.ssh/known_hosts
|
||||
- echo "$GITHUB_PRIVATE_KEY" > "$HOME/.ssh/id_rsa"
|
||||
- chmod 0600 $HOME/.ssh/id_rsa
|
||||
- cd website
|
||||
- yarn install
|
||||
- yarn deploy
|
||||
environment:
|
||||
USE_SSH: true
|
||||
GITHUB_PRIVATE_KEY:
|
||||
from_secret: git_deploy_private_key
|
||||
```
|
||||
|
||||
Now, whenever you push a new tag to GitHub, this trigger will start the drone CI job to publish your website.
|
||||
|
||||
## Deploying to Flightcontrol {#deploying-to-flightcontrol}
|
||||
|
||||
[Flightcontrol](https://www.flightcontrol.dev/?ref=docusaurus) is a service that automatically builds and deploys your web apps to AWS Fargate directly from your Git repository. It gives you full access to inspect and make infrastructure changes without the limitations of a traditional PaaS.
|
||||
|
||||
Get started by following [Flightcontrol's step-by-step Docusaurus guide](https://www.flightcontrol.dev/docs/reference/examples/docusaurus/?ref=docusaurus).
|
||||
|
||||
## Deploying to Koyeb {#deploying-to-koyeb}
|
||||
|
||||
[Koyeb](https://www.koyeb.com) is a developer-friendly serverless platform to deploy apps globally. The platform lets you seamlessly run Docker containers, web apps, and APIs with git-based deployment, native autoscaling, a global edge network, and built-in service mesh and discovery. Check out the [Koyeb's Docusaurus deployment guide](https://www.koyeb.com/tutorials/deploy-docusaurus-on-koyeb) to get started.
|
||||
|
||||
## Deploying to Render {#deploying-to-render}
|
||||
|
||||
[Render](https://render.com) offers [free static site hosting](https://render.com/docs/static-sites) with fully managed SSL, custom domains, a global CDN, and continuous auto-deploy from your Git repo. Get started in just a few minutes by following [Render's guide to deploying Docusaurus](https://render.com/docs/deploy-docusaurus).
|
||||
|
||||
## Deploying to Qovery {#deploying-to-qovery}
|
||||
|
||||
[Qovery](https://www.qovery.com) is a fully-managed cloud platform that runs on your AWS, Digital Ocean, and Scaleway account where you can host static sites, backend APIs, databases, cron jobs, and all your other apps in one place.
|
||||
|
||||
1. Create a Qovery account. Visit the [Qovery dashboard](https://console.qovery.com) to create an account if you don't already have one.
|
||||
2. Create a project.
|
||||
- Click on **Create project** and give a name to your project.
|
||||
- Click on **Next**.
|
||||
3. Create a new environment.
|
||||
- Click on **Create environment** and give a name (e.g. staging, production).
|
||||
4. Add an application.
|
||||
- Click on **Create an application**, give a name and select your GitHub or GitLab repository where your Docusaurus app is located.
|
||||
- Define the main branch name and the root application path.
|
||||
- Click on **Create**. After the application is created:
|
||||
- Navigate to your application **Settings**
|
||||
- Select **Port**
|
||||
- Add port used by your Docusaurus application
|
||||
5. Deploy
|
||||
- All you have to do now is to navigate to your application and click on **Deploy**.
|
||||
|
||||

|
||||
|
||||
That's it. Watch the status and wait till the app is deployed. To open the application in your browser, click on **Action** and **Open** in your application overview.
|
||||
|
||||
## Deploying to Hostman {#deploying-to-hostman}
|
||||
|
||||
[Hostman](https://hostman.com/) allows you to host static websites for free. Hostman automates everything, you just need to connect your repository and follow these easy steps:
|
||||
|
||||
1. Create a service.
|
||||
|
||||
- To deploy a Docusaurus static website, click **Create** in the top-left corner of your [Dashboard](https://dashboard.hostman.com/) and choose **Front-end app or static website**.
|
||||
|
||||
2. Select the project to deploy.
|
||||
|
||||
- If you are logged in to Hostman with your GitHub, GitLab, or Bitbucket account, you will see the repository with your projects, including the private ones.
|
||||
|
||||
- Choose the project you want to deploy. It must contain the directory with the project's files (e.g. `website`).
|
||||
|
||||
- To access a different repository, click **Connect another repository**.
|
||||
|
||||
- If you didn't use your Git account credentials to log in, you'll be able to access the necessary account now, and then select the project.
|
||||
|
||||
3. Configure the build settings.
|
||||
|
||||
- Next, the **Website customization** window will appear. Choose the **Static website** option from the list of frameworks.
|
||||
|
||||
- The **Directory with app** points at the directory that will contain the project's files after the build. If you selected the repository with the contents of the website (or `my_website`) directory during Step 2, you can leave it empty.
|
||||
|
||||
- The standard build command for Docusaurus is:
|
||||
|
||||
```bash npm2yarn
|
||||
npm run build
|
||||
```
|
||||
|
||||
- You can modify the build command if needed. You can enter multiple commands separated by `&&`.
|
||||
|
||||
4. Deploy.
|
||||
|
||||
- Click **Deploy** to start the build process.
|
||||
|
||||
- Once it starts, you will enter the deployment log. If there are any issues with the code, you will get warning or error messages in the log specifying the cause of the problem. Usually, the log contains all the debugging data you'll need.
|
||||
|
||||
- When the deployment is complete, you will receive an email notification and also see a log entry. All done! Your project is up and ready.
|
||||
|
||||
## Deploying to Surge {#deploying-to-surge}
|
||||
|
||||
Surge is a [static web hosting platform](https://surge.sh/help/getting-started-with-surge) that you can use to deploy your Docusaurus project from the command line in seconds. Deploying your project to Surge is easy and free (including custom domains and SSL certs).
|
||||
|
||||
Deploy your app in a matter of seconds using Surge with the following steps:
|
||||
|
||||
1. First, install Surge using npm by running the following command:
|
||||
```bash npm2yarn
|
||||
npm install -g surge
|
||||
```
|
||||
2. To build the static files of your site for production in the root directory of your project, run:
|
||||
```bash npm2yarn
|
||||
npm run build
|
||||
```
|
||||
3. Then, run this command inside the root directory of your project:
|
||||
```bash
|
||||
surge build/
|
||||
```
|
||||
|
||||
First-time users of Surge would be prompted to create an account from the command line (which happens only once).
|
||||
|
||||
Confirm that the site you want to publish is in the `build` directory. A randomly generated subdomain `*.surge.sh subdomain` is always given (which can be edited).
|
||||
|
||||
### Using your domain {#using-your-domain}
|
||||
|
||||
If you have a domain name you can deploy your site using the command:
|
||||
|
||||
```bash
|
||||
surge build/ your-domain.com
|
||||
```
|
||||
|
||||
Your site is now deployed for free at `subdomain.surge.sh` or `your-domain.com` depending on the method you chose.
|
||||
|
||||
### Setting up CNAME file {#setting-up-cname-file}
|
||||
|
||||
Store your domain in a CNAME file for future deployments with the following command:
|
||||
|
||||
```bash
|
||||
echo subdomain.surge.sh > CNAME
|
||||
```
|
||||
|
||||
You can deploy any other changes in the future with the command `surge`.
|
||||
|
||||
## Deploying to Stormkit {#deploying-to-stormkit}
|
||||
|
||||
You can deploy your Docusaurus project to [Stormkit](https://www.stormkit.io), a deployment platform for static websites, single-page applications (SPAs), and serverless functions. For detailed instructions, refer to this [guide](https://www.stormkit.io/blog/how-to-deploy-docusarous).
|
||||
|
||||
## Deploying to QuantCDN {#deploying-to-quantcdn}
|
||||
|
||||
1. Install [Quant CLI](https://docs.quantcdn.io/docs/cli/get-started)
|
||||
2. Create a QuantCDN account by [signing up](https://dashboard.quantcdn.io/register)
|
||||
3. Initialize your project with `quant init` and fill in your credentials:
|
||||
```bash
|
||||
quant init
|
||||
```
|
||||
4. Deploy your site.
|
||||
```bash
|
||||
quant deploy
|
||||
```
|
||||
|
||||
See [docs](https://docs.quantcdn.io/docs/cli/continuous-integration) and [blog](https://www.quantcdn.io/blog) for more examples and use cases for deploying to QuantCDN.
|
||||
|
||||
## Deploying to Layer0 {#deploying-to-layer0}
|
||||
|
||||
[Layer0](https://www.layer0.co) is an all-in-one platform to develop, deploy, preview, experiment on, monitor, and run your headless frontend. It is focused on large, dynamic websites and best-in-class performance through EdgeJS (a JavaScript-based Content Delivery Network), predictive prefetching, and performance monitoring. Layer0 offers a free tier. Get started in just a few minutes by following [Layer0's guide to deploying Docusaurus](https://docs.layer0.co/guides/docusaurus).
|
||||
|
||||
## Deploying to Cloudflare Pages {#deploying-to-cloudflare-pages}
|
||||
|
||||
[Cloudflare Pages](https://pages.cloudflare.com/) is a Jamstack platform for frontend developers to collaborate and deploy websites. Get started within a few minutes by following [this article](https://dev.to/apidev234/deploying-docusaurus-to-cloudflare-pages-565g).
|
||||
|
||||
## Deploying to Azure Static Web Apps {#deploying-to-azure-static-web-apps}
|
||||
|
||||
[Azure Static Web Apps](https://docs.microsoft.com/en-us/azure/static-web-apps/overview) is a service that automatically builds and deploys full-stack web apps to Azure directly from the code repository, simplifying the developer experience for CI/CD. Static Web Apps separates the web application's static assets from its dynamic (API) endpoints. Static assets are served from globally-distributed content servers, making it faster for clients to retrieve files using servers nearby. Dynamic APIs are scaled with serverless architectures using an event-driven functions-based approach that is more cost-effective and scales on demand. Get started in a few minutes by following [this step-by-step guide](https://dev.to/azure/11-share-content-with-docusaurus-azure-static-web-apps-30hc).
|
||||
|
||||
## Deploying to Kinsta {#deploying-to-kinsta}
|
||||
|
||||
[Kinsta Static Site Hosting](https://kinsta.com/static-site-hosting) lets you deploy up to 100 static sites for free, custom domains with SSL, 100 GB monthly bandwidth, and 260+ Cloudflare CDN locations.
|
||||
|
||||
Get started in just a few clicks by following our [Docusaurus on Kinsta](https://kinsta.com/docs/docusaurus-example/) article.
|
770
website/versioned_docs/version-3.3.2/docusaurus-core.mdx
Normal file
770
website/versioned_docs/version-3.3.2/docusaurus-core.mdx
Normal file
|
@ -0,0 +1,770 @@
|
|||
---
|
||||
sidebar_label: Client API
|
||||
---
|
||||
|
||||
# Docusaurus Client API
|
||||
|
||||
Docusaurus provides some APIs on the clients that can be helpful to you when building your site.
|
||||
|
||||
## Components {#components}
|
||||
|
||||
### `<ErrorBoundary />` {#errorboundary}
|
||||
|
||||
This component creates a [React error boundary](https://reactjs.org/docs/error-boundaries.html).
|
||||
|
||||
Use it to wrap components that might throw, and display a fallback when that happens instead of crashing the whole app.
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
||||
|
||||
const SafeComponent = () => (
|
||||
<ErrorBoundary
|
||||
fallback={({error, tryAgain}) => (
|
||||
<div>
|
||||
<p>This component crashed because of error: {error.message}.</p>
|
||||
<button onClick={tryAgain}>Try Again!</button>
|
||||
</div>
|
||||
)}>
|
||||
<SomeDangerousComponentThatMayThrow />
|
||||
</ErrorBoundary>
|
||||
);
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
import ErrorBoundaryTestButton from '@site/src/components/ErrorBoundaryTestButton'
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
To see it in action, click here: <ErrorBoundaryTestButton/>
|
||||
|
||||
:::
|
||||
|
||||
:::info
|
||||
|
||||
Docusaurus uses this component to catch errors within the theme's layout, and also within the entire app.
|
||||
|
||||
:::
|
||||
|
||||
:::note
|
||||
|
||||
This component doesn't catch build-time errors and only protects against client-side render errors that can happen when using stateful React components.
|
||||
|
||||
:::
|
||||
|
||||
#### Props {#errorboundary-props}
|
||||
|
||||
- `fallback`: an optional render callback returning a JSX element. It will receive an object with 2 attributes: `error`, the error that was caught, and `tryAgain`, a function (`() => void`) callback to reset the error in the component and try rendering it again. If not present, `@theme/Error` will be rendered instead. `@theme/Error` is used for the error boundaries wrapping the site, above the layout.
|
||||
|
||||
:::warning
|
||||
|
||||
The `fallback` prop is a callback, and **not a React functional component**. You can't use React hooks inside this callback.
|
||||
|
||||
:::
|
||||
|
||||
### `<Head/>` {#head}
|
||||
|
||||
This reusable React component will manage all of your changes to the document head. It takes plain HTML tags and outputs plain HTML tags and is beginner-friendly. It is a wrapper around [React Helmet](https://github.com/nfl/react-helmet).
|
||||
|
||||
Usage Example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import Head from '@docusaurus/Head';
|
||||
|
||||
const MySEO = () => (
|
||||
// highlight-start
|
||||
<Head>
|
||||
<meta property="og:description" content="My custom description" />
|
||||
<meta charSet="utf-8" />
|
||||
<title>My Title</title>
|
||||
<link rel="canonical" href="http://mysite.com/example" />
|
||||
</Head>
|
||||
// highlight-end
|
||||
);
|
||||
```
|
||||
|
||||
Nested or latter components will override duplicate usages:
|
||||
|
||||
```jsx
|
||||
<Parent>
|
||||
{/* highlight-start */}
|
||||
<Head>
|
||||
<title>My Title</title>
|
||||
<meta name="description" content="Helmet application" />
|
||||
</Head>
|
||||
{/* highlight-end */}
|
||||
<Child>
|
||||
{/* highlight-start */}
|
||||
<Head>
|
||||
<title>Nested Title</title>
|
||||
<meta name="description" content="Nested component" />
|
||||
</Head>
|
||||
{/* highlight-end */}
|
||||
</Child>
|
||||
</Parent>
|
||||
```
|
||||
|
||||
Outputs:
|
||||
|
||||
```html
|
||||
<head>
|
||||
<title>Nested Title</title>
|
||||
<meta name="description" content="Nested component" />
|
||||
</head>
|
||||
```
|
||||
|
||||
### `<Link/>` {#link}
|
||||
|
||||
This component enables linking to internal pages as well as a powerful performance feature called preloading. Preloading is used to prefetch resources so that the resources are fetched by the time the user navigates with this component. We use an `IntersectionObserver` to fetch a low-priority request when the `<Link>` is in the viewport and then use an `onMouseOver` event to trigger a high-priority request when it is likely that a user will navigate to the requested resource.
|
||||
|
||||
The component is a wrapper around react-router’s `<Link>` component that adds useful enhancements specific to Docusaurus. All props are passed through to react-router’s `<Link>` component.
|
||||
|
||||
External links also work, and automatically have these props: `target="_blank" rel="noopener noreferrer"`.
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import Link from '@docusaurus/Link';
|
||||
|
||||
const Page = () => (
|
||||
<div>
|
||||
<p>
|
||||
{/* highlight-next-line */}
|
||||
Check out my <Link to="/blog">blog</Link>!
|
||||
</p>
|
||||
<p>
|
||||
{/* highlight-next-line */}
|
||||
Follow me on <Link to="https://twitter.com/docusaurus">Twitter</Link>!
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
```
|
||||
|
||||
#### `to`: string {#to-string}
|
||||
|
||||
The target location to navigate to. Example: `/docs/introduction`.
|
||||
|
||||
```jsx
|
||||
<Link to="/courses" />
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
Prefer this component to vanilla `<a>` tags because Docusaurus does a lot of optimizations (e.g. broken path detection, prefetching, applying base URL...) if you use `<Link>`.
|
||||
|
||||
:::
|
||||
|
||||
### `<Redirect/>` {#redirect}
|
||||
|
||||
Rendering a `<Redirect>` will navigate to a new location. The new location will override the current location in the history stack like server-side redirects (HTTP 3xx) do. You can refer to [React Router's Redirect documentation](https://reacttraining.com/react-router/web/api/Redirect) for more info on available props.
|
||||
|
||||
Example usage:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import {Redirect} from '@docusaurus/router';
|
||||
|
||||
const Home = () => {
|
||||
// highlight-next-line
|
||||
return <Redirect to="/docs/test" />;
|
||||
};
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
`@docusaurus/router` implements [React Router](https://reacttraining.com/react-router/web/guides/quick-start) and supports its features.
|
||||
|
||||
:::
|
||||
|
||||
### `<BrowserOnly/>` {#browseronly}
|
||||
|
||||
The `<BrowserOnly>` component permits to render React components only in the browser after the React app has hydrated.
|
||||
|
||||
:::tip
|
||||
|
||||
Use it for integrating with code that can't run in Node.js, because the `window` or `document` objects are being accessed.
|
||||
|
||||
:::
|
||||
|
||||
#### Props {#browseronly-props}
|
||||
|
||||
- `children`: render function prop returning browser-only JSX. Will not be executed in Node.js
|
||||
- `fallback` (optional): JSX to render on the server (Node.js) and until React hydration completes.
|
||||
|
||||
#### Example with code {#browseronly-example-code}
|
||||
|
||||
```jsx
|
||||
// highlight-start
|
||||
import BrowserOnly from '@docusaurus/BrowserOnly';
|
||||
// highlight-end
|
||||
|
||||
const MyComponent = () => {
|
||||
return (
|
||||
// highlight-start
|
||||
<BrowserOnly>
|
||||
{() => <span>page url = {window.location.href}</span>}
|
||||
</BrowserOnly>
|
||||
// highlight-end
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
#### Example with a library {#browseronly-example-library}
|
||||
|
||||
```jsx
|
||||
// highlight-start
|
||||
import BrowserOnly from '@docusaurus/BrowserOnly';
|
||||
// highlight-end
|
||||
|
||||
const MyComponent = (props) => {
|
||||
return (
|
||||
// highlight-start
|
||||
<BrowserOnly fallback={<div>Loading...</div>}>
|
||||
{() => {
|
||||
const LibComponent = require('some-lib').LibComponent;
|
||||
return <LibComponent {...props} />;
|
||||
}}
|
||||
</BrowserOnly>
|
||||
// highlight-end
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
### `<Interpolate/>` {#interpolate}
|
||||
|
||||
A simple interpolation component for text containing dynamic placeholders.
|
||||
|
||||
The placeholders will be replaced with the provided dynamic values and JSX elements of your choice (strings, links, styled elements...).
|
||||
|
||||
#### Props {#interpolate-props}
|
||||
|
||||
- `children`: text containing interpolation placeholders like `{placeholderName}`
|
||||
- `values`: object containing interpolation placeholder values
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import Link from '@docusaurus/Link';
|
||||
import Interpolate from '@docusaurus/Interpolate';
|
||||
|
||||
export default function VisitMyWebsiteMessage() {
|
||||
return (
|
||||
// highlight-start
|
||||
<Interpolate
|
||||
values={{
|
||||
firstName: 'Sébastien',
|
||||
website: (
|
||||
<Link to="https://docusaurus.io" className="my-website-class">
|
||||
website
|
||||
</Link>
|
||||
),
|
||||
}}>
|
||||
{'Hello, {firstName}! How are you? Take a look at my {website}'}
|
||||
</Interpolate>
|
||||
// highlight-end
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### `<Translate/>` {#translate}
|
||||
|
||||
When [localizing your site](./i18n/i18n-introduction.mdx), the `<Translate/>` component will allow providing **translation support to React components**, such as your homepage. The `<Translate>` component supports [interpolation](#interpolate).
|
||||
|
||||
The translation strings will statically extracted from your code with the [`docusaurus write-translations`](./cli.mdx#docusaurus-write-translations-sitedir) CLI and a `code.json` translation file will be created in `website/i18n/[locale]`.
|
||||
|
||||
:::note
|
||||
|
||||
The `<Translate/>` props **must be hardcoded strings**.
|
||||
|
||||
Apart from the `values` prop used for interpolation, it is **not possible to use variables**, or the static extraction wouldn't work.
|
||||
|
||||
:::
|
||||
|
||||
#### Props {#translate-props}
|
||||
|
||||
- `children`: untranslated string in the default site locale (can contain [interpolation placeholders](#interpolate))
|
||||
- `id`: optional value to be used as the key in JSON translation files
|
||||
- `description`: optional text to help the translator
|
||||
- `values`: optional object containing interpolation placeholder values
|
||||
|
||||
#### Example {#example}
|
||||
|
||||
```jsx title="src/pages/index.js"
|
||||
import React from 'react';
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
// highlight-start
|
||||
import Translate from '@docusaurus/Translate';
|
||||
// highlight-end
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<Layout>
|
||||
<h1>
|
||||
{/* highlight-start */}
|
||||
<Translate
|
||||
id="homepage.title"
|
||||
description="The homepage welcome message">
|
||||
Welcome to my website
|
||||
</Translate>
|
||||
{/* highlight-end */}
|
||||
</h1>
|
||||
<main>
|
||||
{/* highlight-start */}
|
||||
<Translate values={{firstName: 'Sébastien'}}>
|
||||
{'Welcome, {firstName}! How are you?'}
|
||||
</Translate>
|
||||
{/* highlight-end */}
|
||||
</main>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
You can even omit the children prop and specify a translation string in your `code.json` file manually after running the `docusaurus write-translations` CLI command.
|
||||
|
||||
```jsx
|
||||
<Translate id="homepage.title" />
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
:::info
|
||||
|
||||
The `<Translate>` component supports interpolation. You can also implement [string pluralization](https://github.com/facebook/docusaurus/pull/i18n/i18n-tutorial.mdx#pluralization) through some custom code and the [`translate` imperative API](#translate-imperative).
|
||||
|
||||
:::
|
||||
|
||||
## Hooks {#hooks}
|
||||
|
||||
### `useDocusaurusContext` {#useDocusaurusContext}
|
||||
|
||||
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.mdx) and some additional site metadata.
|
||||
|
||||
```ts
|
||||
type PluginVersionInformation =
|
||||
| {readonly type: 'package'; readonly version?: string}
|
||||
| {readonly type: 'project'}
|
||||
| {readonly type: 'local'}
|
||||
| {readonly type: 'synthetic'};
|
||||
|
||||
type SiteMetadata = {
|
||||
readonly docusaurusVersion: string;
|
||||
readonly siteVersion?: string;
|
||||
readonly pluginVersions: Record<string, PluginVersionInformation>;
|
||||
};
|
||||
|
||||
type I18nLocaleConfig = {
|
||||
label: string;
|
||||
direction: string;
|
||||
};
|
||||
|
||||
type I18n = {
|
||||
defaultLocale: string;
|
||||
locales: [string, ...string[]];
|
||||
currentLocale: string;
|
||||
localeConfigs: Record<string, I18nLocaleConfig>;
|
||||
};
|
||||
|
||||
type DocusaurusContext = {
|
||||
siteConfig: DocusaurusConfig;
|
||||
siteMetadata: SiteMetadata;
|
||||
globalData: Record<string, unknown>;
|
||||
i18n: I18n;
|
||||
codeTranslations: Record<string, string>;
|
||||
};
|
||||
```
|
||||
|
||||
Usage example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
const MyComponent = () => {
|
||||
// highlight-next-line
|
||||
const {siteConfig, siteMetadata} = useDocusaurusContext();
|
||||
return (
|
||||
<div>
|
||||
{/* highlight-start */}
|
||||
<h1>{siteConfig.title}</h1>
|
||||
<div>{siteMetadata.siteVersion}</div>
|
||||
<div>{siteMetadata.docusaurusVersion}</div>
|
||||
{/* highlight-end */}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
The `siteConfig` object only contains **serializable values** (values that are preserved after `JSON.stringify()`). Functions, regexes, etc. would be lost on the client side.
|
||||
|
||||
:::
|
||||
|
||||
### `useIsBrowser` {#useIsBrowser}
|
||||
|
||||
Returns `true` when the React app has successfully hydrated in the browser.
|
||||
|
||||
:::warning
|
||||
|
||||
Use this hook instead of `typeof windows !== 'undefined'` in React rendering logic.
|
||||
|
||||
The first client-side render output (in the browser) **must be exactly the same** as the server-side render output (Node.js). Not following this rule can lead to unexpected hydration behaviors, as described in [The Perils of Rehydration](https://www.joshwcomeau.com/react/the-perils-of-rehydration/).
|
||||
|
||||
:::
|
||||
|
||||
Usage example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
|
||||
const MyComponent = () => {
|
||||
// highlight-start
|
||||
const isBrowser = useIsBrowser();
|
||||
// highlight-end
|
||||
return <div>{isBrowser ? 'Client' : 'Server'}</div>;
|
||||
};
|
||||
```
|
||||
|
||||
### `useBaseUrl` {#useBaseUrl}
|
||||
|
||||
React hook to prepend your site `baseUrl` to a string.
|
||||
|
||||
:::warning
|
||||
|
||||
**Don't use it for regular links!**
|
||||
|
||||
The `/baseUrl/` prefix is automatically added to all **absolute paths** by default:
|
||||
|
||||
- Markdown: `[link](/my/path)` will link to `/baseUrl/my/path`
|
||||
- React: `<Link to="/my/path/">link</Link>` will link to `/baseUrl/my/path`
|
||||
|
||||
:::
|
||||
|
||||
#### Options {#options}
|
||||
|
||||
```ts
|
||||
type BaseUrlOptions = {
|
||||
forcePrependBaseUrl: boolean;
|
||||
absolute: boolean;
|
||||
};
|
||||
```
|
||||
|
||||
#### Example usage: {#example-usage}
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||
|
||||
const SomeImage = () => {
|
||||
// highlight-start
|
||||
const imgSrc = useBaseUrl('/img/myImage.png');
|
||||
// highlight-end
|
||||
return <img src={imgSrc} />;
|
||||
};
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
In most cases, you don't need `useBaseUrl`.
|
||||
|
||||
Prefer a `require()` call for [assets](./guides/markdown-features/markdown-features-assets.mdx):
|
||||
|
||||
```jsx
|
||||
<img src={require('@site/static/img/myImage.png').default} />
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
### `useBaseUrlUtils` {#useBaseUrlUtils}
|
||||
|
||||
Sometimes `useBaseUrl` is not good enough. This hook return additional utils related to your site's base URL.
|
||||
|
||||
- `withBaseUrl`: useful if you need to add base URLs to multiple URLs at once.
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
|
||||
|
||||
const Component = () => {
|
||||
const urls = ['/a', '/b'];
|
||||
// highlight-start
|
||||
const {withBaseUrl} = useBaseUrlUtils();
|
||||
const urlsWithBaseUrl = urls.map(withBaseUrl);
|
||||
// highlight-end
|
||||
return <div>{/* ... */}</div>;
|
||||
};
|
||||
```
|
||||
|
||||
### `useGlobalData` {#useGlobalData}
|
||||
|
||||
React hook to access Docusaurus global data created by all the plugins.
|
||||
|
||||
Global data is namespaced by plugin name then by plugin ID.
|
||||
|
||||
:::info
|
||||
|
||||
Plugin ID is only useful when a plugin is used multiple times on the same site. Each plugin instance is able to create its own global data.
|
||||
|
||||
:::
|
||||
|
||||
```ts
|
||||
type GlobalData = Record<
|
||||
PluginName,
|
||||
Record<
|
||||
PluginId, // "default" by default
|
||||
any // plugin-specific data
|
||||
>
|
||||
>;
|
||||
```
|
||||
|
||||
Usage example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import useGlobalData from '@docusaurus/useGlobalData';
|
||||
|
||||
const MyComponent = () => {
|
||||
// highlight-start
|
||||
const globalData = useGlobalData();
|
||||
const myPluginData = globalData['my-plugin']['default'];
|
||||
return <div>{myPluginData.someAttribute}</div>;
|
||||
// highlight-end
|
||||
};
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
Inspect your site's global data at `.docusaurus/globalData.json`
|
||||
|
||||
:::
|
||||
|
||||
### `usePluginData` {#usePluginData}
|
||||
|
||||
Access global data created by a specific plugin instance.
|
||||
|
||||
This is the most convenient hook to access plugin global data and should be used most of the time.
|
||||
|
||||
`pluginId` is optional if you don't use multi-instance plugins.
|
||||
|
||||
```ts
|
||||
function usePluginData(
|
||||
pluginName: string,
|
||||
pluginId?: string,
|
||||
options?: {failfast?: boolean},
|
||||
);
|
||||
```
|
||||
|
||||
Usage example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import {usePluginData} from '@docusaurus/useGlobalData';
|
||||
|
||||
const MyComponent = () => {
|
||||
// highlight-start
|
||||
const myPluginData = usePluginData('my-plugin');
|
||||
return <div>{myPluginData.someAttribute}</div>;
|
||||
// highlight-end
|
||||
};
|
||||
```
|
||||
|
||||
### `useAllPluginInstancesData` {#useAllPluginInstancesData}
|
||||
|
||||
Access global data created by a specific plugin. Given a plugin name, it returns the data of all the plugins instances of that name, by plugin id.
|
||||
|
||||
```ts
|
||||
function useAllPluginInstancesData(
|
||||
pluginName: string,
|
||||
options?: {failfast?: boolean},
|
||||
);
|
||||
```
|
||||
|
||||
Usage example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import {useAllPluginInstancesData} from '@docusaurus/useGlobalData';
|
||||
|
||||
const MyComponent = () => {
|
||||
// highlight-start
|
||||
const allPluginInstancesData = useAllPluginInstancesData('my-plugin');
|
||||
const myPluginData = allPluginInstancesData['default'];
|
||||
return <div>{myPluginData.someAttribute}</div>;
|
||||
// highlight-end
|
||||
};
|
||||
```
|
||||
|
||||
### `useBrokenLinks` {#useBrokenLinks}
|
||||
|
||||
React hook to access the Docusaurus broken link checker APIs, exposing a way for a Docusaurus pages to report and collect their links and anchors.
|
||||
|
||||
:::warning
|
||||
|
||||
This is an **advanced** API that **most Docusaurus users don't need to use directly**.
|
||||
|
||||
It is already **built-in** in existing high-level components:
|
||||
|
||||
- the [`<Link>`](#link) component will collect links for you
|
||||
- the `@theme/Heading` (used for Markdown headings) will collect anchors
|
||||
|
||||
Use `useBrokenLinks()` if you implement your own `<Heading>` or `<Link>` component.
|
||||
|
||||
:::
|
||||
|
||||
Usage example:
|
||||
|
||||
```js title="MyHeading.js"
|
||||
import useBrokenLinks from '@docusaurus/useBrokenLinks';
|
||||
|
||||
export default function MyHeading(props) {
|
||||
useBrokenLinks().collectAnchor(props.id);
|
||||
return <h2 {...props} />;
|
||||
}
|
||||
```
|
||||
|
||||
```js title="MyLink.js"
|
||||
import useBrokenLinks from '@docusaurus/useBrokenLinks';
|
||||
|
||||
export default function MyLink(props) {
|
||||
useBrokenLinks().collectLink(props.href);
|
||||
return <a {...props} />;
|
||||
}
|
||||
```
|
||||
|
||||
## Functions {#functions}
|
||||
|
||||
### `interpolate` {#interpolate-1}
|
||||
|
||||
The imperative counterpart of the [`<Interpolate>`](#interpolate) component.
|
||||
|
||||
#### Signature {#signature}
|
||||
|
||||
```ts
|
||||
// Simple string interpolation
|
||||
function interpolate(text: string, values: Record<string, string>): string;
|
||||
|
||||
// JSX interpolation
|
||||
function interpolate(
|
||||
text: string,
|
||||
values: Record<string, ReactNode>,
|
||||
): ReactNode;
|
||||
```
|
||||
|
||||
#### Example {#example-1}
|
||||
|
||||
```js
|
||||
// highlight-next-line
|
||||
import {interpolate} from '@docusaurus/Interpolate';
|
||||
|
||||
const message = interpolate('Welcome {firstName}', {firstName: 'Sébastien'});
|
||||
```
|
||||
|
||||
### `translate` {#translate-imperative}
|
||||
|
||||
The imperative counterpart of the [`<Translate>`](#translate) component. Also supporting [placeholders interpolation](#interpolate).
|
||||
|
||||
:::tip
|
||||
|
||||
Use the imperative API for the **rare cases** where a **component cannot be used**, such as:
|
||||
|
||||
- the page `title` metadata
|
||||
- the `placeholder` props of form inputs
|
||||
- the `aria-label` props for accessibility
|
||||
|
||||
:::
|
||||
|
||||
#### Signature {#signature-1}
|
||||
|
||||
```ts
|
||||
function translate(
|
||||
translation: {message: string; id?: string; description?: string},
|
||||
values: Record<string, string>,
|
||||
): string;
|
||||
```
|
||||
|
||||
#### Example {#example-2}
|
||||
|
||||
```jsx title="src/pages/index.js"
|
||||
import React from 'react';
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
// highlight-next-line
|
||||
import {translate} from '@docusaurus/Translate';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<Layout
|
||||
// highlight-next-line
|
||||
title={translate({message: 'My page meta title'})}>
|
||||
<img
|
||||
src={'https://docusaurus.io/logo.png'}
|
||||
aria-label={
|
||||
// highlight-start
|
||||
translate(
|
||||
{
|
||||
message: 'The logo of site {siteName}',
|
||||
// Optional
|
||||
id: 'homepage.logo.ariaLabel',
|
||||
description: 'The home page logo aria label',
|
||||
},
|
||||
{siteName: 'Docusaurus'},
|
||||
)
|
||||
// highlight-end
|
||||
}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Modules {#modules}
|
||||
|
||||
### `ExecutionEnvironment` {#executionenvironment}
|
||||
|
||||
A module that exposes a few boolean variables to check the current rendering environment.
|
||||
|
||||
:::warning
|
||||
|
||||
For React rendering logic, use [`useIsBrowser()`](#useIsBrowser) or [`<BrowserOnly>`](#browseronly) instead.
|
||||
|
||||
:::
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
require('lib-that-only-works-client-side');
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Description |
|
||||
| --- | --- |
|
||||
| `ExecutionEnvironment.canUseDOM` | `true` if on client/browser, `false` on Node.js/prerendering. |
|
||||
| `ExecutionEnvironment.canUseEventListeners` | `true` if on client and has `window.addEventListener`. |
|
||||
| `ExecutionEnvironment.canUseIntersectionObserver` | `true` if on client and has `IntersectionObserver`. |
|
||||
| `ExecutionEnvironment.canUseViewport` | `true` if on client and has `window.screen`. |
|
||||
|
||||
### `constants` {#constants}
|
||||
|
||||
A module exposing useful constants to client-side theme code.
|
||||
|
||||
```js
|
||||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/constants';
|
||||
```
|
||||
|
||||
| Named export | Value |
|
||||
| ------------------- | --------- |
|
||||
| `DEFAULT_PLUGIN_ID` | `default` |
|
140
website/versioned_docs/version-3.3.2/guides/creating-pages.mdx
Normal file
140
website/versioned_docs/version-3.3.2/guides/creating-pages.mdx
Normal file
|
@ -0,0 +1,140 @@
|
|||
---
|
||||
slug: /creating-pages
|
||||
sidebar_label: Pages
|
||||
---
|
||||
|
||||
# Creating Pages
|
||||
|
||||
In this section, we will learn about creating pages in Docusaurus.
|
||||
|
||||
The `@docusaurus/plugin-content-pages` plugin empowers you to create **one-off standalone pages** like a showcase page, playground page, or support page. You can use React components, or Markdown.
|
||||
|
||||
:::note
|
||||
|
||||
Pages do not have sidebars, only [docs](./docs/docs-introduction.mdx) do.
|
||||
|
||||
:::
|
||||
|
||||
:::info
|
||||
|
||||
Check the [Pages Plugin API Reference documentation](./../api/plugins/plugin-content-pages.mdx) for an exhaustive list of options.
|
||||
|
||||
:::
|
||||
|
||||
## Add a React page {#add-a-react-page}
|
||||
|
||||
React is used as the UI library to create pages. Every page component should export a React component, and you can leverage the expressiveness of React to build rich and interactive content.
|
||||
|
||||
Create a file `/src/pages/helloReact.js`:
|
||||
|
||||
```jsx title="/src/pages/helloReact.js"
|
||||
import React from 'react';
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
export default function Hello() {
|
||||
return (
|
||||
<Layout title="Hello" description="Hello React Page">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '50vh',
|
||||
fontSize: '20px',
|
||||
}}>
|
||||
<p>
|
||||
Edit <code>pages/helloReact.js</code> and save to reload.
|
||||
</p>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Once you save the file, the development server will automatically reload the changes. Now open [`http://localhost:3000/helloReact`](http://localhost:3000/helloReact) and you will see the new page you just created.
|
||||
|
||||
Each page doesn't come with any styling. You will need to import the `Layout` component from `@theme/Layout` and wrap your contents within that component if you want the navbar and/or footer to appear.
|
||||
|
||||
:::tip
|
||||
|
||||
You can also create TypeScript pages with the `.tsx` extension (`helloReact.tsx`).
|
||||
|
||||
:::
|
||||
|
||||
## Add a Markdown page {#add-a-markdown-page}
|
||||
|
||||
Create a file `/src/pages/helloMarkdown.md`:
|
||||
|
||||
```md title="/src/pages/helloMarkdown.md"
|
||||
---
|
||||
title: my hello page title
|
||||
description: my hello page description
|
||||
hide_table_of_contents: true
|
||||
---
|
||||
|
||||
# Hello
|
||||
|
||||
How are you?
|
||||
```
|
||||
|
||||
In the same way, a page will be created at [`http://localhost:3000/helloMarkdown`](http://localhost:3000/helloMarkdown).
|
||||
|
||||
Markdown pages are less flexible than React pages because it always uses the theme layout.
|
||||
|
||||
Here's an [example Markdown page](/examples/markdownPageExample).
|
||||
|
||||
:::tip
|
||||
|
||||
You can use the full power of React in Markdown pages too, refer to the [MDX](https://mdxjs.com/) documentation.
|
||||
|
||||
:::
|
||||
|
||||
## Routing {#routing}
|
||||
|
||||
If you are familiar with other static site generators like Jekyll and Next, this routing approach will feel familiar to you. Any JavaScript file you create under `/src/pages/` directory will be automatically converted to a website page, following the `/src/pages/` directory hierarchy. For example:
|
||||
|
||||
- `/src/pages/index.js` → `[baseUrl]`
|
||||
- `/src/pages/foo.js` → `[baseUrl]/foo`
|
||||
- `/src/pages/foo/test.js` → `[baseUrl]/foo/test`
|
||||
- `/src/pages/foo/index.js` → `[baseUrl]/foo/`
|
||||
|
||||
In this component-based development era, it is encouraged to co-locate your styling, markup, and behavior together into components. Each page is a component, and if you need to customize your page design with your own styles, we recommend co-locating your styles with the page component in its own directory. For example, to create a "Support" page, you could do one of the following:
|
||||
|
||||
- Add a `/src/pages/support.js` file
|
||||
- Create a `/src/pages/support/` directory and a `/src/pages/support/index.js` file.
|
||||
|
||||
The latter is preferred as it has the benefits of letting you put files related to the page within that directory. For example, a CSS module file (`styles.module.css`) with styles meant to only be used on the "Support" page.
|
||||
|
||||
:::note
|
||||
|
||||
This is merely a recommended directory structure, and you will still need to manually import the CSS module file within your component module (`support/index.js`).
|
||||
|
||||
:::
|
||||
|
||||
By default, any Markdown or JavaScript file starting with `_` will be ignored and no routes will be created for that file (see the `exclude` option).
|
||||
|
||||
```bash
|
||||
my-website
|
||||
├── src
|
||||
│ └── pages
|
||||
│ ├── styles.module.css
|
||||
│ ├── index.js
|
||||
│ ├── _ignored.js
|
||||
│ ├── _ignored-folder
|
||||
│ │ ├── Component1.js
|
||||
│ │ └── Component2.js
|
||||
│ └── support
|
||||
│ ├── index.js
|
||||
│ └── styles.module.css
|
||||
.
|
||||
```
|
||||
|
||||
:::warning
|
||||
|
||||
All JavaScript/TypeScript files within the `src/pages/` directory will have corresponding website paths generated for them. If you want to create reusable components into that directory, use the `exclude` option (by default, files prefixed with `_`, test files(`.test.js`), and files in `__tests__` directory are not turned into pages).
|
||||
|
||||
:::
|
||||
|
||||
### Duplicate Routes {#duplicate-routes}
|
||||
|
||||
You may accidentally create multiple pages that are meant to be accessed on the same route. When this happens, Docusaurus will warn you about duplicate routes when you run `yarn start` or `yarn build` (behavior configurable through the [`onDuplicateRoutes`](../api/docusaurus.config.js.mdx#onDuplicateRoutes) config), but the site will still be built successfully. The page that was created last will be accessible, but it will override other conflicting pages. To resolve this issue, you should modify or remove any conflicting routes.
|
|
@ -0,0 +1,176 @@
|
|||
---
|
||||
id: create-doc
|
||||
description: Create a Markdown Document
|
||||
slug: /create-doc
|
||||
---
|
||||
|
||||
# Create a doc
|
||||
|
||||
Create a Markdown file, `greeting.md`, and place it under the `docs` directory.
|
||||
|
||||
```bash
|
||||
website # root directory of your site
|
||||
├── docs
|
||||
│ └── greeting.md
|
||||
├── src
|
||||
│ └── pages
|
||||
├── docusaurus.config.js
|
||||
├── ...
|
||||
```
|
||||
|
||||
```md
|
||||
---
|
||||
description: Create a doc page with rich content.
|
||||
---
|
||||
|
||||
# Hello from Docusaurus
|
||||
|
||||
Are you ready to create the documentation site for your open source project?
|
||||
|
||||
## Headers
|
||||
|
||||
will show up on the table of contents on the upper right
|
||||
|
||||
So that your users will know what this page is all about without scrolling down or even without reading too much.
|
||||
|
||||
## Only h2 and h3 will be in the TOC by default.
|
||||
|
||||
You can configure the TOC heading levels either per-document or in the theme configuration.
|
||||
|
||||
The headers are well-spaced so that the hierarchy is clear.
|
||||
|
||||
- lists will help you
|
||||
- present the key points
|
||||
- that you want your users to remember
|
||||
- and you may nest them
|
||||
- multiple times
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
All files prefixed with an underscore (`_`) under the `docs` directory are treated as "partial" pages and will be ignored by default.
|
||||
|
||||
Read more about [importing partial pages](../markdown-features/markdown-features-react.mdx#importing-markdown).
|
||||
|
||||
:::
|
||||
|
||||
## Doc front matter {#doc-front-matter}
|
||||
|
||||
The [front matter](../markdown-features/markdown-features-intro.mdx#front-matter) is used to provide additional metadata for your doc page. Front matter is optional—Docusaurus will be able to infer all necessary metadata without the front matter. For example, the [doc tags](#doc-tags) feature introduced below requires using front matter. For all possible fields, see [the API documentation](../../api/plugins/plugin-content-docs.mdx#markdown-front-matter).
|
||||
|
||||
## Doc tags {#doc-tags}
|
||||
|
||||
Optionally, you can add tags to your doc pages, which introduces another dimension of categorization in addition to the [docs sidebar](./sidebar/index.mdx). Tags are passed in the front matter as a list of labels:
|
||||
|
||||
```md "your-doc-page.md"
|
||||
---
|
||||
id: doc-with-tags
|
||||
title: A doc with tags
|
||||
tags:
|
||||
- Demo
|
||||
- Getting started
|
||||
---
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
Tags can also be declared with `tags: [Demo, Getting started]`.
|
||||
|
||||
Read more about all the possible [Yaml array syntaxes](https://www.w3schools.io/file/yaml-arrays/).
|
||||
|
||||
:::
|
||||
|
||||
## Organizing folder structure {#organizing-folder-structure}
|
||||
|
||||
How the Markdown files are arranged under the `docs` folder can have multiple impacts on Docusaurus content generation. However, most of them can be decoupled from the file structure.
|
||||
|
||||
### Document ID {#document-id}
|
||||
|
||||
Every document has a unique `id`. By default, a document `id` is the name of the document (without the extension) relative to the root docs directory.
|
||||
|
||||
For example, the ID of `greeting.md` is `greeting`, and the ID of `guide/hello.md` is `guide/hello`.
|
||||
|
||||
```bash
|
||||
website # Root directory of your site
|
||||
└── docs
|
||||
├── greeting.md
|
||||
└── guide
|
||||
└── hello.md
|
||||
```
|
||||
|
||||
However, the **last part** of the `id` can be defined by the user in the front matter. For example, if `guide/hello.md`'s content is defined as below, its final `id` is `guide/part1`.
|
||||
|
||||
```md
|
||||
---
|
||||
id: part1
|
||||
---
|
||||
|
||||
Lorem ipsum
|
||||
```
|
||||
|
||||
The ID is used to refer to a document when hand-writing sidebars, or when using docs-related layout components or hooks.
|
||||
|
||||
### Doc URLs {#doc-urls}
|
||||
|
||||
By default, a document's URL location is its file path relative to the `docs` folder, with a few exceptions. Namely, if a file is named one the following, the file name won't be included in the URL:
|
||||
|
||||
- Named as `index` (case-insensitive): `docs/Guides/index.md`
|
||||
- Named as `README` (case-insensitive): `docs/Guides/README.mdx`
|
||||
- Same name as parent folder: `docs/Guides/Guides.md`
|
||||
|
||||
In all cases, the default slug would only be `/Guides`, without the `/index`, `/README`, or duplicate `/Guides` segment.
|
||||
|
||||
:::note
|
||||
|
||||
This convention is exactly the same as [the category index convention](./sidebar/autogenerated.mdx#category-index-convention). However, the `isCategoryIndex` configuration does _not_ affect the document URL.
|
||||
|
||||
:::
|
||||
|
||||
Use the `slug` front matter to change a document's URL.
|
||||
|
||||
For example, suppose your site structure looks like this:
|
||||
|
||||
```bash
|
||||
website # Root directory of your site
|
||||
└── docs
|
||||
└── guide
|
||||
└── hello.md
|
||||
```
|
||||
|
||||
By default `hello.md` will be available at `/docs/guide/hello`. You can change its URL location to `/docs/bonjour`:
|
||||
|
||||
```md
|
||||
---
|
||||
slug: /bonjour
|
||||
---
|
||||
|
||||
Lorem ipsum
|
||||
```
|
||||
|
||||
`slug` will be appended to the doc plugin's `routeBasePath`, which is `/docs` by default. See [Docs-only mode](docs-introduction.mdx#docs-only-mode) for how to remove the `/docs` part from the URL.
|
||||
|
||||
:::note
|
||||
|
||||
It is possible to use:
|
||||
|
||||
- absolute slugs: `slug: /mySlug`, `slug: /`...
|
||||
- relative slugs: `slug: mySlug`, `slug: ./../mySlug`...
|
||||
|
||||
:::
|
||||
|
||||
If you want a document to be available at the root, and have a path like `https://docusaurus.io/docs/`, you can use the slug front matter:
|
||||
|
||||
```md
|
||||
---
|
||||
id: my-home-doc
|
||||
slug: /
|
||||
---
|
||||
|
||||
Lorem ipsum
|
||||
```
|
||||
|
||||
### Sidebars {#sidebars}
|
||||
|
||||
When using [autogenerated sidebars](./sidebar/autogenerated.mdx), the file structure will determine the sidebar structure.
|
||||
|
||||
Our recommendation for file system organization is: make your file system mirror the sidebar structure (so you don't need to handwrite your `sidebars.js` file), and use the `slug` front matter to customize URLs of each document.
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue