From 1d52fa777b91a35fedc17ccebe4974a0c06e34fe Mon Sep 17 00:00:00 2001 From: Soreine Date: Fri, 2 Dec 2016 14:29:28 +0100 Subject: [PATCH 1/5] Add gitbook4 dependencies --- package.json | 63 +++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 015f0e3..2f519d3 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,39 @@ { - "name": "gitbook-plugin-github", - "version": "2.0.0", - "description": "Display a link to your GitHub repo in your gitbook", - "main": "index.js", - "authors": [ - { - "name": "Michael Jackson" - }, - { - "name": "Samy Pessé", - "email": "samy@gitbook.com" - } - ], - "repository": { - "type": "git", - "url": "https://github.com/GitbookIO/plugin-github.git" + "name": "gitbook-plugin-github", + "version": "2.0.0", + "description": "Display a link to your GitHub repo in your gitbook", + "main": "index.js", + "authors": [ + { + "name": "Michael Jackson" }, - "license": "Apache-2.0", - "engines": { - "gitbook": ">=2.5.0" - }, - "gitbook": { - "properties": { - "url": { - "type": "string", - "required": true, - "title": "URL to your GitHub repository" - } - } + { + "name": "Samy Pessé", + "email": "samy@gitbook.com" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/GitbookIO/plugin-github.git" + }, + "license": "Apache-2.0", + "engines": { + "gitbook": ">=4.0.0-alpha.0" + }, + "gitbook": { + "properties": { + "url": { + "type": "string", + "required": true, + "title": "URL to your GitHub repository" + } } + }, + "dependencies": { + "gitbook-core": "^4.0.0" + }, + "devDependencies": { + "eslint-config-gitbook": "^1.4.0", + "gitbook-plugin": "^4.0.0" + } } From c1595eea659d9bf2c96195d34a6cabc170f054ce Mon Sep 17 00:00:00 2001 From: Soreine Date: Fri, 2 Dec 2016 14:40:54 +0100 Subject: [PATCH 2/5] Run `gitbook-plugin create` --- .eslintignore | 2 ++ .eslintrc | 3 +++ .gitignore | 31 +++++++++++++++++++++++++++++++ .npmignore | 2 ++ index.js | 14 +++++++------- package.json | 23 +++++++++++++++++------ 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .npmignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..1d35cda --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +# Plugin assets +_assets/plugin.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..90359b2 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "gitbook/plugin" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef47881 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules + +# vim swapfile +*.swp + +# Plugin assets +_assets/plugin.js diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..a0e53cf --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +# Publish assets on NPM +!_assets/plugin.js diff --git a/index.js b/index.js index 55383f1..e542ae8 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,10 @@ + module.exports = { - - website: { - assets: './assets', - js: [ - 'plugin.js' - ] - } + blocks: { + + }, + + hooks: { + } }; diff --git a/package.json b/package.json index 2f519d3..34cba1a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { + "title": "Github Sharing", "name": "gitbook-plugin-github", "version": "2.0.0", "description": "Display a link to your GitHub repo in your gitbook", + "keywords": ['github', 'sharing', 'repository'], "main": "index.js", "authors": [ { @@ -17,6 +19,16 @@ "url": "https://github.com/GitbookIO/plugin-github.git" }, "license": "Apache-2.0", + "browser": "./_assets/plugin.js", + "ebook": "./_assets/plugin.js", + "dependencies": { + "gitbook-core": "^4.0.0" + }, + "devDependencies": { + "gitbook-plugin": "^4.0.0", + "eslint": "3.7.1", + "eslint-config-gitbook": "1.4.0" + }, "engines": { "gitbook": ">=4.0.0-alpha.0" }, @@ -29,11 +41,10 @@ } } }, - "dependencies": { - "gitbook-core": "^4.0.0" - }, - "devDependencies": { - "eslint-config-gitbook": "^1.4.0", - "gitbook-plugin": "^4.0.0" + "scripts": { + "lint": "eslint ./", + "build-website": "gitbook-plugin build ./src/index.js ./_assets/plugin.js", + "prepublish": "npm run build-website", + "test": "gitbook-plugin test && npm run lint" } } From fef1e62189733321335c9d6cba52d2cfd55f8180 Mon Sep 17 00:00:00 2001 From: Soreine Date: Fri, 2 Dec 2016 14:43:21 +0100 Subject: [PATCH 3/5] Add social category --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 34cba1a..73dc90a 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "gitbook-plugin-github", "version": "2.0.0", "description": "Display a link to your GitHub repo in your gitbook", - "keywords": ['github', 'sharing', 'repository'], + "keywords": ["gitbook:social", "github", "sharing", "repository"], "main": "index.js", "authors": [ { From 1385da0b67a488cf00b3fd59a1da143128d4524d Mon Sep 17 00:00:00 2001 From: Soreine Date: Fri, 2 Dec 2016 16:08:09 +0100 Subject: [PATCH 4/5] Implement Button in toolbar --- assets/plugin.js | 14 -------------- src/components/GitHubButton.js | 34 ++++++++++++++++++++++++++++++++++ src/index.js | 9 +++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) delete mode 100644 assets/plugin.js create mode 100644 src/components/GitHubButton.js create mode 100644 src/index.js diff --git a/assets/plugin.js b/assets/plugin.js deleted file mode 100644 index 14810ce..0000000 --- a/assets/plugin.js +++ /dev/null @@ -1,14 +0,0 @@ -require([ 'gitbook' ], function (gitbook) { - gitbook.events.bind('start', function (e, config) { - var githubURL = config.github.url; - - gitbook.toolbar.createButton({ - icon: 'fa fa-github', - label: 'GitHub', - position: 'right', - onClick: function() { - window.open(githubURL) - } - }); - }); -}); diff --git a/src/components/GitHubButton.js b/src/components/GitHubButton.js new file mode 100644 index 0000000..3f2b0d0 --- /dev/null +++ b/src/components/GitHubButton.js @@ -0,0 +1,34 @@ +const GitBook = require('gitbook-core'); +const { React } = GitBook; + +/** + * Display a button that links to the GitHub repository + */ +const SharingButtons = React.createClass({ + propTypes: { + url: React.PropTypes.string.isRequired + }, + + render() { + const { url } = this.props; + + return ( + + + + + + ); + } +}); + +function mapStateToProps(state) { + const options = state.config.getIn(['pluginsConfig', 'github']) || {}; + const { url = '' } = options; + + return { + url + }; +} + +module.exports = GitBook.connect(SharingButtons, mapStateToProps); diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..6a4079d --- /dev/null +++ b/src/index.js @@ -0,0 +1,9 @@ +const GitBook = require('gitbook-core'); +const GitHubButton = require('./components/GitHubButton'); + +module.exports = GitBook.createPlugin({ + activate: (dispatch, getState, { Components }) => { + // Dispatch initialization actions + dispatch(Components.registerComponent(GitHubButton, { role: 'toolbar:buttons:right' })); + } +}); From b3bcfdbbb44b14b6aa416f28d6b6de3151be3f6c Mon Sep 17 00:00:00 2001 From: Soreine Date: Fri, 2 Dec 2016 17:06:03 +0100 Subject: [PATCH 5/5] Fix click on button --- src/components/GitHubButton.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/GitHubButton.js b/src/components/GitHubButton.js index 3f2b0d0..cc4e5c3 100644 --- a/src/components/GitHubButton.js +++ b/src/components/GitHubButton.js @@ -14,7 +14,8 @@ const SharingButtons = React.createClass({ return ( - + window.open(url)}> @@ -23,8 +24,7 @@ const SharingButtons = React.createClass({ }); function mapStateToProps(state) { - const options = state.config.getIn(['pluginsConfig', 'github']) || {}; - const { url = '' } = options; + const url = state.config.getIn(['pluginsConfig', 'github', 'url']); return { url