From 56cbb5f3eda7b7ef4994066a29bcee2566080329 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Fri, 8 Jun 2018 01:15:40 +0800 Subject: [PATCH] feat: support "themeConfig.sidebar: 'auto'" (close: #552) --- docs/default-theme-config/README.md | 24 ++++++++++++++++++++++++ docs/zh/default-theme-config/README.md | 24 ++++++++++++++++++++++++ lib/default-theme/util.js | 9 +++++---- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/docs/default-theme-config/README.md b/docs/default-theme-config/README.md index 304220dc0e..83c0715628 100644 --- a/docs/default-theme-config/README.md +++ b/docs/default-theme-config/README.md @@ -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`: diff --git a/docs/zh/default-theme-config/README.md b/docs/zh/default-theme-config/README.md index 5df6a954db..c28b4dc60a 100644 --- a/docs/zh/default-theme-config/README.md +++ b/docs/zh/default-theme-config/README.md @@ -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` 来禁用指定页面的侧边栏: diff --git a/lib/default-theme/util.js b/lib/default-theme/util.js index 22192591bb..581a690417 100644 --- a/lib/default-theme/util.js +++ b/lib/default-theme/util.js @@ -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 []