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: auto generate sidebar from header #226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,20 @@ const store = new Vuex.Store({
: []
},

sidebar(_, {config}) {
sidebar(state, {config}) {
const sidebar = config.sidebar || []
if (sidebar === 'auto') {
return [
{
children: [
{
title: state.page && state.page.title,
link: state.route && state.route.path
}
]
}
]
}
return typeof sidebar === 'function' ? sidebar(store) : sidebar
},

Expand Down
8 changes: 8 additions & 0 deletions website/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ interface SidebarItemLink {
}
```

- If you want to automatically generate a sidebar from nav header, set sidebar to auto mode

```javascript
{
sidebar: 'auto'
}
```

## sourcePath

- Type: `string`
Expand Down
8 changes: 8 additions & 0 deletions website/docs/zh/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ interface ItemLink {
}
```

- 如果要从导航标题自动生成侧边栏,请将侧边栏设置为自动模式

```javascript
{
sidebar: 'auto'
}
```

## sourcePath

- 类型:`string`
Expand Down