mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-29 17:07:08 +02:00
chore(v2): prepare v2.0.0-beta.0 release (#4774)
* beta.0 version docs + changelog * fix config for beta switch * v2.0.0-beta.0
This commit is contained in:
parent
fe6492aa87
commit
7e4d7671c8
103 changed files with 11779 additions and 149 deletions
|
@ -0,0 +1,489 @@
|
|||
---
|
||||
id: docusaurus.config.js
|
||||
title: docusaurus.config.js
|
||||
description: API reference for Docusaurus configuration file.
|
||||
slug: /docusaurus.config.js
|
||||
---
|
||||
|
||||
## Overview {#overview}
|
||||
|
||||
`docusaurus.config.js` contains configurations for your site and is placed in the root directory of your site.
|
||||
|
||||
## Required fields {#required-fields}
|
||||
|
||||
### `title` {#title}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Title for your website.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
title: 'Docusaurus',
|
||||
};
|
||||
```
|
||||
|
||||
### `favicon` {#favicon}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
URL for site favicon. Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
favicon: 'https://docusaurus.io/favicon.ico',
|
||||
};
|
||||
```
|
||||
|
||||
You can also use the favicon URL relative to the `static` directory of your site. For example, your site has the following directory structure:
|
||||
|
||||
```bash
|
||||
.
|
||||
├── README.md
|
||||
├ # ... other files in root directory
|
||||
└─ static
|
||||
└── img
|
||||
└── favicon.ico
|
||||
```
|
||||
|
||||
So you can refer it like below:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
favicon: 'img/favicon.ico',
|
||||
};
|
||||
```
|
||||
|
||||
### `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"
|
||||
module.exports = {
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
```
|
||||
|
||||
### `baseUrl` {#baseurl}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
Base URL for your site. This can also be considered the path after the host. For example, `/metro/` is the baseUrl 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.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
baseUrl: '/',
|
||||
};
|
||||
```
|
||||
|
||||
## Optional fields {#optional-fields}
|
||||
|
||||
### `i18n` {#i18n}
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
The i18n configuration object to [localize your site](../i18n/i18n-introduction.md).
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
locales: ['en', 'fr'],
|
||||
localeConfigs: {
|
||||
en: {
|
||||
label: 'English',
|
||||
direction: 'ltr',
|
||||
},
|
||||
fr: {
|
||||
label: 'Français',
|
||||
direction: 'ltr',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
- `label`: the label to use for this locale
|
||||
- `direction`: `ltr` (default) or `rtl` (for [right-to-left languages](https://developer.mozilla.org/en-US/docs/Glossary/rtl) like Araric, Hebrew, etc.)
|
||||
|
||||
### `noIndex` {#noindex}
|
||||
|
||||
- Type: `boolean`
|
||||
|
||||
This option adds `<meta name="robots" content="noindex, nofollow">` in pages, 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"
|
||||
module.exports = {
|
||||
noIndex: true, // Defaults to `false`
|
||||
};
|
||||
```
|
||||
|
||||
### `onBrokenLinks` {#onbrokenlinks}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'error' | '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, but you can lower this security if needed.
|
||||
|
||||
:::note
|
||||
|
||||
The broken links detection is only available for a production build (`docusaurus build`).
|
||||
|
||||
:::
|
||||
|
||||
### `onBrokenMarkdownLinks` {#onbrokenmarkdownlinks}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'error' | '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, but you can change this security if needed.
|
||||
|
||||
### `onDuplicateRoutes` {#onduplicateroutes}
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'error' | 'throw'`
|
||||
|
||||
The behavior of Docusaurus when it detects any [duplicate routes](/guides/creating-pages.md#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"
|
||||
module.exports = {
|
||||
tagline:
|
||||
'Docusaurus makes it easy to maintain Open Source documentation websites.',
|
||||
};
|
||||
```
|
||||
|
||||
### `organizationName` {#organizationname}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The GitHub user or organization that owns the repository. Used by the deployment command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// Docusaurus' organization is facebook
|
||||
organizationName: 'facebook',
|
||||
};
|
||||
```
|
||||
|
||||
### `projectName` {#projectname}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The name of the GitHub repository. Used by the deployment command.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
projectName: 'docusaurus',
|
||||
};
|
||||
```
|
||||
|
||||
### `githubHost` {#githubhost}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The hostname of your server. Useful if you are using GitHub Enterprise.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
githubHost: 'github.com',
|
||||
};
|
||||
```
|
||||
|
||||
### `githubPort` {#githubPort}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
The port of your server. Useful if you are using GitHub Enterprise.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
githubPort: '22',
|
||||
};
|
||||
```
|
||||
|
||||
### `themeConfig` {#themeconfig}
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
The [theme configuration](./themes/theme-configuration.md) object, to customize your site UI like navbar, footer.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themeConfig: {
|
||||
hideableSidebar: false,
|
||||
colorMode: {
|
||||
defaultMode: 'light',
|
||||
disableSwitch: false,
|
||||
respectPrefersColorScheme: true,
|
||||
switchConfig: {
|
||||
darkIcon: '🌙',
|
||||
lightIcon: '\u2600',
|
||||
// React inline style object
|
||||
// see https://reactjs.org/docs/dom-elements.html#style
|
||||
darkIconStyle: {
|
||||
marginLeft: '2px',
|
||||
},
|
||||
lightIconStyle: {
|
||||
marginLeft: '1px',
|
||||
},
|
||||
},
|
||||
},
|
||||
navbar: {
|
||||
title: 'Site Title',
|
||||
logo: {
|
||||
alt: 'Site Logo',
|
||||
src: 'img/logo.svg',
|
||||
},
|
||||
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: 'Facebook Open Source Logo',
|
||||
src: 'https://docusaurus.io/img/oss_logo.png',
|
||||
},
|
||||
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, // You can also put own HTML here
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### `plugins` {#plugins}
|
||||
|
||||
<!-- TODO: configuration for plugins -->
|
||||
|
||||
- Type: `any[]`
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [],
|
||||
};
|
||||
```
|
||||
|
||||
### `themes` {#themes}
|
||||
|
||||
<!-- TODO: configuration for plugins -->
|
||||
|
||||
- Type: `any[]`
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themes: [],
|
||||
};
|
||||
```
|
||||
|
||||
### `presets` {#presets}
|
||||
|
||||
<!-- TODO: configuration for presets -->
|
||||
|
||||
- Type: `any[]`
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
presets: [],
|
||||
};
|
||||
```
|
||||
|
||||
### `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"
|
||||
module.exports = {
|
||||
customFields: {
|
||||
admin: 'endi',
|
||||
superman: 'lol',
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Attempting to add unknown field in the config will lead to error in build time:
|
||||
|
||||
```bash
|
||||
Error: The field(s) 'foo', 'bar' are not recognized in docusaurus.config.js
|
||||
```
|
||||
|
||||
### `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>`.
|
||||
|
||||
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"
|
||||
module.exports = {
|
||||
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,
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `clientModules` {#clientmodules}
|
||||
|
||||
An array of client modules to load globally on your site:
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
clientModules: [
|
||||
require.resolve('./mySiteGlobalJs.js'),
|
||||
require.resolve('./mySiteGlobalCss.css'),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
See also: [`getClientModules()`](lifecycle-apis.md#getclientmodules).
|
||||
|
||||
### `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"
|
||||
module.exports = {
|
||||
ssrTemplate: `<!DOCTYPE html>
|
||||
<html <%~ it.htmlAttributes %>>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=3.0, minimum-scale=0.86">
|
||||
<meta name="generator" content="Docusaurus v<%= it.version %>">
|
||||
<%~ it.headTags %>
|
||||
<% it.metaAttributes.forEach((metaAttribute) => { %>
|
||||
<%~ metaAttribute %>
|
||||
<% }); %>
|
||||
<% it.stylesheets.forEach((stylesheet) => { %>
|
||||
<link rel="stylesheet" type="text/css" href="<%= it.baseUrl %><%= stylesheet %>" />
|
||||
<% }); %>
|
||||
<% it.scripts.forEach((script) => { %>
|
||||
<link rel="preload" href="<%= it.baseUrl %><%= script %>" as="script">
|
||||
<% }); %>
|
||||
</head>
|
||||
<body <%~ it.bodyAttributes %> itemscope="" itemtype="http://schema.org/Organization">
|
||||
<%~ it.preBodyTags %>
|
||||
<div id="__docusaurus">
|
||||
<%~ it.appHtml %>
|
||||
</div>
|
||||
<div id="outside-docusaurus">
|
||||
<span>Custom markup</span>
|
||||
</div>
|
||||
<% it.scripts.forEach((script) => { %>
|
||||
<script type="text/javascript" src="<%= it.baseUrl %><%= script %>"></script>
|
||||
<% }); %>
|
||||
<%~ it.postBodyTags %>
|
||||
</body>
|
||||
</html>
|
||||
};
|
||||
```
|
||||
|
||||
### `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>`.
|
||||
|
||||
- Type: `(string | Object)[]`
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
stylesheets: [
|
||||
// String format.
|
||||
'https://docusaurus.io/style.css',
|
||||
// Object format.
|
||||
{
|
||||
href: 'http://mydomain.com/style.css',
|
||||
type: 'text/css',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `titleDelimiter` {#titledelimiter}
|
||||
|
||||
- Type: `string`
|
||||
|
||||
A string that will be used as title delimiter in the generated `<title>` tag.
|
||||
|
||||
Example:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
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"
|
||||
module.exports = {
|
||||
baseUrlIssueBanner: true, // Defaults to `true`
|
||||
};
|
||||
```
|
||||
|
||||

|
||||
|
||||
:::caution
|
||||
|
||||
This banner need to inline CSS / JS.
|
||||
|
||||
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,28 @@
|
|||
---
|
||||
id: plugins-overview
|
||||
title: 'Docusaurus plugins'
|
||||
sidebar_label: Plugins overview
|
||||
slug: '/api/plugins'
|
||||
---
|
||||
|
||||
We provide official Docusaurus plugins.
|
||||
|
||||
## Content plugins {#content-plugins}
|
||||
|
||||
These plugins are responsible to load your site's content, and create pages for your theme to render.
|
||||
|
||||
- [@docusaurus/plugin-content-docs](./plugin-content-docs.md)
|
||||
- [@docusaurus/plugin-content-blog](./plugin-content-blog.md)
|
||||
- [@docusaurus/plugin-content-pages](./plugin-content-pages.md)
|
||||
|
||||
## Behavior plugins {#behavior-plugins}
|
||||
|
||||
These plugins will add a useful behavior to your Docusaurus site.
|
||||
|
||||
- [@docusaurus/plugin-debug](./plugin-debug.md)
|
||||
- [@docusaurus/plugin-sitemap](./plugin-sitemap.md)
|
||||
- [@docusaurus/plugin-pwa](./plugin-pwa.md)
|
||||
- [@docusaurus/plugin-client-redirects](./plugin-client-redirects.md)
|
||||
- [@docusaurus/plugin-ideal-image](./plugin-ideal-image.md)
|
||||
- [@docusaurus/plugin-google-analytics](./plugin-google-analytics.md)
|
||||
- [@docusaurus/plugin-google-gtag](./plugin-google-gtag.md)
|
|
@ -0,0 +1,129 @@
|
|||
---
|
||||
id: plugin-client-redirects
|
||||
title: '📦 plugin-client-redirects'
|
||||
slug: '/api/plugins/@docusaurus/plugin-client-redirects'
|
||||
---
|
||||
|
||||
Docusaurus Plugin to generate **client-side redirects**.
|
||||
|
||||
This plugin will write additional HTML pages to your static site, that redirects the user to your existing Docusaurus pages with JavaScript.
|
||||
|
||||
:::note
|
||||
|
||||
This plugin only create redirects for the production build.
|
||||
|
||||
:::
|
||||
|
||||
:::caution
|
||||
|
||||
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}
|
||||
|
||||
Main usecase: you have `/myDocusaurusPage`, and you want to redirect to this page from `/myDocusaurusPage.html`:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-client-redirects',
|
||||
{
|
||||
fromExtensions: ['html'],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
Second usecase: you have `/myDocusaurusPage.html`, and you want to redirect to this page from `/myDocusaurusPage`.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-client-redirects',
|
||||
{
|
||||
toExtensions: ['html'],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
For custom redirect logic, provide your own `createRedirects` function.
|
||||
|
||||
Let's imagine you change the url of an existing page, you might want to make sure the old url still works:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-client-redirects',
|
||||
{
|
||||
redirects: [
|
||||
{
|
||||
to: '/docs/newDocPath', // string
|
||||
from: ['/docs/oldDocPathFrom2019', '/docs/legacyDocPathFrom2016'], // string | string[]
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
It's possible to use a function to create the redirects for each existing path:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-client-redirects',
|
||||
{
|
||||
createRedirects: function (existingPath) {
|
||||
if (existingPath === '/docs/newDocPath') {
|
||||
return ['/docs/oldDocPathFrom2019', '/docs/legacyDocPathFrom2016']; // string | string[]
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
Finally, it's possible to use all options at the same time:
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-client-redirects',
|
||||
{
|
||||
fromExtensions: ['html', 'htm'],
|
||||
toExtensions: ['exe', 'zip'],
|
||||
redirects: [
|
||||
{
|
||||
to: '/docs/newDocPath',
|
||||
from: '/docs/oldDocPath',
|
||||
},
|
||||
],
|
||||
createRedirects: function (existingPath) {
|
||||
if (existingPath === '/docs/newDocPath2') {
|
||||
return ['/docs/oldDocPath2'];
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
|
@ -0,0 +1,140 @@
|
|||
---
|
||||
id: plugin-content-blog
|
||||
title: '📦 plugin-content-blog'
|
||||
slug: '/api/plugins/@docusaurus/plugin-content-blog'
|
||||
---
|
||||
|
||||
Provides the [Blog](blog.md) feature and is the default blog plugin for Docusaurus.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-content-blog
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency. You can also configure it through the [classic preset options](presets.md#docusauruspreset-classic) instead of doing it like below.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-content-blog',
|
||||
{
|
||||
/**
|
||||
* Path to data on filesystem relative to site dir.
|
||||
*/
|
||||
path: 'blog',
|
||||
/**
|
||||
* Base url to edit your site.
|
||||
* Docusaurus will compute the final editUrl with "editUrl + relativeDocPath"
|
||||
*/
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
|
||||
/**
|
||||
* For advanced cases, compute the edit url for each markdown file yourself.
|
||||
*/
|
||||
editUrl: ({locale, blogDirPath, blogPath, permalink}) => {
|
||||
return `https://github.com/facebook/docusaurus/edit/master/website/${blogDirPath}/${blogPath}`;
|
||||
},
|
||||
/**
|
||||
* Useful if you commit localized files to git.
|
||||
* When markdown files are localized, the edit url will target the localized file,
|
||||
* instead of the original unlocalized file.
|
||||
* Note: this option is ignored when editUrl is a function
|
||||
*/
|
||||
editLocalizedFiles: false,
|
||||
/**
|
||||
* Blog page title for better SEO
|
||||
*/
|
||||
blogTitle: 'Blog title',
|
||||
/**
|
||||
* Blog page meta description for better SEO
|
||||
*/
|
||||
blogDescription: 'Blog',
|
||||
/**
|
||||
* Number of blog post elements to show in the blog sidebar
|
||||
* 'ALL' to show all blog posts
|
||||
* 0 to disable
|
||||
*/
|
||||
blogSidebarCount: 5,
|
||||
/**
|
||||
* Title of the blog sidebar
|
||||
*/
|
||||
blogSidebarTitle: 'All our posts',
|
||||
/**
|
||||
* URL route for the blog section of your site.
|
||||
* *DO NOT* include a trailing slash.
|
||||
*/
|
||||
routeBasePath: 'blog',
|
||||
include: ['*.md', '*.mdx'],
|
||||
postsPerPage: 10,
|
||||
/**
|
||||
* Theme components used by the blog pages.
|
||||
*/
|
||||
blogListComponent: '@theme/BlogListPage',
|
||||
blogPostComponent: '@theme/BlogPostPage',
|
||||
blogTagsListComponent: '@theme/BlogTagsListPage',
|
||||
blogTagsPostsComponent: '@theme/BlogTagsPostsPage',
|
||||
/**
|
||||
* Remark and Rehype plugins passed to MDX.
|
||||
*/
|
||||
remarkPlugins: [
|
||||
/* require('remark-math') */
|
||||
],
|
||||
rehypePlugins: [],
|
||||
/**
|
||||
* Custom Remark and Rehype plugins passed to MDX before
|
||||
* the default Docusaurus Remark and Rehype plugins.
|
||||
*/
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
/**
|
||||
* Truncate marker, can be a regex or string.
|
||||
*/
|
||||
truncateMarker: /<!--\s*(truncate)\s*-->/,
|
||||
/**
|
||||
* Show estimated reading time for the blog post.
|
||||
*/
|
||||
showReadingTime: true,
|
||||
/**
|
||||
* Blog feed.
|
||||
* If feedOptions is undefined, no rss feed will be generated.
|
||||
*/
|
||||
feedOptions: {
|
||||
type: '', // required. 'rss' | 'feed' | 'all'
|
||||
title: '', // default to siteConfig.title
|
||||
description: '', // default to `${siteConfig.title} Blog`
|
||||
copyright: '',
|
||||
language: undefined, // possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.md) 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**: N/A
|
||||
- **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
|
||||
├── first-blog-post.md
|
||||
└── second-blog-post.md
|
||||
```
|
|
@ -0,0 +1,260 @@
|
|||
---
|
||||
id: plugin-content-docs
|
||||
title: '📦 plugin-content-docs'
|
||||
slug: '/api/plugins/@docusaurus/plugin-content-docs'
|
||||
---
|
||||
|
||||
Provides the [Docs](../../guides/docs/docs-introduction.md) functionality and is the default docs plugin for Docusaurus.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-content-docs
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency. You can also configure it through the [classic preset options](presets.md#docusauruspreset-classic) instead of doing it like below.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-content-docs',
|
||||
{
|
||||
/**
|
||||
* Path to data on filesystem relative to site dir.
|
||||
*/
|
||||
path: 'docs',
|
||||
/**
|
||||
* Base url to edit your site.
|
||||
* Docusaurus will compute the final editUrl with "editUrl + relativeDocPath"
|
||||
*/
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
|
||||
/**
|
||||
* For advanced cases, compute the edit url for each markdown file yourself.
|
||||
*/
|
||||
editUrl: function ({
|
||||
locale,
|
||||
version,
|
||||
versionDocsDirPath,
|
||||
docPath,
|
||||
permalink,
|
||||
}) {
|
||||
return `https://github.com/facebook/docusaurus/edit/master/website/${versionDocsDirPath}/${docPath}`;
|
||||
},
|
||||
/**
|
||||
* Useful if you commit localized files to git.
|
||||
* When markdown files are localized, the edit url will target the localized file,
|
||||
* instead of the original unlocalized file.
|
||||
* Note: this option is ignored when editUrl is a function
|
||||
*/
|
||||
editLocalizedFiles: false,
|
||||
/**
|
||||
* Useful if you don't want users to submit doc pull-requests to older versions.
|
||||
* When docs are versioned, the edit url will link to the doc
|
||||
* in current version, instead of the versioned doc.
|
||||
* Note: this option is ignored when editUrl is a function
|
||||
*/
|
||||
editCurrentVersion: false,
|
||||
/**
|
||||
* URL route for the docs section of your site.
|
||||
* *DO NOT* include a trailing slash.
|
||||
* INFO: It is possible to set just `/` for shipping docs without base path.
|
||||
*/
|
||||
routeBasePath: 'docs',
|
||||
include: ['**/*.md', '**/*.mdx'], // Extensions to include.
|
||||
/**
|
||||
* Path to sidebar configuration for showing a list of markdown pages.
|
||||
*/
|
||||
sidebarPath: 'sidebars.js',
|
||||
/**
|
||||
* Function used to replace the sidebar items of type "autogenerated"
|
||||
* by real sidebar items (docs, categories, links...)
|
||||
*/
|
||||
sidebarItemsGenerator: async function ({
|
||||
defaultSidebarItemsGenerator, // useful to re-use/enhance default sidebar generation logic from Docusaurus
|
||||
numberPrefixParser, // numberPrefixParser configured for this plugin
|
||||
item, // the sidebar item with type "autogenerated"
|
||||
version, // the current version
|
||||
docs, // all the docs of that version (unfiltered)
|
||||
}) {
|
||||
// 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'},
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
/**
|
||||
* The Docs plugin supports number prefixes like "01-My Folder/02.My Doc.md".
|
||||
* Number prefixes are extracted and used as position to order autogenerated sidebar items.
|
||||
* For conveniency, number prefixes are automatically removed from the default doc id, name, title.
|
||||
* This parsing logic is configurable to allow all possible usecases and filename patterns.
|
||||
* Use "false" to disable this behavior and leave the docs untouched.
|
||||
*/
|
||||
numberPrefixParser: function (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};
|
||||
},
|
||||
/**
|
||||
* Theme components used by the docs pages
|
||||
*/
|
||||
docLayoutComponent: '@theme/DocPage',
|
||||
docItemComponent: '@theme/DocItem',
|
||||
/**
|
||||
* Remark and Rehype plugins passed to MDX
|
||||
*/
|
||||
remarkPlugins: [
|
||||
/* require('remark-math') */
|
||||
],
|
||||
rehypePlugins: [],
|
||||
/**
|
||||
* Custom Remark and Rehype plugins passed to MDX before
|
||||
* the default Docusaurus Remark and Rehype plugins.
|
||||
*/
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
/**
|
||||
* Whether to display the author who last updated the doc.
|
||||
*/
|
||||
showLastUpdateAuthor: false,
|
||||
/**
|
||||
* Whether to display the last date the doc was updated.
|
||||
*/
|
||||
showLastUpdateTime: false,
|
||||
/**
|
||||
* By default, versioning is enabled on versioned sites.
|
||||
* This is a way to explicitly disable the versioning feature.
|
||||
*/
|
||||
disableVersioning: false,
|
||||
/**
|
||||
* Skip the next release docs when versioning is enabled.
|
||||
* This will not generate HTML files in the production build for documents
|
||||
* in `/docs/next` directory, only versioned docs.
|
||||
*/
|
||||
excludeNextVersionDocs: false,
|
||||
/**
|
||||
* The last version is the one we navigate to in priority on versioned sites
|
||||
* It is the one displayed by default in docs navbar items
|
||||
* By default, the last version is the first one to appear in versions.json
|
||||
* By default, the last version is at the "root" (docs have path=/docs/myDoc)
|
||||
* Note: it is possible to configure the path and label of the last version
|
||||
* Tip: using lastVersion: 'current' make sense in many cases
|
||||
*/
|
||||
lastVersion: undefined,
|
||||
/**
|
||||
* The docusaurus versioning defaults don't make sense for all projects
|
||||
* This gives the ability customize the label and path of each version
|
||||
* You may not like that default version
|
||||
*/
|
||||
versions: {
|
||||
/*
|
||||
Example configuration:
|
||||
current: {
|
||||
label: 'Android SDK v2.0.0 (WIP)',
|
||||
path: 'android-2.0.0',
|
||||
},
|
||||
'1.0.0': {
|
||||
label: 'Android SDK v1.0.0',
|
||||
path: 'android-1.0.0',
|
||||
},
|
||||
*/
|
||||
},
|
||||
/**
|
||||
* Sometimes you only want to include a subset of all available versions.
|
||||
* Tip: limit to 2 or 3 versions to improve startup and build time in dev and deploy previews
|
||||
*/
|
||||
onlyIncludeVersions: undefined, // ex: ["current", "1.0.0", "2.0.0"]
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## Markdown Frontmatter {#markdown-frontmatter}
|
||||
|
||||
Markdown documents can use the following markdown frontmatter metadata fields, enclosed by a line `---` on either side:
|
||||
|
||||
- `id`: A unique document id. If this field is not present, the document's `id` will default to its file name (without the extension)
|
||||
- `title`: The title of your document. If this field is not present, the document's `title` will default to its `id`
|
||||
- `hide_title`: Whether to hide the title at the top of the doc. By default, it is `false`
|
||||
- `hide_table_of_contents`: Whether to hide the table of contents to the right. By default it is `false`
|
||||
- `sidebar_label`: The text shown in the document sidebar and in the next/previous button for this document. If this field is not present, the document's `sidebar_label` will default to its `title`
|
||||
- `sidebar_position`: Permits to control the position of a doc inside the generated sidebar slice, when using `autogenerated` sidebar items. Can be Int or Float.
|
||||
- `parse_number_prefixes`: When a document has a number prefix (`001 - My Doc.md`, `2. MyDoc.md`...), it is automatically parsed and extracted by the plugin `numberPrefixParser`, and the number prefix is used as `sidebar_position`. Use `parse_number_prefixes: false` to disable number prefix parsing on this doc
|
||||
- `custom_edit_url`: The URL for editing this document. If this field is not present, the document's edit URL will fall back to `editUrl` from options fields passed to `docusaurus-plugin-content-docs`
|
||||
- `keywords`: Keywords meta tag for the document page, for search engines
|
||||
- `description`: 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. If this field is not present, it will default to the first line of the contents
|
||||
- `image`: Cover or thumbnail image that will be used when displaying the link to your post
|
||||
- `slug`: Allows to customize the document url (`/<routeBasePath>/<slug>`). Support multiple patterns: `slug: my-doc`, `slug: /my/path/myDoc`, `slug: /`
|
||||
|
||||
Example:
|
||||
|
||||
```yml
|
||||
---
|
||||
id: doc-markdown
|
||||
title: Markdown Features
|
||||
hide_title: false
|
||||
hide_table_of_contents: false
|
||||
sidebar_label: Markdown :)
|
||||
custom_edit_url: https://github.com/facebook/docusaurus/edit/master/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
|
||||
---
|
||||
My Document Markdown content
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.md) 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.md#docusaurus-write-translations)
|
||||
- **Markdown files**: `website/i18n/<locale>/docusaurus-plugin-content-docs/<version>`
|
||||
|
||||
### 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,89 @@
|
|||
---
|
||||
id: plugin-content-pages
|
||||
title: '📦 plugin-content-pages'
|
||||
slug: '/api/plugins/@docusaurus/plugin-content-pages'
|
||||
---
|
||||
|
||||
The default pages plugin for Docusaurus. The classic template ships with this plugin with default configurations. This plugin provides [creating pages](guides/creating-pages.md) functionality.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-content-pages
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency. You can also configure it through the [classic preset options](presets.md#docusauruspreset-classic) instead of doing it like below.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-content-pages',
|
||||
{
|
||||
/**
|
||||
* Path to data on filesystem
|
||||
* relative to site dir
|
||||
* components in this directory will be automatically converted to pages
|
||||
*/
|
||||
path: 'src/pages',
|
||||
/**
|
||||
* URL route for the page section of your site
|
||||
* do not include trailing slash
|
||||
*/
|
||||
routeBasePath: '',
|
||||
include: ['**/*.{js,jsx,ts,tsx,md,mdx}'],
|
||||
/**
|
||||
* No Route will be created for matching files
|
||||
*/
|
||||
exclude: [
|
||||
'**/_*.{js,jsx,ts,tsx,md,mdx}',
|
||||
'**/*.test.{js,ts}',
|
||||
'**/__tests__/**',
|
||||
],
|
||||
/**
|
||||
* Theme component used by markdown pages.
|
||||
*/
|
||||
mdxPageComponent: '@theme/MDXPage',
|
||||
/**
|
||||
* Remark and Rehype plugins passed to MDX
|
||||
*/
|
||||
remarkPlugins: [],
|
||||
rehypePlugins: [],
|
||||
/**
|
||||
* Custom Remark and Rehype plugins passed to MDX before
|
||||
* the default Docusaurus Remark and Rehype plugins.
|
||||
*/
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.md) 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.md#docusaurus-write-translations)
|
||||
- **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,39 @@
|
|||
---
|
||||
id: plugin-debug
|
||||
title: '📦 plugin-debug'
|
||||
slug: '/api/plugins/@docusaurus/plugin-debug'
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
:::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](http://docusaurus.io/__docusaurus/debug).
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-debug
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency. You can also configure it through the [classic preset options](presets.md#docusauruspreset-classic) instead of doing it like below.
|
||||
|
||||
By default, it's enabled in dev, and disabled in prod, to avoid exposing potentially sensitive information.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: ['@docusaurus/plugin-debug'],
|
||||
};
|
||||
```
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
id: plugin-google-analytics
|
||||
title: '📦 plugin-google-analytics'
|
||||
slug: '/api/plugins/@docusaurus/plugin-google-analytics'
|
||||
---
|
||||
|
||||
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) instead.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-google-analytics
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: ['@docusaurus/plugin-google-analytics'],
|
||||
themeConfig: {
|
||||
googleAnalytics: {
|
||||
trackingID: 'UA-141789564-1',
|
||||
// Optional fields.
|
||||
anonymizeIP: true, // Should IPs be anonymized?
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
id: plugin-google-gtag
|
||||
title: '📦 plugin-google-gtag'
|
||||
slug: '/api/plugins/@docusaurus/plugin-google-gtag'
|
||||
---
|
||||
|
||||
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, **in the production build**. 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!
|
||||
|
||||
:::
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-google-gtag
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: ['@docusaurus/plugin-google-gtag'],
|
||||
themeConfig: {
|
||||
gtag: {
|
||||
// You can also use your "G-" Measurement ID here.
|
||||
trackingID: 'UA-141789564-1',
|
||||
// Optional fields.
|
||||
anonymizeIP: true, // Should IPs be anonymized?
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
id: plugin-ideal-image
|
||||
title: '📦 plugin-ideal-image'
|
||||
slug: '/api/plugins/@docusaurus/plugin-ideal-image'
|
||||
---
|
||||
|
||||
Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder) **in the production builds**.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-ideal-image
|
||||
```
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
Modify your `docusaurus.config.js`
|
||||
|
||||
```diff
|
||||
module.exports = {
|
||||
...
|
||||
+ plugins: ['@docusaurus/plugin-ideal-image'],
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Usage {#usage}
|
||||
|
||||
This plugin supports the PNG, GIF 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')} />
|
||||
```
|
||||
|
||||
## Options {#options}
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| `name` | `string` | `ideal-img/[name].[hash:hex:7].[width].[ext]` | Filename template for output files. |
|
||||
| `sizes` | `array` | _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` | `integer` | _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` | `integer` | | As an alternative to manually specifying `sizes`, you can specify `min`, `max` and `steps`, and the sizes will be generated for you. |
|
||||
| `max` | `integer` | | See `min` above |
|
||||
| `steps` | `integer` | `4` | Configure the number of images generated between `min` and `max` (inclusive) |
|
||||
| `quality` | `integer` | `85` | JPEG compression quality |
|
|
@ -0,0 +1,313 @@
|
|||
---
|
||||
id: plugin-pwa
|
||||
title: '📦 plugin-pwa'
|
||||
slug: '/api/plugins/@docusaurus/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"
|
||||
module.exports = {
|
||||
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.
|
||||
|
||||
> ### [What is Precaching?](https://developers.google.com/web/tools/workbox/modules/workbox-precaching)
|
||||
>
|
||||
> 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.
|
||||
|
||||
:::caution
|
||||
|
||||
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: `Array<'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 <= 940px)
|
||||
- `saveData`: activates for users with `navigator.connection.saveData === true`
|
||||
- `always`: activates for all users
|
||||
|
||||
:::caution
|
||||
|
||||
Use this carefully: some users may not like to be forced to use the offline mode.
|
||||
|
||||
:::
|
||||
|
||||
:::danger
|
||||
|
||||
It is not possible to detect if an as a PWA in a very reliable way.
|
||||
|
||||
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://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.injectManifest) 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"
|
||||
module.exports = {
|
||||
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}'],
|
||||
// ...
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
### `reloadPopup` {#reloadpopup}
|
||||
|
||||
- Type: `string | false`
|
||||
- Default: `'@theme/PwaReloadPopup'`
|
||||
|
||||
Module path to reload popup component. This popup is rendered when a new service worker is waiting to be installed, and we suggest a reload to the user.
|
||||
|
||||
Passing `false` will disable the popup, but this is not recommended: users won't have a way to get up-to-date content.
|
||||
|
||||
A custom component can be used, as long as it accepts `onReload` as a prop. The `onReload` callback 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.
|
||||
|
||||
```ts
|
||||
interface PwaReloadPopupProps {
|
||||
onReload: () => void;
|
||||
}
|
||||
```
|
||||
|
||||
The default theme includes an implementation for the reload popup and uses [Infima Alerts](https://infima.dev/docs/components/alert).
|
||||
|
||||

|
||||
|
||||
### `pwaHead` {#pwahead}
|
||||
|
||||
- Type: `Array<{ tagName: string } & Record<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
|
||||
module.exports = {
|
||||
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>
|
||||
```
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
id: plugin-sitemap
|
||||
title: '📦 plugin-sitemap'
|
||||
slug: '/api/plugins/@docusaurus/plugin-sitemap'
|
||||
---
|
||||
|
||||
This plugin creates sitemap for your site so that search engine crawlers can crawl your site more accurately.
|
||||
|
||||
## Installation {#installation}
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/plugin-sitemap
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency. You can also configure it through the [classic preset options](presets.md#docusauruspreset-classic) instead of doing it like below.
|
||||
|
||||
:::
|
||||
|
||||
## Configuration {#configuration}
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
plugins: [
|
||||
[
|
||||
'@docusaurus/plugin-sitemap',
|
||||
{
|
||||
changefreq: 'weekly',
|
||||
priority: 0.5,
|
||||
trailingSlash: false,
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
```
|
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
id: themes-overview
|
||||
title: 'Docusaurus themes'
|
||||
sidebar_label: Themes overview
|
||||
slug: '/api/themes'
|
||||
---
|
||||
|
||||
We provide official Docusaurus themes.
|
||||
|
||||
## Main themes {#main-themes}
|
||||
|
||||
The main themes implement the user interface for the [docs](../plugins/plugin-content-docs.md), [blog](../plugins/plugin-content-blog.md) and [pages](../plugins/plugin-content-pages.md) plugins.
|
||||
|
||||
- [@docusaurus/theme-classic](./theme-classic.md)
|
||||
- [@docusaurus/theme-bootstrap](./theme-bootstrap.md) 🚧
|
||||
|
||||
:::caution
|
||||
|
||||
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.md)
|
||||
- [@docusaurus/theme-search-algolia](./theme-search-algolia.md)
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
id: theme-bootstrap
|
||||
title: '📦 theme-bootstrap'
|
||||
slug: '/api/themes/@docusaurus/theme-bootstrap'
|
||||
---
|
||||
|
||||
:::danger
|
||||
|
||||
The bootstrap theme is a work in progress, and is not production ready.
|
||||
|
||||
:::
|
||||
|
||||
🚧 The bootstrap theme for Docusaurus.
|
||||
|
||||
You can refer to the [theme configuration page](theme-configuration.md) for more details on the configuration.
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/theme-bootstrap
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-bootstrap`, you don't need to install it as a dependency.
|
||||
|
||||
:::
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
id: theme-classic
|
||||
title: '📦 theme-classic'
|
||||
slug: '/api/themes/@docusaurus/theme-classic'
|
||||
---
|
||||
|
||||
The classic theme for Docusaurus.
|
||||
|
||||
You can refer to the [theme configuration page](theme-configuration.md) 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.
|
||||
|
||||
:::
|
|
@ -0,0 +1,575 @@
|
|||
---
|
||||
id: theme-configuration
|
||||
title: 'Theme configuration'
|
||||
slug: '/api/themes/configuration'
|
||||
---
|
||||
|
||||
This configuration applies to all [main themes](./overview.md).
|
||||
|
||||
## Common {#common}
|
||||
|
||||
### Color mode - dark mode {#color-mode---dark-mode}
|
||||
|
||||
The classic theme provides by default light and dark mode support, with a navbar switch for the user.
|
||||
|
||||
It is possible to customize the color mode support with the following configuration:
|
||||
|
||||
```js {6-35} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
// ...
|
||||
colorMode: {
|
||||
// "light" | "dark"
|
||||
defaultMode: 'light',
|
||||
|
||||
// Hides the switch in the navbar
|
||||
// Useful if you want to support a single color mode
|
||||
disableSwitch: false,
|
||||
|
||||
// Should we use the prefers-color-scheme media-query,
|
||||
// using user system preferences, instead of the hardcoded defaultMode
|
||||
respectPrefersColorScheme: false,
|
||||
|
||||
// Dark/light switch icon options
|
||||
switchConfig: {
|
||||
// Icon for the switch while in dark mode
|
||||
darkIcon: '🌙',
|
||||
|
||||
// CSS to apply to dark icon,
|
||||
// React inline style object
|
||||
// see https://reactjs.org/docs/dom-elements.html#style
|
||||
darkIconStyle: {
|
||||
marginLeft: '2px',
|
||||
},
|
||||
|
||||
// Unicode icons such as '\u2600' will work
|
||||
// Unicode with 5 chars require brackets: '\u{1F602}'
|
||||
lightIcon: '\u{1F602}',
|
||||
|
||||
lightIconStyle: {
|
||||
marginLeft: '1px',
|
||||
},
|
||||
},
|
||||
},
|
||||
// ...
|
||||
},
|
||||
// ...
|
||||
};
|
||||
```
|
||||
|
||||
:::caution
|
||||
|
||||
With `respectPrefersColorScheme: true`, the `defaultMode` is overridden by user system preferences.
|
||||
|
||||
If you only want to support one color mode, you likely want to ignore user system preferences.
|
||||
|
||||
:::
|
||||
|
||||
### Meta image {#meta-image}
|
||||
|
||||
You can configure a default image that will be used for your meta tag, in particular `og:image` and `twitter:image`.
|
||||
|
||||
```js {4-6} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
// Relative to your site's "static" directory.
|
||||
// Cannot be SVGs. Can be external URLs too.
|
||||
image: 'img/docusaurus.png',
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Metadatas {#metadatas}
|
||||
|
||||
You can configure additional html metadatas (and override existing ones).
|
||||
|
||||
```js {4} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
metadatas: [{name: 'twitter:card', content: 'summary'}],
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Announcement bar {#announcement-bar}
|
||||
|
||||
Sometimes you want to announce something in your website. Just for such a case, you can add an announcement bar. This is a non-fixed and optionally dismissable panel above the navbar.
|
||||
|
||||
```js {4-11} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
announcementBar: {
|
||||
id: 'support_us', // Any value that will identify this message.
|
||||
content:
|
||||
'We are looking to revamp our docs, please fill <a target="_blank" rel="noopener noreferrer" href="#">this survey</a>',
|
||||
backgroundColor: '#fafbfc', // Defaults to `#fff`.
|
||||
textColor: '#091E42', // Defaults to `#000`.
|
||||
isCloseable: false, // Defaults to `true`.
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## i18n {#i18n}
|
||||
|
||||
Read the [i18n introduction](../../i18n/i18n-introduction.md) first.
|
||||
|
||||
### Translation files location {#translation-files-location}
|
||||
|
||||
- **Base path**: `website/i18n/<locale>/docusaurus-theme-<themeName>`
|
||||
- **Multi-instance path**: N/A
|
||||
- **JSON files**: extracted with [`docusaurus write-translations`](../../cli.md#docusaurus-write-translations)
|
||||
- **Markdown files**: `N/A
|
||||
|
||||
### Example file-system structure {#example-file-system-structure}
|
||||
|
||||
```bash
|
||||
website/i18n/<locale>/docusaurus-theme-classic
|
||||
│
|
||||
│ # translations for the theme
|
||||
├── navbar.json
|
||||
└── footer.json
|
||||
```
|
||||
|
||||
## Hooks {#hooks}
|
||||
|
||||
### `useThemeContext` {#usethemecontext}
|
||||
|
||||
React hook to access theme context. This context contains functions for setting light and dark mode and boolean property, indicating which mode is currently in use.
|
||||
|
||||
Usage example:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
// highlight-next-line
|
||||
import useThemeContext from '@theme/hooks/useThemeContext';
|
||||
|
||||
const Example = () => {
|
||||
// highlight-next-line
|
||||
const {isDarkTheme, setLightTheme, setDarkTheme} = useThemeContext();
|
||||
|
||||
return <h1>Dark mode is now {isDarkTheme ? 'on' : 'off'}</h1>;
|
||||
};
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
The component calling `useThemeContext` must be a child of the `Layout` component.
|
||||
|
||||
```jsx
|
||||
function ExamplePage() {
|
||||
return (
|
||||
<Layout>
|
||||
<Example />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Navbar {#navbar}
|
||||
|
||||
### Navbar title & logo {#navbar-title--logo}
|
||||
|
||||
You can add a logo and title to the navbar via `themeConfig.navbar`. Logo can be placed in [static folder](static-assets.md). Logo URL is set to base URL of your site by default. Although you can specify your own URL for the logo, if it is an external link, it will open in a new tab. In addition, you can override a value for the target attribute of logo link, it can come in handy if you are hosting docs website in a subdirectory of your main website, and in which case you probably do not need a link in the logo to the main website will open in a new tab.
|
||||
|
||||
To improve dark mode support, you can also set a different logo for this mode.
|
||||
|
||||
```js {5-11} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
title: 'Site Title',
|
||||
logo: {
|
||||
alt: 'Site Logo',
|
||||
src: 'img/logo.svg',
|
||||
srcDark: 'img/logo_dark.svg', // Default to `logo.src`.
|
||||
href: 'https://docusaurus.io/', // Default to `siteConfig.baseUrl`.
|
||||
target: '_self', // By default, this value is calculated based on the `href` attribute (the external link will open in a new tab, all others in the current one).
|
||||
},
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar items {#navbar-items}
|
||||
|
||||
You can add items to the navbar via `themeConfig.navbar.items`.
|
||||
|
||||
By default, Navbar items are regular links (internal or external).
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
// highlight-start
|
||||
items: [
|
||||
{
|
||||
// Client-side routing, used for navigating within the website.
|
||||
// The baseUrl will be automatically prepended to this value.
|
||||
to: 'docs/introduction',
|
||||
// A full-page navigation, used for navigating outside of the website.
|
||||
// You should only use either `to` or `href`.
|
||||
href: 'https://www.facebook.com',
|
||||
// Prepends the baseUrl to href values.
|
||||
prependBaseUrlToHref: true,
|
||||
// The string to be shown.
|
||||
label: 'Introduction',
|
||||
// Left or right side of the navbar.
|
||||
position: 'left', // or 'right'
|
||||
// To apply the active class styling on all
|
||||
// routes starting with this path.
|
||||
// This usually isn't necessary
|
||||
activeBasePath: 'docs',
|
||||
// Alternative to activeBasePath if required.
|
||||
activeBaseRegex: 'docs/(next|v8)',
|
||||
// Custom CSS class (for styling any item).
|
||||
className: '',
|
||||
},
|
||||
// ... other items
|
||||
],
|
||||
// highlight-end
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
React Router should automatically apply active link styling to links, but you can use `activeBasePath` in edge cases. For cases in which a link should be active on several different paths (such as when you have multiple doc folders under the same sidebar), you can use `activeBaseRegex`. `activeBaseRegex` is a more flexible alternative to `activeBasePath` and takes precedence over it -- Docusaurus parses it into a regular expression that is tested against the current URL.
|
||||
|
||||
Outbound (external) links automatically get `target="_blank" rel="noopener noreferrer"` attributes.
|
||||
|
||||
### Navbar dropdown {#navbar-dropdown}
|
||||
|
||||
Navbar items can also be dropdown items by specifying the `items`, an inner array of navbar items.
|
||||
|
||||
```js {9-19} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
label: 'Community',
|
||||
position: 'left', // or 'right'
|
||||
items: [
|
||||
{
|
||||
label: 'Facebook',
|
||||
href: '...',
|
||||
},
|
||||
{
|
||||
label: 'GitHub',
|
||||
href: '...',
|
||||
},
|
||||
// ... more items
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar doc link {#navbar-doc-link}
|
||||
|
||||
If you want to link to a specific doc, this special navbar item type will render the link to the doc of the provided `docId`. It will get the class `navbar__link--active` as long as you browse a doc of the same sidebar.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
items: [
|
||||
// highlight-start
|
||||
{
|
||||
type: 'doc',
|
||||
docId: 'introduction',
|
||||
|
||||
//// Optional
|
||||
position: 'left',
|
||||
label: 'Docs',
|
||||
activeSidebarClassName: 'navbar__link--active',
|
||||
docsPluginId: 'default',
|
||||
},
|
||||
// highlight-end
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar docs version dropdown {#navbar-docs-version-dropdown}
|
||||
|
||||
If you use docs with versioning, this special navbar item type that will render a dropdown with all your site's available versions.
|
||||
|
||||
The user will be able to switch from one version to another, while staying on the same doc (as long as the doc id is constant across versions).
|
||||
|
||||
```js {5-8} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
type: 'docsVersionDropdown',
|
||||
|
||||
//// Optional
|
||||
position: 'left',
|
||||
// Add additional dropdown items at the beginning/end of the dropdown.
|
||||
dropdownItemsBefore: [],
|
||||
dropdownItemsAfter: [{to: '/versions', label: 'All versions'}],
|
||||
// Do not add the link active class when browsing docs.
|
||||
dropdownActiveClassDisabled: true,
|
||||
docsPluginId: 'default',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar docs version {#navbar-docs-version}
|
||||
|
||||
If you use docs with versioning, this special navbar item type will link to the active/browsed version of your doc (depends on the current url), and fallback to the latest version.
|
||||
|
||||
```js title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
items: [
|
||||
// highlight-start
|
||||
{
|
||||
type: 'docsVersion',
|
||||
|
||||
//// Optional
|
||||
position: 'left',
|
||||
to: '/path', // by default, link to active/latest version
|
||||
label: 'label', // by default, show active/latest version label
|
||||
docsPluginId: 'default',
|
||||
},
|
||||
// highlight-end
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar locale dropdown {#navbar-locale-dropdown}
|
||||
|
||||
If you use the [i18n feature](../../i18n/i18n-introduction.md), this special navbar item type will render a dropdown with all your site's available locales.
|
||||
|
||||
The user will be able to switch from one locale to another, while staying on the same page.
|
||||
|
||||
```js {5-8} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
type: 'localeDropdown',
|
||||
|
||||
//// Optional
|
||||
position: 'left',
|
||||
// Add additional dropdown items at the beginning/end of the dropdown.
|
||||
dropdownItemsBefore: [],
|
||||
dropdownItemsAfter: [
|
||||
{
|
||||
to: 'https://my-site.com/help-us-translate',
|
||||
label: 'Help us translate',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar search {#navbar-search}
|
||||
|
||||
If you use the [search](../../search.md), the search bar will be the rightmost element in the navbar.
|
||||
|
||||
However, with this special navbar item type, you can change the default location.
|
||||
|
||||
```js {5-8} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
items: [
|
||||
{
|
||||
type: 'search',
|
||||
position: 'right',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Auto-hide sticky navbar {#auto-hide-sticky-navbar}
|
||||
|
||||
You can enable this cool UI feature that automatically hides the navbar when a user starts scrolling down the page, and show it again when the user scrolls up.
|
||||
|
||||
```js {5} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
hideOnScroll: true,
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Navbar style {#navbar-style}
|
||||
|
||||
You can set the static Navbar style without disabling the theme switching ability. The selected style will always apply no matter which theme user have selected.
|
||||
|
||||
Currently, there are two possible style options: `dark` and `primary` (based on the `--ifm-color-primary` color). You can see the styles preview in the [Infima documentation](https://infima.dev/docs/components/navbar/).
|
||||
|
||||
```js {5} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
navbar: {
|
||||
style: 'primary',
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
<!--
|
||||
|
||||
## Footer {#footer}
|
||||
|
||||
TODO.
|
||||
|
||||
-->
|
||||
|
||||
## CodeBlock {#codeblock}
|
||||
|
||||
Docusaurus uses [Prism React Renderer](https://github.com/FormidableLabs/prism-react-renderer) to highlight code blocks.
|
||||
|
||||
### Theme {#theme}
|
||||
|
||||
By default, we use [Palenight](https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/themes/palenight.js) as syntax highlighting theme. You can specify a custom theme from the [list of available themes](https://github.com/FormidableLabs/prism-react-renderer/tree/master/src/themes). If you want to use a different syntax highlighting theme when the site is in dark mode, you may also do so.
|
||||
|
||||
```js {5-6} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
prism: {
|
||||
theme: require('prism-react-renderer/themes/github'),
|
||||
darkTheme: require('prism-react-renderer/themes/dracula'),
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
If you use the line highlighting Markdown syntax, you might need to specify a different highlight background color for the dark mode syntax highlighting theme. Refer to the [docs for guidance](../../guides/markdown-features/markdown-features-code-blocks.mdx#line-highlighting).
|
||||
|
||||
:::
|
||||
|
||||
### Default language {#default-language}
|
||||
|
||||
You can set a default language for code blocks if no language is added after the opening triple backticks (i.e. ```). Note that a valid [language name](https://prismjs.com/#supported-languages) must be passed, e.g.:
|
||||
|
||||
```js {5} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
themeConfig: {
|
||||
prism: {
|
||||
defaultLanguage: 'javascript',
|
||||
},
|
||||
// ...
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## Footer {#footer-1}
|
||||
|
||||
You can add logo and a copyright to the footer via `themeConfig.footer`. Logo can be placed in [static folder](static-assets.md). Logo URL works in the same way of the navbar logo.
|
||||
|
||||
```js {5-15} title="docusaurus.config.js"
|
||||
// ...
|
||||
footer: {
|
||||
logo: {
|
||||
alt: 'Facebook Open Source Logo',
|
||||
src: 'img/oss_logo.png',
|
||||
href: 'https://opensource.facebook.com',
|
||||
},
|
||||
copyright: `Copyright © ${new Date().getFullYear()} My Project, Inc. Built with Docusaurus.`,
|
||||
}
|
||||
```
|
||||
|
||||
## Footer Links {#footer-links}
|
||||
|
||||
You can add links to the footer via `themeConfig.footer.links`:
|
||||
|
||||
```js {5-15} title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
// ...
|
||||
footer: {
|
||||
links: [
|
||||
{
|
||||
// Label of the section of these links
|
||||
title: 'Docs',
|
||||
items: [
|
||||
{
|
||||
// Label of the link
|
||||
label: 'Style Guide',
|
||||
// Client-side routing, used for navigating within the website.
|
||||
// The baseUrl will be automatically prepended to this value.
|
||||
to: 'docs/',
|
||||
},
|
||||
{
|
||||
label: 'Second Doc',
|
||||
to: 'docs/doc2/',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Community',
|
||||
items: [
|
||||
{
|
||||
label: 'Stack Overflow',
|
||||
// A full-page navigation, used for navigating outside of the website.
|
||||
href: 'https://stackoverflow.com/questions/tagged/docusaurus',
|
||||
},
|
||||
{
|
||||
label: 'Discord',
|
||||
href: 'https://discordapp.com/invite/docusaurus',
|
||||
},
|
||||
{
|
||||
label: 'Twitter',
|
||||
href: 'https://twitter.com/docusaurus',
|
||||
},
|
||||
{
|
||||
//Renders the html pass-through instead of a simple link
|
||||
html: `
|
||||
<a href="https://www.netlify.com" target="_blank" rel="noreferrer noopener" aria-label="Deploys by Netlify">
|
||||
<img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" alt="Deploys by Netlify" />
|
||||
</a>
|
||||
`,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
id: theme-live-codeblock
|
||||
title: '📦 theme-live-codeblock'
|
||||
slug: '/api/themes/@docusaurus/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}
|
||||
|
||||
```jsx title="docusaurus.config.js"
|
||||
module.exports = {
|
||||
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,19 @@
|
|||
---
|
||||
id: theme-search-algolia
|
||||
title: '📦 theme-search-algolia'
|
||||
slug: '/api/themes/@docusaurus/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.md) documentation.
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save @docusaurus/theme-search-algolia
|
||||
```
|
||||
|
||||
This theme also adds search page available at `/search` (as swizzleable `SearchPage` component) path with OpenSearch support.
|
||||
|
||||
:::tip
|
||||
|
||||
If you have installed `@docusaurus/preset-classic`, you don't need to install it as a dependency.
|
||||
|
||||
:::
|
Loading…
Add table
Add a link
Reference in a new issue