Skip to content

Commit

Permalink
feat: support "themeConfig.sidebar: 'auto'" (close: #552)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Jun 7, 2018
1 parent 84f3a09 commit 56cbb5f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
24 changes: 24 additions & 0 deletions docs/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@ sidebar: auto
---
```

You can also enable it in all pages by using config:

``` js
// .vuepress/config.js
module.exports = {
themeConfig: {
sidebar: 'auto'
}
}
```

In [multi-language](../guide/i18n.md) mode, you can also apply it to a specific locale:

``` js
// .vuepress/config.js
module.exports = {
themeConfig: {
'/': {
sidebar: 'auto'
}
}
}
```

### Disabling the Sidebar

You can disable the sidebar on a specific page with `YAML front matter`:
Expand Down
24 changes: 24 additions & 0 deletions docs/zh/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ sidebar: auto
---
```

你也可以通过配置来在所有页面中启用它:

``` js
// .vuepress/config.js
module.exports = {
themeConfig: {
sidebar: 'auto'
}
}
```

[多语言](../guide/i18n.md) 模式下, 你也可以将其应用到某一特定的语言下:

``` js
// .vuepress/config.js
module.exports = {
themeConfig: {
'/zh/': {
sidebar: 'auto'
}
}
}
```

### 禁用侧边栏

你可以通过 `YAML front matter` 来禁用指定页面的侧边栏:
Expand Down
9 changes: 5 additions & 4 deletions lib/default-theme/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,17 @@ function resolvePath (relative, base, append) {
}

export function resolveSidebarItems (page, route, site, localePath) {
const pageSidebarConfig = page.frontmatter.sidebar
if (pageSidebarConfig === 'auto') {
return resolveHeaders(page)
}
const { pages, themeConfig } = site

const localeConfig = localePath && themeConfig.locales
? themeConfig.locales[localePath] || themeConfig
: themeConfig

const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar
if (pageSidebarConfig === 'auto') {
return resolveHeaders(page)
}

const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
if (!sidebarConfig) {
return []
Expand Down

0 comments on commit 56cbb5f

Please sign in to comment.