Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 69 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
node_modules

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# 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

# nyc test coverage
.nyc_output

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

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

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


# End of https://www.gitignore.io/api/node

.DS_Store
yarn-error.log

index.js
gatsby-ssr.js
28 changes: 6 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _gatsbyConfig = require('../../gatsby-config');

var _gatsbyConfig2 = _interopRequireDefault(_gatsbyConfig);
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _jsonp = require('jsonp');

Expand All @@ -32,23 +30,6 @@ var subscribeEmailToMailchimp = function subscribeEmailToMailchimp(url) {
});
};

/*
* parse the plugin options to use in our jsonp request
*/

var getPluginOptions = function getPluginOptions() {
// find gatsby-mailchimp plugin options (MC list settings)
var options = _gatsbyConfig2.default.plugins.find(function (plugin) {
return plugin.resolve === 'gatsby-plugin-mailchimp';
}).options;

var isString = typeof options.endpoint === 'string';
if (!isString) {
throw 'Mailchimp endpoint required and must be of type string. See repo README for more info.';
}
return options;
};

/*
* build a query string of MC list fields
* ex: '&KEY1=value1&KEY2=value2'
Expand Down Expand Up @@ -80,9 +61,12 @@ var addToMailchimp = function addToMailchimp(email, fields) {
// note, we change `/post` to `/post-json`
// otherwise, Mailchomp returns an error

var _getPluginOptions = getPluginOptions(),
endpoint = _getPluginOptions.endpoint;
var _ref = window.__GATSBY_PLUGIN_MAILCHIMP__ || {},
endpoint = _ref.endpoint;

if (!(typeof endpoint === 'undefined' ? 'undefined' : _typeof(endpoint)) === 'string') {
return Promise.reject('Mailchimp endpoint required and must be of type string. See repo README for more info.');
}
endpoint = endpoint.replace(/\/post/g, '/post-json');

var queryParams = '&EMAIL=' + emailEncoded + convertListFields(fields);
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"type": "git",
"url": "https://github.com/benjaminhoffman/gatsby-plugin-mailchimp.git"
},
"files": [
"index.js",
"gatsby-ssr.js",
"yarn.lock"
],
"keywords": [
"gatsby",
"gatsby-plugin",
Expand Down