mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
docs(v2): update plugins, presets and themes docs (#1889)
* docs(v2): update plugins, presets and themes docs * ideal image plugin * proof reading * Merge master
This commit is contained in:
parent
242c9e0c29
commit
2bbfbf88d6
12 changed files with 360 additions and 227 deletions
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
id: advanced-themes
|
||||
title: Themes
|
||||
title: Writing Themes
|
||||
---
|
||||
|
||||
In this doc, we discuss how themes are designed and how you can write your own themes.
|
||||
|
@ -32,47 +32,8 @@ A Docusaurus theme normally includes an `index.js` file where you hook up to the
|
|||
```
|
||||
|
||||
There are two lifecycle methods that are essential to theme implementation:
|
||||
|
||||
**`getThemePath`**
|
||||
|
||||
Returns the path to the directory where the theme components can be found. When your users calls `swizzle`, `getThemePath` is called and its returned path is used to find your theme components.
|
||||
|
||||
If you use the folder directory above, your `getThemePath` can be:
|
||||
|
||||
```js
|
||||
// my-theme/src/index.js
|
||||
|
||||
const path = require('path');
|
||||
module.exports = function(context, options) {
|
||||
return {
|
||||
name: 'name-of-my-theme',
|
||||
getThemePath() {
|
||||
return path.resolve(__dirname, './theme');
|
||||
},
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
**`getClientModules`**
|
||||
|
||||
Returns 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.
|
||||
|
||||
As an example, to make your theme load a `customCss` object from `options` passed in by the user:
|
||||
|
||||
```js
|
||||
// my-theme/src/index.js
|
||||
|
||||
const path = require('path');
|
||||
module.exports = function(context, options) {
|
||||
const {customCss} = options || {};
|
||||
return {
|
||||
name: 'name-of-my-theme',
|
||||
getClientModules() {
|
||||
return [customCss];
|
||||
},
|
||||
};
|
||||
};
|
||||
```
|
||||
- [getThemePath](lifecycle-apis.md#getthemepath)
|
||||
- [getClientModules](lifecycle-apis.md#getclientmodules)
|
||||
|
||||
<!--
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue