Skip to content

Commit

Permalink
Add plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DevanB committed May 5, 2020
0 parents commit 46e4696
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tal ~/torii/gatsby-plugin-intercom-spa]$ vi ../torii_extension/.gitignore

node_modules/*

.env
*.tmp
*.log

# IntelliJ project files
.idea
*.iml
*.ipr
*.iws

# Mac files
*.DS_Store

/gatsby-ssr.js
yarn.lock
34 changes: 34 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
*.un~
yarn.lock
src
flow-typed
coverage
decls
examples
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Devan Beitel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# gatsby-plugin-splitbee

Easily add [Splitbee](https://splitbee.io/) to your Gatsby site.

## Install
`npm install --save gatsby-plugin-splitbee`

## How to use

```javascript
// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-plugin-splitbee`,
options: {
includeInDevelopment: false,
delayTimeout: 0
},
},
]
```

## Configuration

- `includeInDevelopment` - Optional. Defaults to `false`
- `delayTimeout` - Optional. Number of milliseconds to wait before loading the Splitbee. Defaults to `0`


1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "gatsby-plugin-splitbee",
"description": "Gatsby plugin to add Splitbee to a Gatsby site",
"version": "0.1.0",
"author": "Devan Beitel <[email protected]>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/DevanB/gatsby-plugin-splitbee"
},
"main": "index.js",
"files": [
"gatsby-ssr.js"
],
"keywords": [
"gatsby",
"gatsby-plugin",
"splitbee"
],
"scripts": {
"build": "babel src --out-dir . --ignore __tests__",
"watch": "babel -w src --out-dir . --ignore __tests__",
"prepublish": "cross-env NODE_ENV=production npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"babel-runtime": "^6.26.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"cross-env": "^5.0.5"
}
}
21 changes: 21 additions & 0 deletions src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react"

exports.onRenderBody = ({ setPostBodyComponents }, pluginOptions) => {
const includeInDevelopment = !!(pluginOptions.includeInDevelopment)
const isEnabled = (includeInDevelopment || process.env.NODE_ENV === 'production')

if (!isEnabled) {
return null
}

return setPostBodyComponents([
<script
key={`gatsby-plugin-splitbee`}
dangerouslySetInnerHTML={{
__html: `
(function(){var w=window;var sb=w.splitbee;var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Splitbee=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://cdn.splitbee.io/sb.js';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}function ld(){setTimeout(l, ${pluginOptions.delayTimeout || 0});}if(w.attachEvent){w.attachEvent('onload',ld);}else{w.addEventListener('load',ld,false);}})()
`
}}
/>
])
}

0 comments on commit 46e4696

Please sign in to comment.