Skip to content

Commit

Permalink
Fix: Cannot serve off /.../index.html
Browse files Browse the repository at this point in the history
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:

docsifyjs#427
  • Loading branch information
rgladwell committed Oct 16, 2020
1 parent 1863d8e commit 939e23b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/router/history/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 8 additions & 1 deletion src/core/router/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 939e23b

Please sign in to comment.