Skip to content

Commit 1f3ae01

Browse files
committed
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
1 parent 0ef6aa8 commit 1f3ae01

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/core/router/history/hash.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export class HashHistory extends History {
1818
const path = window.location.pathname || '';
1919
const base = this.config.basePath;
2020

21-
return /^(\/|https?:)/g.test(base) ? base : cleanPath(path + '/' + base);
21+
const basePath = path.endsWith('.html')
22+
? path + '#/' + base
23+
: path + '/' + base;
24+
return /^(\/|https?:)/g.test(base) ? base : cleanPath(basePath);
2225
}
2326

2427
getCurrentPath() {

src/core/router/util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,15 @@ export const resolvePath = cached(path => {
7676
return '/' + resolved.join('/');
7777
});
7878

79+
function normaliseFragment(path) {
80+
return path
81+
.split('/')
82+
.filter(p => !p.includes('#'))
83+
.join('/');
84+
}
85+
7986
export function getPath(...args) {
80-
return cleanPath(args.join('/'));
87+
return cleanPath(args.map(normaliseFragment).join('/'));
8188
}
8289

8390
export const replaceSlug = cached(path => {

0 commit comments

Comments
 (0)