ozum / vuepress-bar

VuePress sidebar and navbar generator based on file and directory structure. Focus your documents, not sidebar or navbar.
90 stars 40 forks source link

Sidebar is not defined #31

Closed chris-dnv closed 3 years ago

chris-dnv commented 3 years ago

I'm trying to add the sidebar filter as per the Readme however on the build i get ReferenceError: sidebar is not defined. Could you help please?

Themeconfig in config.js

image

ozum commented 3 years ago

It's a JavaScript error. You didn't define the sidebar variable anywhere. First define the variable.

Please see the example below. Actually, it is the same example in README, but I added comments.

// Here we define sidebar variable.
const { nav, sidebar } = getConfig();

module.exports = {
  themeConfig: {
    nav,

    // Here we can use the sidebar variable defined above.
    sidebar: sidebar.filter((i) => i.title !== "Node Modules"),
  }
};
chris-dnv commented 3 years ago

Thank you Ozum this was indeed the initial issue,

However no matter what title i try to filter i get the following error on build :

TypeError: Cannot read property 'filter' of undefined

themeConfig:{ ...getConfig(${__dirname}/..`), logo: "/logo.png", nav: [ { text: 'Home', link: '/' }, { text: 'VoA2.0', link: '/01.VoA 2.0 Design/' }, { text: 'VoA China', link: '/02.VoA China Design/' }, ], sidebar: sidebar.filter((i) => i.title !== "VoA China Design"), },plugins: [

image

ozum commented 3 years ago

This problem seems again related to JS. First, try console.log(sidebar) or other debugging methods to see what is the content of the sidebar variable.