vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.29k stars 2.15k forks source link

Sidebar's base need extends parent's base #4114

Open Wetoria opened 3 months ago

Wetoria commented 3 months ago

Is your feature request related to a problem? Please describe.

Example like below config of sidebar.

{
  "sidebar": {
    "/zh-Hans/reference/": {
      "base": "/zh-Hans/reference/",
      "items": [
        {
          "text": "社区集市",
          "link": "/",
          "base": "/zh-Hans/reference/bazaar",
          "items": [
            {
              "text": "图标 icon",
              "link": "/icon"
            },
            {
              "text": "插件 plugin",
              "link": "/plugin"
            }
          ]
        },
        {
          "text": "插件 API",
          "link": "/",
          "base": "/zh-Hans/reference/api/plugin",
          "items": [
            {
              "text": "事件总线",
              "link": "/event-bus/"
            },
            {
              "text": "类",
              "base": "/class",
              "items": [
                {
                  "text": "Plugin",
                  "link": "/Plugin"
                },
                {
                  "text": "Dialog",
                  "link": "/zh-Hans/reference/api/plugin/class/Dialog"
                }
              ]
            }
          ]
        }
      ]
    }
  }
}

When I set a base value of parent, the child node can jump correct. like icon and plugin in /zh-Hans/reference/bazaar.

But when I use extends value of base, I can not jump to the correct page. like plugin in class.

In order to fix this problem, I need to change /class into /zh-Hans/reference/api/plugin/class.

Fine, I can jump to the page plugin of class correctly.

But it is a terrible thing to write path multi times. In this example, means the part of zh-Hans, reference, api.

This problem can not fix with relative path. When I use ./ or ../ will lead a new problem.

If I am in event-bus now, use relative ./class will check with /zh-Hans/reference/api/plugin/event-bus. Click plugin will get /zh-Hans/reference/api/plugin/event-but/class/plugin.

Describe the solution you'd like

I think base value should extends of parent. Which means the result of "base": "/class" should be added the parent's base or link, like /zh-Hans/reference/api/plugin/class.

Maybe just append the base or link in sidebar.ts#L111 can implement this feature.

Describe alternatives you've considered

No response

Additional context

No response

Validations

brc-dd commented 3 months ago

This was discussed earlier, but it leaves no feasible way to remove parent's base. For example, how would you do this then:

https://github.com/vuejs/vitepress/blob/df27e44db668f2eddbf9d350e5dae4e042fe1250/docs/.vitepress/config/en.ts#L104

image

the last link in above image doesn't share the same base as rest of the group.

Wetoria commented 3 months ago

This was discussed earlier, but it leaves no feasible way to remove parent's base. For example, how would you do this then:

https://github.com/vuejs/vitepress/blob/df27e44db668f2eddbf9d350e5dae4e042fe1250/docs/.vitepress/config/en.ts#L104

image

the last link in above image doesn't share the same base as rest of the group.

I'm not sure about all logics. Maybe we can use a path starts without slash? Just like the mode of base + link.

In above example, change './class' to 'class' should be append parent's base?

I notice someway will check http: or https:, so I'm not sure about other problems, If will lead, plz let me know. tks a lot.

Wetoria commented 3 months ago

After my attempts, I found that it is possible to create a soft link in the guide directory by the way of soft link, and it can also jump to the corresponding page