web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.19k stars 108 forks source link

[Feature]: Inject context in sidebar generate to enable using css to control sidebar display #1158

Closed Timeless0911 closed 2 weeks ago

Timeless0911 commented 2 weeks ago

What problem does this feature solve?

In some huge scale sites, we may need to display different pages according to the switching of different modes, such as the react and vue modes of a tool library document.

At this time, clicking the mode switching button is expected to cause the sidebar content to change.

What does the proposed API look like?

It is hoped that context configuration will be supported in _meta.jaon, and by injecting data-context when generating the sidebar dom, users can control the display of sidebar via css when clicking the switch button, so as to achieve the purpose of controlling sidebar content display.

{
  {
    "type": "file",
    "name": "foo.react",
    "context": "react"
  },
  {
    "type": "file",
    "name": "foo.vue",
    "context": "vue"
  }
}
<div class=".rspress-sidebar-group">
  <div data-context="vue" />
  <div data-context="react" />
</div>

This solution is a less invasive solution to Rspress and may cause other experience issues, such as the feature of go to previous/next page