사이드바 아이템
We have introduced three types of item types in the example in the previous section: doc
, category
, and link
, whose usages are fairly intuitive. 우리는 공식 API를 통해 지원할 겁니다. There's also a fourth type: autogenerated
, which we will explain in detail later.
- Doc: link to a doc page, associating it with the sidebar
- Link: link to any internal or external page
- Category: creates a dropdown of sidebar items
- Autogenerated: generate a sidebar slice automatically
- HTML: renders pure HTML in the item's position
- *Ref: link to a doc page, without making the item take part in navigation generation
Doc: link to a doc
Use the doc
type to link to a doc page and assign that doc to a sidebar:
type SidebarItemDoc =
// Normal syntax
| {
type: 'doc';
id: string;
label: string; // Sidebar label text
className?: string; // Class name for sidebar label
customProps?: Record<string, unknown>; // Custom props
}
// Shorthand syntax
| string; // docId shortcut
예:
module.exports = {
mySidebar: [
// 일반 구문:
{
type: 'doc',
id: 'doc1', // 문서 id
label: 'Getting started', // 사이드바 라벨
},
// 단축 구문:
'doc2', // 문서 id
],
};
If you use the doc shorthand or 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.
A doc
item sets an implicit sidebar association. Don't assign the same doc to multiple sidebars: change the type to ref
instead.
사이드바 사용자 지정 속성은 임의의 문서 메타데이터를 클라이언트측에 전파하는 유용한 방법이므로 문서 오브젝트를 가져오는 문서 관련 후크를 사용할 때 추가적인 정보를 얻을 수 있습니다.
Link: link to any page
Use the link
type to link to any page (internal or external) that is not a doc.
type SidebarItemLink = {
type: 'link';
label: string;
href: string;
className?: string;
description?: string;
};
예:
module.exports = {
myLinksSidebar: [
// 외부 링크
{
type: 'link',
label: 'Facebook', // 링크 라벨
href: 'https://facebook.com', // 외부 URL
},
// 내부 링크
{
type: 'link',
label: 'Home', // 링크 라벨
href: '/', // 내부 경로
},
],
};
HTML: render custom markup
Use the html
type to render custom HTML within the item's <li>
tag.
구분선, 섹션 제목, 광고, 이미지 등과 같은 사용자 지정 항목을 삽입하는데 유용할 수 있습니다.
type SidebarItemHtml = {
type: 'html';
value: string;
defaultStyle?: boolean; // 기본 메뉴 아이템 스타일 사용
className?: string;
};
예:
module.exports = {
myHtmlSidebar: [
{
type: 'html',
value: '<img src="sponsor.png" alt="Sponsor" />', // The HTML to be rendered
defaultStyle: true, // Use the default menu item styling
},
],
};
The menu item is already wrapped in an <li>
tag, so if your custom item is simple, such as a title, just supply a string as the value and use the className
property to style it:
module.exports = {
myHtmlSidebar: [
{
type: 'html',
value: 'Core concepts',
className: 'sidebar-title',
},
],
};
Category: create a hierarchy
Use the category
type to create a hierarchy of sidebar items.
type SidebarItemCategory = {
type: 'category';
label: string; // Sidebar label text.
items: SidebarItem[]; // Array of sidebar items.
className?: string;
description?: string;
// Category options:
collapsible: boolean; // Set the category to be collapsible
collapsed: boolean; // Set the category to be initially collapsed or open by default
link: SidebarItemCategoryLinkDoc | SidebarItemCategoryLinkGeneratedIndex;
};
예:
module.exports = {
docs: [
{
type: 'category',
label: 'Guides',
collapsible: true,
collapsed: false,
items: [
'creating-pages',
{
type: 'category',
label: 'Docs',
items: ['introduction', 'sidebar', 'markdown-features', 'versioning'],
},
],
},
],
};
Use the shorthand syntax when you don't need customizations:
module.exports = {
docs: {
Guides: [
'creating-pages',
{
Docs: ['introduction', 'sidebar', 'markdown-features', 'versioning'],
},
],
},
};