mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-03 00:39:45 +02:00
docs: add link from every category index page to the guide page (#7665)
This commit is contained in:
parent
42ab07f62f
commit
8e3e89d9ff
4 changed files with 120 additions and 43 deletions
|
@ -60,7 +60,7 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
If you use the doc shorthand or [autogenerated](#sidebar-item-autogenerated) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page.
|
||||
If you use the doc shorthand or [autogenerated](#sidebar-item-autogenerated) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page.
|
||||
|
||||
:::note
|
||||
|
||||
|
@ -230,29 +230,10 @@ With category links, clicking on a category can navigate you to another page.
|
|||
|
||||
Use category links to introduce a category of documents.
|
||||
|
||||
Autogenerated categories can use the [`_category_.yml`](./autogenerated.md#category-item-metadata) file to declare the link.
|
||||
|
||||
:::
|
||||
|
||||
#### Doc link {#category-doc-link}
|
||||
|
||||
A category can link to an existing document.
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
docs: [
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Guides',
|
||||
// highlight-start
|
||||
link: {type: 'doc', id: 'introduction'},
|
||||
// highlight-end
|
||||
items: ['pages', 'docs', 'blog', 'search'],
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
See it in action on the [i18n introduction page](../../../i18n/i18n-introduction.md).
|
||||
|
||||
#### Generated index page {#generated-index-page}
|
||||
|
||||
You can auto-generate an index page that displays all the direct children of this category. The `slug` allows you to customize the generated page's route, which defaults to `/category/[categoryName]`.
|
||||
|
@ -287,6 +268,27 @@ Use `generated-index` links as a quick way to get an introductory document.
|
|||
|
||||
:::
|
||||
|
||||
#### Doc link {#category-doc-link}
|
||||
|
||||
A category can link to an existing document.
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
docs: [
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Guides',
|
||||
// highlight-start
|
||||
link: {type: 'doc', id: 'introduction'},
|
||||
// highlight-end
|
||||
items: ['pages', 'docs', 'blog', 'search'],
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
See it in action on the [i18n introduction page](../../../i18n/i18n-introduction.md).
|
||||
|
||||
#### Embedding generated index in doc page {#embedding-generated-index-in-doc-page}
|
||||
|
||||
You can embed the generated cards list in a normal doc page as well, as long as the doc is used as a category index page. To do so, you need to use the `DocCardList` component, paired with the `useCurrentSidebarCategory` hook.
|
||||
|
@ -404,8 +406,10 @@ You can express typical sidebar items without much customization more concisely
|
|||
|
||||
An item with type `doc` can be simply a string representing its ID:
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="Longhand">
|
||||
```
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
|
@ -420,8 +424,10 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="Shorthand">
|
||||
```
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
|
@ -433,8 +439,10 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
So it's possible to simplify the example above to:
|
||||
|
||||
|
@ -472,8 +480,10 @@ module.exports = {
|
|||
|
||||
A category item can be represented by an object whose key is its label, and the value is an array of subitems.
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="Longhand">
|
||||
```
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
|
@ -489,8 +499,10 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="Shorthand">
|
||||
```
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
|
@ -504,8 +516,10 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
This permits us to simplify that example to:
|
||||
|
||||
|
@ -553,8 +567,10 @@ Note how the two consecutive category shorthands are compressed into one object
|
|||
|
||||
Wherever you have an array of items that is reduced to one category shorthand, you can omit that enclosing array as well.
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="Before">
|
||||
```
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
|
@ -572,8 +588,10 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
<TabItem value="After">
|
||||
```
|
||||
|
||||
```js title="sidebars.js"
|
||||
module.exports = {
|
||||
|
@ -587,5 +605,7 @@ module.exports = {
|
|||
};
|
||||
```
|
||||
|
||||
```mdx-code-block
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue