rspress icon indicating copy to clipboard operation
rspress copied to clipboard

[Bug]: Unreliable behavour of slashes `\` in sidebar configuration for page paths

Open antonio-ivanovski opened this issue 1 year ago • 2 comments

Version

System:
    OS: macOS 14.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 1.12 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 122.0.6261.111
    Safari: 17.3.1
  npmPackages:
    rspress: ^1.0.0 => 1.13.2

Details

I have a sidebar configuration in the rspress.config.ts file. My content structure makes more sense to be configured this way instead of _meta.json. Following the sidebar configuration from the docs, I have the following config (also available in the reproduce link)


// Folder structure (from the starter template)
// docs 
//   guide
//     index.md
//   hello.md

themeConfig: {
    sidebar: {
      '/': [
        { text: "Markdown & MDX", link: '/guide'},
        { text: "Hello", link: '/hello'},
      ]
    },

I am hosting this in GitHub Pages at this link: https://toteto.github.io/test-rspress/

When I navigate to https://toteto.github.io/test-rspress/guide/ my expectations is to get the guide/index.md page with the sidebar on the side with both the Markdown & MDX and Hello items. However the case is that the sidebar is not being shown.

image

In order to get it working, i need to navigate to https://toteto.github.io/test-rspress/guide.html

Another way to get it working is to change the link to include a slash at the end

-{ text: "Markdown & MDX", link: '/guide'},
+{ text: "Markdown & MDX", link: '/guide/'},

Or to have the full path

-{ text: "Markdown & MDX", link: '/guide'},
+{ text: "Markdown & MDX", link: '/guide/index.html'},

To me it looks like it is some sidebar matching issues in the render logic for the sidebar

Reproduce link

https://github.com/toteto/test-rspress/tree/gh-pages

Reproduce Steps

  1. Create sidebar config with items as described in the config
  2. Navigate to the site or deploy it to GitHub pages
  3. The sidebar is not shown

antonio-ivanovski avatar Mar 07 '24 20:03 antonio-ivanovski

Take the ending slash or not has different means: /guide -> /guide.md(x) /guide/ -> /guide/index.md(x)

sanyuan0704 avatar Mar 08 '24 00:03 sanyuan0704

Take the ending slash or not has different means: /guide -> /guide.md(x) /guide/ -> /guide/index.md(x)

Why is this the case? Personally think that it is easier to configure and think about the configuration if /guide and /guide/ pointed to the same thing where there is no conflicting files,

For example if there is guide.md and guide/index.md, maybe it should have the distinction, but in cases where there is just one, it just creates case for confusion.

Also maybe this case should be documented in the API for sidebar?

antonio-ivanovski avatar Mar 08 '24 09:03 antonio-ivanovski