Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed Mar 4, 2021
0 parents commit 1d248de
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
101 changes: 101 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
logs
*.log
node_modules
*.un~
yarn.lock
package-lock.json
flow-typed
coverage
decls
examples
.gitattributes
*.code-workspace
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) 2021 Pittica S.r.l.s.

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.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# pittica/gatsby-plugin-cookiehub

![License](https://img.shields.io/github/license/pittica/gatsby-plugin-cookiehub)
![Version](https://img.shields.io/github/package-json/v/pittica/gatsby-plugin-cookiehub)
![Release](https://img.shields.io/github/v/release/pittica/gatsby-plugin-cookiehub)
![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/pittica/gatsby-plugin-cookiehub/dev/gatsby)
![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/pittica/gatsby-plugin-cookiehub/dev/react)
[![npm](https://img.shields.io/npm/v/@pittica/gatsby-plugin-cookiehub)](https://www.npmjs.com/package/@pittica/gatsby-plugin-cookiehub)

## Description

[CookieHub](https://www.cookiehub.com/) plugin for [GatsbyJS](https://www.gatsbyjs.org/).

## Install

[![npm](https://img.shields.io/npm/v/@pittica/gatsby-plugin-cookiehub)](https://www.npmjs.com/package/@pittica/gatsby-plugin-cookiehub)

```shell
npm install @pittica/gatsby-plugin-cookiehub
```

## Usage

The plugin provides integration for [CookieHub](https://www.cookiehub.com/) site.

## Configuration

Edit your **gatsby-config.js**.

```javascript
module.exports = {
plugins: [
{
resolve: `@pittica/gatsby-plugin-cookiehub`,
options: {
code: CODE,
debug: false,
cookie: 'pittica-cookiehub',
}
},
],
}
```
### Options

* #### key
Description: CookieHub domain code.

Required: **YES**.

Type: **String**.
* #### debug
Description: A value indicating whether run CookieHub in debug/development mode.

Required: **NO**.

Type: **Boolean**.
* #### cookie
Description: The prefix of the cookie name.

Required: **NO**.

Type: **String**.


## Copyright

(c) 2021, Pittaca S.r.l.s.
9 changes: 9 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.pluginOptionsSchema = ({ Joi }) => {
return Joi.object({
code: Joi.string().required().description(`CookieHub domain code.`),
debug: Joi.boolean()
.description(`A value indicating whether run CookieHub in debug/development mode.`)
.default(false),
cookie: Joi.string().description(`The prefix of the cookie name.`).default('pittica-cookiehub')
});
};
8 changes: 8 additions & 0 deletions gatsby-plugin-cookiehub.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
22 changes: 22 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const onRenderBody = ({ setHeadComponents }, { cookie, code, debug }) => {
return setHeadComponents([
<script
key="pittica-cookiehub"
dangerouslySetInnerHTML={{
__html: `
function allowCookie(category,value){
document.cookie="${cookie}-"+category+"="+(value?"true":"false")+"; path=/";
document.dispatchEvent(new CustomEvent('consentchange',{detail:{category:category,allowed:value}}));
}
var cpm={onAllow:function(category){allowCookie(category,true);},onDeny:function(category){allowCookie(category,false);}};
(function(h,u,b){
var d=h.getElementsByTagName("script")[0],e=h.createElement("script");
e.async=true;e.src='https://cookiehub.net/${debug ? 'dev/' : ''}c2/${code}.js';
e.onload=function(){u.cookiehub.load(b);}
d.parentNode.insertBefore(e,d);
})(document,window,cpm);
`
}}
/>
]);
};
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.consent = (callback) => {
document.addEventListener('consentchange', () => {
callback();
});
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@pittica/gatsby-plugin-cookiehub",
"private": false,
"description": "CookieHub plugin for GatsbyJS.",
"version": "1.0.0",
"author": {
"name": "Lucio Benini",
"email": "[email protected]",
"url": "https://pittica.com"
},
"bugs": {
"url": "https://github.com/pittica/gatsby-plugin-cookiehub/issues"
},
"deprecated": false,
"homepage": "https://github.com/pittica/gatsby-plugin-cookiehub",
"keywords": [ "gatsby", "gatsby-plugin", "gdpr", "cookiehub" ],
"devDependencies": {
"gatsby": "^2.32.3"
},
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/pittica/gatsby-plugin-cookiehub.git"
}
}

0 comments on commit 1d248de

Please sign in to comment.