diff options
Diffstat (limited to 'packages/gitbook-core/src/components')
-rw-r--r-- | packages/gitbook-core/src/components/Image.js | 37 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/InjectedComponent.js | 2 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/Link.js | 9 |
3 files changed, 47 insertions, 1 deletions
diff --git a/packages/gitbook-core/src/components/Image.js b/packages/gitbook-core/src/components/Image.js new file mode 100644 index 0000000..802d66a --- /dev/null +++ b/packages/gitbook-core/src/components/Image.js @@ -0,0 +1,37 @@ +const React = require('react'); +const ReactRedux = require('react-redux'); + +const File = require('../models/File'); +const FileShape = require('../propTypes/File'); + +/** + * Local image. Using this component instead of <img> + * avoid broken links when location changes. + * + * @type {ReactClass} + */ +const Image = React.createClass({ + propTypes: { + currentFile: FileShape, + src: React.PropTypes.oneOfType([ + React.PropTypes.string, + FileShape + ]) + }, + + render() { + let { src, currentFile, ...props } = this.props; + delete props.dispatch; + + if (File.is(src)) { + src = src.url; + } + + src = currentFile.relative(src); + return <img src={src} {...props} />; + } +}); + +module.exports = ReactRedux.connect((state) => { + return { currentFile: state.file }; +})(Image); diff --git a/packages/gitbook-core/src/components/InjectedComponent.js b/packages/gitbook-core/src/components/InjectedComponent.js index 097edaf..d237cd0 100644 --- a/packages/gitbook-core/src/components/InjectedComponent.js +++ b/packages/gitbook-core/src/components/InjectedComponent.js @@ -53,6 +53,8 @@ const InjectedComponentSet = React.createClass({ render() { const { components, props, children, ...divProps } = this.props; + delete divProps.matching; + delete divProps.dispatch; const inner = components.map((Comp, i) => <Injection key={i} component={Comp} props={props} />); diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js index ab364bb..9827f0b 100644 --- a/packages/gitbook-core/src/components/Link.js +++ b/packages/gitbook-core/src/components/Link.js @@ -6,6 +6,12 @@ const SummaryArticle = require('../models/SummaryArticle'); const SummaryArticleShape = require('../propTypes/SummaryArticle'); const FileShape = require('../propTypes/File'); +/** + * Link to another page or file in the book. Using this component instead of <a> + * avoid broken links when location changes. + * + * @type {ReactClass} + */ const Link = React.createClass({ propTypes: { currentFile: FileShape, @@ -22,6 +28,7 @@ const Link = React.createClass({ render() { const { currentFile, to, children, ...props } = this.props; let href = to; + delete props.dispatch; if (SummaryArticle.is(to) || File.is(to)) { href = to.url; @@ -32,6 +39,6 @@ const Link = React.createClass({ } }); -module.exports = ReactRedux.connect(state => { +module.exports = ReactRedux.connect((state) => { return { currentFile: state.file }; })(Link); |