diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-26 18:45:12 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-26 18:45:12 +0200 |
commit | 51f4cd6dae0511d77bea71c6abf94c86aacdf67f (patch) | |
tree | cb26b070b03e7faf56097aa2ef35f9491b8d19aa /packages/gitbook-core/src | |
parent | 64ce8bcf4277d450b5d4c63ac92df35cf4c5af10 (diff) | |
download | gitbook-51f4cd6dae0511d77bea71c6abf94c86aacdf67f.zip gitbook-51f4cd6dae0511d77bea71c6abf94c86aacdf67f.tar.gz gitbook-51f4cd6dae0511d77bea71c6abf94c86aacdf67f.tar.bz2 |
Fix link and navigation click
Diffstat (limited to 'packages/gitbook-core/src')
-rw-r--r-- | packages/gitbook-core/src/actions/navigation.js | 2 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/Link.js | 10 | ||||
-rw-r--r-- | packages/gitbook-core/src/reducers/page.js | 15 |
3 files changed, 18 insertions, 9 deletions
diff --git a/packages/gitbook-core/src/actions/navigation.js b/packages/gitbook-core/src/actions/navigation.js index af0fdff..60be593 100644 --- a/packages/gitbook-core/src/actions/navigation.js +++ b/packages/gitbook-core/src/actions/navigation.js @@ -71,7 +71,7 @@ function redirect(uri) { * @param {Boolean} options.replace * @return {Action} action */ -function fetchPage(uri, options) { +function fetchPage(uri, options = {}) { const { replace } = options; return (dispatch, getState) => { diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js index ade7461..83ecdd5 100644 --- a/packages/gitbook-core/src/components/Link.js +++ b/packages/gitbook-core/src/components/Link.js @@ -1,5 +1,7 @@ const React = require('react'); const ReactRedux = require('react-redux'); +const path = require('path'); +const url = require('url'); const SummaryArticleShape = require('../shapes/SummaryArticle'); const Link = React.createClass({ @@ -23,9 +25,13 @@ const Link = React.createClass({ return to; } + // Article if (typeof to.ref === 'string') { - // TODO: normalize url - return to.ref; + const parts = url.parse(to.ref); + const ext = path.extname(parts.pathname); + const pathname = path.basename(parts.pathname, ext) + '.html'; + + return pathname + (parts.hash || ''); } }, diff --git a/packages/gitbook-core/src/reducers/page.js b/packages/gitbook-core/src/reducers/page.js index 275fce7..2d8c943 100644 --- a/packages/gitbook-core/src/reducers/page.js +++ b/packages/gitbook-core/src/reducers/page.js @@ -2,17 +2,20 @@ const { Record } = require('immutable'); const ACTION_TYPES = require('../actions/TYPES'); const DEFAULTS = { - title: '', - content: '', - dir: 'ltr', - depth: 1, - level: '' + title: '', + content: '', + dir: 'ltr', + depth: 1, + level: '', + previous: null }; class PageState extends Record(DEFAULTS) { static create(state) { return state instanceof PageState ? - state : new PageState(state); + state : new PageState({ + ...state + }); } } |