mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-07 06:07:42 +02:00
feat(v2): add support for sync to npm2yarn tabs (#3705)
This commit is contained in:
parent
f31dcb6844
commit
3aeb90fcac
3 changed files with 18 additions and 8 deletions
|
@ -34,15 +34,15 @@ module.exports = {
|
||||||
{
|
{
|
||||||
docs: {
|
docs: {
|
||||||
// ...
|
// ...
|
||||||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')],
|
remarkPlugins: [[require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}]],
|
||||||
},
|
},
|
||||||
blog: {
|
blog: {
|
||||||
// ...
|
// ...
|
||||||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')],
|
remarkPlugins: [[require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}]],
|
||||||
},
|
},
|
||||||
pages: {
|
pages: {
|
||||||
// ...
|
// ...
|
||||||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')],
|
remarkPlugins: [[require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}]],
|
||||||
},
|
},
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
@ -51,3 +51,9 @@ module.exports = {
|
||||||
// ...
|
// ...
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
| Property | Type | Default | Description |
|
||||||
|
|----------|-----------|---------|---------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `sync` | `boolean` | `false` | Syncing tab choices (yarn and npm). See https://v2.docusaurus.io/docs/markdown-features/#syncing-tab-choices for details. |
|
||||||
|
|
|
@ -10,14 +10,15 @@ const npmToYarn = require('npm-to-yarn');
|
||||||
// E.g. global install: 'npm i' -> 'yarn'
|
// E.g. global install: 'npm i' -> 'yarn'
|
||||||
const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn');
|
const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn');
|
||||||
|
|
||||||
const transformNode = (node) => {
|
const transformNode = (node, isSync) => {
|
||||||
|
const groupIdProp = isSync ? 'groupId="npm2yarn" ' : '';
|
||||||
const npmCode = node.value;
|
const npmCode = node.value;
|
||||||
const yarnCode = convertNpmToYarn(node.value);
|
const yarnCode = convertNpmToYarn(node.value);
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
type: 'jsx',
|
type: 'jsx',
|
||||||
value:
|
value:
|
||||||
`<Tabs defaultValue="npm" ` +
|
`<Tabs defaultValue="npm" ${groupIdProp}` +
|
||||||
`values={[
|
`values={[
|
||||||
{ label: 'npm', value: 'npm', },
|
{ label: 'npm', value: 'npm', },
|
||||||
{ label: 'Yarn', value: 'yarn', },
|
{ label: 'Yarn', value: 'yarn', },
|
||||||
|
@ -53,12 +54,13 @@ const nodeForImport = {
|
||||||
"import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';",
|
"import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = (options = {}) => {
|
||||||
|
const {sync = false} = options;
|
||||||
let transformed = false;
|
let transformed = false;
|
||||||
const transformer = (node) => {
|
const transformer = (node) => {
|
||||||
if (matchNode(node)) {
|
if (matchNode(node)) {
|
||||||
transformed = true;
|
transformed = true;
|
||||||
return transformNode(node);
|
return transformNode(node, sync);
|
||||||
}
|
}
|
||||||
if (Array.isArray(node.children)) {
|
if (Array.isArray(node.children)) {
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
|
@ -194,7 +194,9 @@ module.exports = {
|
||||||
'https://github.com/facebook/docusaurus/edit/master/website/',
|
'https://github.com/facebook/docusaurus/edit/master/website/',
|
||||||
showLastUpdateAuthor: true,
|
showLastUpdateAuthor: true,
|
||||||
showLastUpdateTime: true,
|
showLastUpdateTime: true,
|
||||||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')],
|
remarkPlugins: [
|
||||||
|
[require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}],
|
||||||
|
],
|
||||||
disableVersioning: isVersioningDisabled,
|
disableVersioning: isVersioningDisabled,
|
||||||
lastVersion: 'current',
|
lastVersion: 'current',
|
||||||
onlyIncludeVersions:
|
onlyIncludeVersions:
|
||||||
|
|
Loading…
Add table
Reference in a new issue