Skip to content

fix: Cannot serve off /.../index.html #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Add code comments for explicit file changes
  • Loading branch information
rgladwell committed Oct 16, 2020
commit e42c3df8d94e89c5b3bcc53077c50a980d42ef04
5 changes: 5 additions & 0 deletions src/core/router/history/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class HashHistory extends History {
const path = window.location.pathname || '';
const base = this.config.basePath;

// This handles the case where Docsify is served off an
// explicit file path, i.e.`/base/index.html#/blah`. This
// prevents the `/index.html` part of the URI from being
// remove during routing.
// See here: https://github.com/docsifyjs/docsify/pull/1372
const basePath = path.endsWith('.html')
? path + '#/' + base
: path + '/' + base;
Expand Down
23 changes: 23 additions & 0 deletions src/core/router/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ export const resolvePath = cached(path => {
return '/' + resolved.join('/');
});

/**
* Normalises the URI path to handle the case where Docsify is
* hosted off explicit files, i.e. /index.html. This function
* eliminates any path segments that contain `#` fragments.
*
* This is used to map browser URIs to markdown file sources.
*
* For example:
*
* http://example.org/base/index.html#/blah
*
* would be mapped to:
*
* http://example.org/base/blah.md.
*
* See here for more information:
*
* https://github.com/docsifyjs/docsify/pull/1372
*
* @param {string} path The URI path to normalise
* @return {string} { path, query }
*/

function normaliseFragment(path) {
return path
.split('/')
Expand Down