diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-25 19:05:35 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-25 19:05:35 +0200 |
commit | 7fa3e34f9fe433ee99f797c745ef0f54b5efd89a (patch) | |
tree | 4bbc39a59c853347cd5b68ec52544347cc11a408 /packages/gitbook-core | |
parent | e46cd78f803891dfc8c304ea8ec4bc813ad16b5b (diff) | |
download | gitbook-7fa3e34f9fe433ee99f797c745ef0f54b5efd89a.zip gitbook-7fa3e34f9fe433ee99f797c745ef0f54b5efd89a.tar.gz gitbook-7fa3e34f9fe433ee99f797c745ef0f54b5efd89a.tar.bz2 |
Mark article as active in summary
Diffstat (limited to 'packages/gitbook-core')
-rw-r--r-- | packages/gitbook-core/src/actions/navigation.js | 14 | ||||
-rw-r--r-- | packages/gitbook-core/src/components/Link.js | 38 | ||||
-rw-r--r-- | packages/gitbook-core/src/index.js | 2 |
3 files changed, 53 insertions, 1 deletions
diff --git a/packages/gitbook-core/src/actions/navigation.js b/packages/gitbook-core/src/actions/navigation.js index a467d23..0d00687 100644 --- a/packages/gitbook-core/src/actions/navigation.js +++ b/packages/gitbook-core/src/actions/navigation.js @@ -2,6 +2,8 @@ /** * Fetch a new page and update the store accordingly + * @param {String} uri + * @return {Action} action */ function fetchPage(uri) { return (dispatch, getState) => { @@ -9,6 +11,16 @@ function fetchPage(uri) { }; } +/** + * Fetch a new article + * @param {SummaryArticle} article + * @return {Action} action + */ +function fetchArticle(article) { + return fetchPage(article.path); +} + module.exports = { - fetchPage + fetchPage, + fetchArticle }; diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js new file mode 100644 index 0000000..2f909de --- /dev/null +++ b/packages/gitbook-core/src/components/Link.js @@ -0,0 +1,38 @@ +const React = require('react'); +const SummaryArticleShape = require('../shapes/SummaryArticle'); + +const Link = React.createClass({ + propTypes: { + children: React.PropTypes.node, + href: React.PropTypes.string, + to: React.PropTypes.oneOfType([ + React.PropTypes.string, + SummaryArticleShape + ]) + }, + + getHref() { + const { to, href } = this.props; + + if (href) { + return href; + } + + if (typeof to === 'string') { + return to; + } + + if (typeof to.ref === 'string') { + // TODO: normalize url + return to.ref; + } + }, + + render() { + const { children, ...props } = this.props; + const href = this.getHref(); + return <a href={href} {...props}>{children}</a>; + } +}); + +module.exports = Link; diff --git a/packages/gitbook-core/src/index.js b/packages/gitbook-core/src/index.js index 0a5d8c5..f002d9e 100644 --- a/packages/gitbook-core/src/index.js +++ b/packages/gitbook-core/src/index.js @@ -5,6 +5,7 @@ const { Flex, Box } = require('reflexbox'); const { InjectedComponent, InjectedComponentSet } = require('./components/InjectedComponent'); const { ImportLink, ImportScript, ImportCSS } = require('./components/Import'); const HTMLContent = require('./components/HTMLContent'); +const Link = require('./components/Link'); const { registerComponent } = require('./actions/components'); const ACTIONS = require('./actions/TYPES'); @@ -39,6 +40,7 @@ module.exports = { ImportCSS, FlexLayout: Flex, FlexBox: Box, + Link, // Utilities Shapes }; |