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
Next Next commit
Fix: Cannot serve off /.../index.html
Docsify must be hosted on a server that supports a default directory
index (i.e. maps `/.../` -> `/.../index.html`).

Some platforms do not support this, however. For example, HTML apps
hosted on the popular game/software platform, Itch.io.

This change supports hosting Docsify off an explicit path file, such as
`/index.html`. It does this by:

 1. Adding handling for paths like `index.html#/blah`, and
 2. Normalising paths with fragments back to markdown paths

For example, `http://example.org/index.html#/blah` would be mapped to
`http://example.org/blah.md`.

This fixes:

#427
rgladwell committed Oct 16, 2020
commit 939e23b3bffae396c3329e475f5264c397ce4449
5 changes: 4 additions & 1 deletion src/core/router/history/hash.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,10 @@ export class HashHistory extends History {
const path = window.location.pathname || '';
const base = this.config.basePath;

return /^(\/|https?:)/g.test(base) ? base : cleanPath(path + '/' + base);
const basePath = path.endsWith('.html')
? path + '#/' + base
: path + '/' + base;
return /^(\/|https?:)/g.test(base) ? base : cleanPath(basePath);
}

getCurrentPath() {
9 changes: 8 additions & 1 deletion src/core/router/util.js
Original file line number Diff line number Diff line change
@@ -76,8 +76,15 @@ export const resolvePath = cached(path => {
return '/' + resolved.join('/');
});

function normaliseFragment(path) {
return path
.split('/')
.filter(p => !p.includes('#'))
.join('/');
}

export function getPath(...args) {
return cleanPath(args.join('/'));
return cleanPath(args.map(normaliseFragment).join('/'));
}

export const replaceSlug = cached(path => {