diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-10-09 16:52:22 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-10-09 16:52:27 +0200 |
commit | 417013a230dbf19c2e9abaf73d08fe3045024a10 (patch) | |
tree | 93ec66d2ca90daa965f61d2db41882913e99333e | |
parent | 5a57a2c62ad67210143bfe5dd96dd1605b3724f6 (diff) | |
download | gitbook-417013a230dbf19c2e9abaf73d08fe3045024a10.zip gitbook-417013a230dbf19c2e9abaf73d08fe3045024a10.tar.gz gitbook-417013a230dbf19c2e9abaf73d08fe3045024a10.tar.bz2 |
Resolve assets and lunr index before loading
-rw-r--r-- | packages/gitbook-core/src/models/File.js | 2 | ||||
-rw-r--r-- | packages/gitbook-plugin-lunr/src/actions.js | 8 | ||||
-rw-r--r-- | packages/gitbook/src/browser/render.js | 10 |
3 files changed, 14 insertions, 6 deletions
diff --git a/packages/gitbook-core/src/models/File.js b/packages/gitbook-core/src/models/File.js index 3ec6130..74db11e 100644 --- a/packages/gitbook-core/src/models/File.js +++ b/packages/gitbook-core/src/models/File.js @@ -29,7 +29,7 @@ class File extends Record(DEFAULTS) { return path.relative( path.dirname(this.path), to - ); + ) || './'; } /** diff --git a/packages/gitbook-plugin-lunr/src/actions.js b/packages/gitbook-plugin-lunr/src/actions.js index 4d878c7..765fa2e 100644 --- a/packages/gitbook-plugin-lunr/src/actions.js +++ b/packages/gitbook-plugin-lunr/src/actions.js @@ -3,6 +3,7 @@ const GitBook = require('gitbook-core'); const TYPES = { LOAD: 'lunr/load' }; +const INDEX_FILENAME = 'search_index.json'; /** * Load an index set @@ -19,7 +20,9 @@ function load(json) { */ function fetch() { return (dispatch, getState) => { - const { idx } = getState().lunr; + const { lunr, file } = getState(); + const { idx } = lunr; + const filePath = file.relative(INDEX_FILENAME); if (idx) { return GitBook.Promise.resolve(); @@ -27,8 +30,7 @@ function fetch() { return GitBook.Promise.resolve() .then(() => { - // TODO: resolve the file correctly - return window.fetch('search_index.json'); + return window.fetch(filePath); }) .then(response => response.json()) .then(json => dispatch(load(json))); diff --git a/packages/gitbook/src/browser/render.js b/packages/gitbook/src/browser/render.js index d5062c6..15e60ab 100644 --- a/packages/gitbook/src/browser/render.js +++ b/packages/gitbook/src/browser/render.js @@ -59,9 +59,13 @@ function render(plugins, initialState, type, role) { const payload = JSON.stringify(initialState); const context = GitBook.createContext(browserPlugins, initialState); + const currentFile = context.getState().file; + const scripts = plugins.toList() .filter(plugin => plugin.getPackage().has(type)) - .map(plugin => 'gitbook/plugins/' + plugin.getName() + '.js') + .map(plugin => { + return currentFile.relative('gitbook/plugins/' + plugin.getName() + '.js'); + }) .toArray(); const el = GitBook.renderWithContext(context, { role }); @@ -81,7 +85,9 @@ function render(plugins, initialState, type, role) { innerHTML={innerHTML} payload={payload} bootstrap={getBootstrapCode(role)} - scripts={['gitbook/core.js'].concat(scripts)} + scripts={[ + currentFile.relative('gitbook/core.js') + ].concat(scripts)} />; const html = ReactDOMServer.renderToStaticMarkup(htmlEl); |