vitepress-sidebar
vitepress-sidebar copied to clipboard
When rewrites are enabled, the plugin fails
When rewrites are enabled in the config.ts file, the sidebar is not automatically generated
// vitepress config.ts
import { defineConfig } from "vitepress";
import { generateSidebar } from "vitepress-sidebar";
export default defineConfig({
rewrites: {
"demo/test.md": "page/example.md",
},
themeConfig: {
nav: [
{ text: "dmeo", link: "/demo/test" },
{ text: "javascript", link: "/javascript/basic" },
],
sidebar: generateSidebar([
{
documentRootPath: "docs",
scanStartPath: "demo",
resolvePath: "/demo/",
},
{
documentRootPath: "docs",
scanStartPath: "javascript",
resolvePath: "/javascript/",
},
]),
},
});
ββ.vitepress
β β config.mts
β β
β ββtheme
β index.ts
β style.css
β
ββdemo
β test.md
β
ββjavascript
basic.md
When I click the demo button in nav, there is no sidebar on the left side of the page
- OS: [Windows 10]
- Browser [Chrome]
Hello, thank you for using VitePress Sidebar.
Could you please change the resolvePath in your settings to page, which is the URL after the rewrite, and see if the issue persists?
before:
generateSidebar([
{
documentRootPath: "docs",
scanStartPath: "demo",
resolvePath: "/demo/",
},
{
documentRootPath: "docs",
scanStartPath: "javascript",
resolvePath: "/javascript/",
},
])
after:
generateSidebar([
{
documentRootPath: "docs",
scanStartPath: "demo",
resolvePath: "/page/",
},
{
documentRootPath: "docs",
scanStartPath: "javascript",
resolvePath: "/javascript/",
},
])
Regards,
Still wrong. When rewrites are not enabled, Click this button to display the demo/index.md file, and the sidebar of the left side is jump to normal
On this basis, open rewrites. Add the following in the config.ts file
rewrites: {
"demo/test.md": "page/example.md",
},
Click the demo-index button to display the index.md file under the demo folder correctly. Click on the page button on the left to jump correctly to demo/page.html, and correctly display the content of the page.md file and the left side Sidebar. However, clicking the test button will jump to page/example.html. Although the content of the test.md file is correctly displayed, there is no sidebar on the left.
Click the demo-test button, the same is true.
According to the way you said, after modifying resolvepath to page, it is still wrong
Hi! First, well done for this plugin @jooy2. It's amazing!
I have a similar issue that could be related to this problem.
I defined a rewrites rule to rename files with same name as folder into index.md
rewrites: {
'^(?<rest>.*(?=\\/))?\\/?(?<dir>.+?)\\/\\2\\.md$': ':rest*/:dir/index.md',
},
It works well, but somehow mess with the Next/Prev links.
Here is a stackblitz that reproduces the problem: https://stackblitz.com/edit/vite-epbzzd?file=docs%2F.vitepress%2Fconfig.ts
What I noticed is everytime we get on an index file, navigation only propose the top-file of the sidebar as next link.
I thought it was the rewrites rules, but even if I apply page by page, it's still the same:
rewrites: {
'menu/menu.md': 'menu/index.md',
'menu/fruits/fruits.md': 'menu/fruits/index.md',
'menu/vegetables/vegetables.md': 'menu/vegetables/index.md',
},
Let me know if you need more infos!
Hello! Thank you for your patience. I recently released a version that addresses the original issue and additional issues you left in the comments.
Here's the solution to @ghost's case:
- Upgrade the version of
vitepress-sidebarto 1.25.0. - Modify the following options:
...
scanStartPath: 'demo',
resolvePath: '/page/',
basePath: '/demo/',
...
Specifying this option will satisfy the rewrite rule above, 'demo/test.md': 'page/example.md', to display the menu. However, this will display the menu, but the previous/next links will not be organized correctly.
To configure the previous/next links correctly, modify the rewrite option as follows:
rewrites: {
'demo/:page': 'page/:page'
},
And modify the vitepress-sidebar' options to:
...
scanStartPath: 'demo',
resolvePath: '/page/',
...
For more information, see the following articles: https://vitepress-sidebar.jooy2.com/advanced-usage/multiple-sidebars-how-to
And @satche's case has been fixed with the PR you sent me.
If the issue persists, please open a new issue and I'll move this issue to complete.
Thanks!