vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.17k stars 923 forks source link

[Feature request] SidebarConfigObject should have a fallback option #1321

Closed wxsms closed 1 year ago

wxsms commented 1 year ago

Clear and concise description of the problem

we can use sidebar object to define sidebar for different pages, like:

export default {
  theme: defaultTheme({
    // 侧边栏对象
    // 不同子路径下的页面会使用不同的侧边栏
    sidebar: {
      '/guide/': [
        {
          text: 'Guide',
          children: ['/guide/README.md', '/guide/getting-started.md'],
        },
      ],
      '/reference/': [
        {
          text: 'Reference',
          children: ['/reference/cli.md', '/reference/config.md'],
        },
      ],
    },
  }),
}

but if we only want some of these routes to use special sidebar, others keep auto, I have to add auto to every other pages in frontmatter, because there're no fallback.

Suggested solution

export default {
  theme: defaultTheme({
    // 侧边栏对象
    // 不同子路径下的页面会使用不同的侧边栏
    sidebar: {
      '/guide/': [
        {
          text: 'Guide',
          children: ['/guide/README.md', '/guide/getting-started.md'],
        },
      ],
      '/reference/': [
        {
          text: 'Reference',
          children: ['/reference/cli.md', '/reference/config.md'],
        },
      ],
     '*': 'auto'
    },
  }),
}

Alternative

No response

Additional context

No response

Mister-Hope commented 1 year ago

'/' is fallback

wxsms commented 1 year ago

'/' is fallback

But looks like we can not use '/': 'auto' syntax, The signature of SidebarConfigObject not allow so.

anyway I close this because I finally found out that it's not very important to my project. but it may still be a problem for others.