Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): provide doc sidebar_label through sidebars.js #4500

Merged
merged 14 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Available document ids=

return {
type: 'link',
label: sidebarLabel || title,
label: sidebarLabel || item.label || title,
href: permalink,
customProps: item.customProps,
};
Expand Down
8 changes: 7 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ function assertIsCategory(
function assertIsDoc(
item: Record<string, unknown>,
): asserts item is SidebarItemDoc {
assertItem(item, ['id', 'customProps']);
assertItem(item, ['id', 'label', 'customProps']);
if (typeof item.id !== 'string') {
throw new Error(
`Error loading ${JSON.stringify(item)}. "id" must be a string.`,
);
}

if (item.label && typeof item.label !== 'string') {
throw new Error(
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
);
}
}

function assertIsLink(
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type SidebarItemBase = {

export type SidebarItemDoc = SidebarItemBase & {
type: 'doc' | 'ref';
label?: string;
id: string;
};

Expand Down
4 changes: 3 additions & 1 deletion website/docs/guides/docs/sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type SidebarItemDoc =
| {
type: 'doc';
id: string;
label: string; // Sidebar label text
};
```

Expand All @@ -137,10 +138,11 @@ Example:
{
type: 'doc',
id: 'doc1', // string - document id
label: 'Getting started' // Sidebar label text
}
```

Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above:
The sidebar_label in the markdown frontformatter has a higher precedence over the label key in `SidebarItemDoc`. Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above:
samuelships marked this conversation as resolved.
Show resolved Hide resolved

```js
'doc1'; // string - document id
Expand Down
1 change: 0 additions & 1 deletion website/docs/i18n/i18n-crowdin.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
id: crowdin
title: i18n - Using Crowdin
sidebar_label: Using Crowdin
slug: /i18n/crowdin
---

Expand Down
1 change: 0 additions & 1 deletion website/docs/i18n/i18n-git.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
id: git
title: i18n - Using git
sidebar_label: Using Git
slug: /i18n/git
---

Expand Down
1 change: 0 additions & 1 deletion website/docs/i18n/i18n-introduction.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
id: introduction
title: i18n - Introduction
sidebar_label: Introduction
slug: /i18n/introduction
---

Expand Down
1 change: 0 additions & 1 deletion website/docs/i18n/i18n-tutorial.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
id: tutorial
title: i18n - Tutorial
sidebar_label: Tutorial
slug: /i18n/tutorial
---

Expand Down
24 changes: 20 additions & 4 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,26 @@ module.exports = {
type: 'category',
label: 'Internationalization',
items: [
'i18n/introduction',
'i18n/tutorial',
'i18n/git',
'i18n/crowdin',
{
type: 'doc',
id: 'i18n/introduction',
label: 'Introduction',
},
{
type: 'doc',
id: 'i18n/tutorial',
label: 'Tutorial',
},
{
type: 'doc',
id: 'i18n/git',
label: 'Using Git',
},
{
type: 'doc',
id: 'i18n/crowdin',
label: 'Using Crowdin',
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type SidebarItemDoc =
| {
type: 'doc';
id: string;
label: string; // Sidebar label text
};
```

Expand All @@ -137,10 +138,11 @@ Example:
{
type: 'doc',
id: 'doc1', // string - document id
label: 'Getting started' // Sidebar label text
}
```

Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above:
The sidebar_label in the markdown frontformatter has a higher precedence over the label key in `SidebarItemDoc`. Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above:
samuelships marked this conversation as resolved.
Show resolved Hide resolved

```js
'doc1'; // string - document id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type SidebarItemDoc =
| {
type: 'doc';
id: string;
label: string; // Sidebar label text
};
```

Expand All @@ -137,10 +138,11 @@ Example:
{
type: 'doc',
id: 'doc1', // string - document id
label: 'Getting started' // Sidebar label text
}
```

Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above:
The sidebar_label in the markdown frontformatter has a higher precedence over the label key in `SidebarItemDoc`. Using just the [Document ID](#document-id) is also valid, the following is equivalent to the above:
samuelships marked this conversation as resolved.
Show resolved Hide resolved

```js
'doc1'; // string - document id
Expand Down