jooy2 / vitepress-sidebar

🔌 VitePress Sidebar is a plugin for VitePress that automatically configures and manages the sidebar of your page with simple settings.
https://vitepress-sidebar.cdget.com
MIT License
168 stars 8 forks source link

Empty `options` fails to render sidebar #157

Closed dmohns closed 5 months ago

dmohns commented 5 months ago

Describe the bug

When calling generateSidebar with an empty options object the sidebar generation returns {}. Passing anything fixes the behaviour, see example below.

To Reproduce

console.log('Empty options');
console.log(generateSidebar({}));
console.log('(Essentially) Empty options');
console.log(generateSidebar({ debugPrint: false }));

Returns

Empty options
{}
(Essentially) Empty options
[
  { text: 'dev_docs', items: [ [Object], [Object], [Object] ] },
  { text: 'introduction', items: [ [Object], [Object], [Object] ] },
  {
    text: 'usage_guide',
    items: [ [Object], [Object], [Object], [Object] ]
  }
]

Expected behavior

When calling with empty options a rendered sidebar with default values should be returned. While (I think) this doesn't happen too often in a live environment, it might occur when users are exploring and playing around with the library.

Screenshots If applicable, add screenshots to help explain your problem.

N/A

Desktop (please complete the following information):

Additional context

I'm not very experienced with JavaScript. Maybe such a behaviour is totally normal and intuitive for JS users. If so, please ignore this bug report 😉

jooy2 commented 5 months ago

Hello, Thank you for using vitepress-sidebar.

Your comment is valid and makes a very good point. It seems that plugin need to handle empty objects or empty option values correctly.

So i have fixed that issue and it will be reflected in the next release.

Thanks!