docsifyjs / docsify

🃏 A magical documentation site generator.
https://docsify.js.org
MIT License
27.63k stars 5.67k forks source link

404 error with a different http server for sidebar files #1713

Open CxRes opened 2 years ago

CxRes commented 2 years ago

Bug Report

I am using a different server than the one provided by docsify-cli (http-server) because of docsifyjs/docsify-cli#32. I find that the server keeps complaining about missing sidebar file for each route even though I have set a global sidebar file. Like so:

 "GET foo/docs/bar/_sidebar.md" Error (404): "Not found"

The pages however work fine with the global sidebar loaded.

Steps to reproduce

Configurations that I have tried:

  1. Original Files are in /foo/docs Homepage is /foo/docs/bar/README.md I have a static sidebar at /foo/docs/_sidebar.md
window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '_sidebar.md',
     ...
}

1a.

window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '/_sidebar.md', //explicit slash
     ...
}

2.

window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
        '/.*/_sidebar.md': '/_sidebar.md', // alias as in docs
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '_sidebar.md',
     ...
}

3.

window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
        '/foo/docs/.*/_sidebar.md': '/foo/docs/_sidebar.md', // full alias which is probably incorrect
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '_sidebar.md',
     ...
}

In each of these cases, I get the 404 error.

What is current behaviour

There is an 404 error message for missing sidebar for each route, even when a global sidebar is defined.

What is the expected behaviour

There should be no error message! Docsify should not look for a local sidebar file.

Other relevant information

Please create a reproducible sandbox

Cannot do so, as I need to change how the page is served. Help appreciated.

kxh4892636 commented 2 years ago

where is your index.html? in /foo/docs/ or /foo/ if your index.html in /foo/ Configurations blow can work

window.$docsify = {
  name: "foo",
  alias: {
    "/bar/": "/",
  },
  basePath: "/docs/",
  loadSidebar: "_sidebar.md",
  homepage: "README.md",
  ...
}
CxRes commented 2 years ago

where is your index.html? in /foo/docs/ or /foo/ if your index.html in /foo/ Configurations blow can work

Sorry it was not clear but as I said above, files are in /oo/docs/ including index.html. The configuration works fine in that my page loads, except I get 404 error for missing sidebar for each and every route like for /foo/docs/bar/_sidebar.md or /foo/docs/baz/_sidebar.md. Docsify simply should not even be looking for these routes with loadSidebar specified as a file and exclusively look at /foo/docs/_sidebar.md for all routes. (that's why I classify this a bug)!

kxh4892636 commented 2 years ago

you can read https://docsify.js.org/#/more-pages?id=nested-sidebars. you configure

alias: {
    "/": "/bar/",
  },

when you look at /foo/docs/_sidebar.md, you will redirect /foo/docs/bar/_sidrbar.md, so you get 404 error. So delete it and modify homePage : "/bar/README.md". Configurations below can work

window.$docsify = {
  name: "foo",
  loadSidebar: "_sidebar.md",
  homepage: "/bar/README.md",
trusktr commented 2 years ago

If I understand correctly, you've specified a specific sidebar, so it should not try to find side bar files based on your current path. I believe this should be improved.

GregEisenberg commented 2 years ago

I believe I am running into this issue too. Using c4Builder which use docsify it is generating a docsify site with sidebar. The top level pages all work perfectly. But any page in a subdirectory gets 404 for the _sidebar.md file and there is 1 request made per level of nesting. These requests are all initiated from the docsify/lib/docsify.min.js code.

Not sure if there is some setting which c4Builder needs to set when call docsify or if I am just hitting this issue.

sy-records commented 2 years ago

Try setting alias

        alias: {
            '/.*/_sidebar.md': '/_sidebar.md'
        },
GregEisenberg commented 2 years ago

Thanks @sy-records for your FAST reply. I was able to set "alias": { '/.*/_sidebar.md': '/_sidebar.md' }, in the JSON object called window.$docsify in index.html and that does seem to solve the issue. However since I am using the c4Builder which calls docsify and generates the index.html I will have to figure out how to get this included by default.

Was I correct in adding to the window.$docsify object in index.html? Was there some other place to add it?

Thanks again!

phoenixweiss commented 2 years ago

@sy-records Thanks!

QPod0 commented 8 months ago

@sy-records Could you please take a few minutes to see why this sidebar is not loading cased by a 404 error of _sidebar.md?

I've tried both GitHub Actions and Deploy from a branch.

sy-records commented 8 months ago

@QPod0 No GitHub Actions is required, no Jekyll theme needs to be set, just open the page, select the corresponding branch and directory.

image

QPod0 commented 8 months ago

Thanks @sy-records ! It now works well.