Skip to content

Commit 56cbb5f

Browse files
committed
feat: support "themeConfig.sidebar: 'auto'" (close: #552)
1 parent 84f3a09 commit 56cbb5f

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

docs/default-theme-config/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,30 @@ sidebar: auto
250250
---
251251
```
252252

253+
You can also enable it in all pages by using config:
254+
255+
``` js
256+
// .vuepress/config.js
257+
module.exports = {
258+
themeConfig: {
259+
sidebar: 'auto'
260+
}
261+
}
262+
```
263+
264+
In [multi-language](../guide/i18n.md) mode, you can also apply it to a specific locale:
265+
266+
``` js
267+
// .vuepress/config.js
268+
module.exports = {
269+
themeConfig: {
270+
'/': {
271+
sidebar: 'auto'
272+
}
273+
}
274+
}
275+
```
276+
253277
### Disabling the Sidebar
254278

255279
You can disable the sidebar on a specific page with `YAML front matter`:

docs/zh/default-theme-config/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,30 @@ sidebar: auto
247247
---
248248
```
249249

250+
你也可以通过配置来在所有页面中启用它:
251+
252+
``` js
253+
// .vuepress/config.js
254+
module.exports = {
255+
themeConfig: {
256+
sidebar: 'auto'
257+
}
258+
}
259+
```
260+
261+
[多语言](../guide/i18n.md) 模式下, 你也可以将其应用到某一特定的语言下:
262+
263+
``` js
264+
// .vuepress/config.js
265+
module.exports = {
266+
themeConfig: {
267+
'/zh/': {
268+
sidebar: 'auto'
269+
}
270+
}
271+
}
272+
```
273+
250274
### 禁用侧边栏
251275

252276
你可以通过 `YAML front matter` 来禁用指定页面的侧边栏:

lib/default-theme/util.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ function resolvePath (relative, base, append) {
109109
}
110110

111111
export function resolveSidebarItems (page, route, site, localePath) {
112-
const pageSidebarConfig = page.frontmatter.sidebar
113-
if (pageSidebarConfig === 'auto') {
114-
return resolveHeaders(page)
115-
}
116112
const { pages, themeConfig } = site
117113

118114
const localeConfig = localePath && themeConfig.locales
119115
? themeConfig.locales[localePath] || themeConfig
120116
: themeConfig
121117

118+
const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar
119+
if (pageSidebarConfig === 'auto') {
120+
return resolveHeaders(page)
121+
}
122+
122123
const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
123124
if (!sidebarConfig) {
124125
return []

0 commit comments

Comments
 (0)