Skip to content
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

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

Merged
Prev Previous commit
Next Next commit
Add code comments for explicit file changes
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
@@ -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;
23 changes: 23 additions & 0 deletions src/core/router/util.js
Original file line number Diff line number Diff line change
@@ -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('/')