summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/components/Link.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-core/src/components/Link.js')
-rw-r--r--packages/gitbook-core/src/components/Link.js42
1 files changed, 15 insertions, 27 deletions
diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js
index 8c142ea..f5b9753 100644
--- a/packages/gitbook-core/src/components/Link.js
+++ b/packages/gitbook-core/src/components/Link.js
@@ -4,43 +4,29 @@ const ReactRedux = require('react-redux');
const File = require('../models/File');
const SummaryArticle = require('../models/SummaryArticle');
const SummaryArticleShape = require('../shapes/SummaryArticle');
-const ContextShape = require('../shapes/Context');
+const FileShape = require('../shapes/File');
const Link = React.createClass({
propTypes: {
- children: React.PropTypes.node,
- href: React.PropTypes.string,
- to: React.PropTypes.oneOfType([
+ currentFile: FileShape,
+ children: React.PropTypes.node,
+
+ // Destination of the link
+ to: React.PropTypes.oneOfType([
React.PropTypes.string,
- SummaryArticleShape
+ SummaryArticleShape,
+ FileShape
])
},
- contextTypes: {
- gitbook: ContextShape.isRequired
- },
-
getHref() {
- const { gitbook } = this.context;
- let { to, href } = this.props;
-
- if (href) {
- return href;
- }
-
- if (SummaryArticle.is(to)) {
- return to.toURL(gitbook);
- }
-
- if (typeof to === 'string') {
- to = new File(to);
- }
+ let { currentFile, to } = this.props;
- if (File.is(to)) {
- return to.toURL(gitbook);
+ if (SummaryArticle.is(to) || File.is(to)) {
+ to = to.url;
}
- throw new Error('Invalid format for prop "to"');
+ return currentFile.relative(to);
},
render() {
@@ -50,4 +36,6 @@ const Link = React.createClass({
}
});
-module.exports = ReactRedux.connect()(Link);
+module.exports = ReactRedux.connect(state => {
+ return { currentFile: state.file };
+})(Link);