gatsby-source-darksky
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -11,9 +11,10 @@ "use strict"; | ||
exports.sourceNodes = | ||
var _createWeatherNode = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref2 = _asyncToGenerator( | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(_ref, configOptions) { | ||
var actions, createNodeId, createContentDigest, createNode, processWeather, key, latitude, longitude, exclude, apiUrl, response, data, nodeData; | ||
regeneratorRuntime.mark(function _callee(latitude, longitude, createNodeId, createContentDigest, createNode, configOptions) { | ||
var _processWeather, key, exclude, apiUrl, response, data, nodeData; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -23,7 +24,3 @@ while (1) { | ||
case 0: | ||
actions = _ref.actions, createNodeId = _ref.createNodeId, createContentDigest = _ref.createContentDigest; | ||
createNode = actions.createNode; | ||
delete configOptions.plugins; | ||
processWeather = function processWeather(weather) { | ||
_processWeather = function _processWeather(weather) { | ||
var nodeId = createNodeId(`weather-data-${uuidv4()}`); | ||
@@ -44,19 +41,19 @@ var nodeContent = JSON.stringify(weather); | ||
key = configOptions.key, latitude = configOptions.latitude, longitude = configOptions.longitude, exclude = configOptions.exclude; | ||
key = configOptions.key, exclude = configOptions.exclude; | ||
exclude = exclude.join(','); | ||
apiUrl = `https://api.darksky.net/forecast/${key}/${latitude},${longitude}?exclude=${exclude}`; | ||
_context.next = 9; | ||
_context.next = 6; | ||
return fetch(apiUrl); | ||
case 9: | ||
case 6: | ||
response = _context.sent; | ||
_context.next = 12; | ||
_context.next = 9; | ||
return response.json(); | ||
case 12: | ||
case 9: | ||
data = _context.sent; | ||
nodeData = processWeather(data); | ||
nodeData = _processWeather(data); | ||
createNode(nodeData); | ||
case 15: | ||
case 12: | ||
case "end": | ||
@@ -69,5 +66,78 @@ return _context.stop(); | ||
return function (_x, _x2) { | ||
return _ref2.apply(this, arguments); | ||
return function _createWeatherNode(_x, _x2, _x3, _x4, _x5, _x6) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
exports.sourceNodes = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref3 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee3(_ref2, configOptions) { | ||
var actions, createNodeId, createContentDigest, createNode, latitude, longitude; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
actions = _ref2.actions, createNodeId = _ref2.createNodeId, createContentDigest = _ref2.createContentDigest; | ||
createNode = actions.createNode; | ||
delete configOptions.plugins; | ||
if (!configOptions.latitude) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
latitude = configOptions.latitude, longitude = configOptions.longitude; | ||
_context3.next = 7; | ||
return _createWeatherNode(latitude, longitude, createNodeId, createContentDigest, createNode, configOptions); | ||
case 7: | ||
_context3.next = 10; | ||
break; | ||
case 9: | ||
exports.onCreateNode = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref5 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2(_ref4) { | ||
var node, parsedContent, _parsedContent$result, latitude, longitude; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
node = _ref4.node; | ||
parsedContent = JSON.parse(node.internal.content); | ||
_parsedContent$result = parsedContent.results[0].geometry.location, latitude = _parsedContent$result.lat, longitude = _parsedContent$result.lng; | ||
_context2.next = 5; | ||
return _createWeatherNode(latitude, longitude, createNodeId, createContentDigest, createNode, configOptions); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
return function (_x9) { | ||
return _ref5.apply(this, arguments); | ||
}; | ||
}(); | ||
case 10: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
return function (_x7, _x8) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); |
@@ -18,3 +18,3 @@ { | ||
}, | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"dependencies": { | ||
@@ -21,0 +21,0 @@ "node-fetch": "^2.3.0", |
@@ -34,3 +34,3 @@ # gatsby-source-darksky | ||
The configuration options for this plugin mirror the [forecast request parameters](https://darksky.net/dev/docs). Please review those docs for more details. | ||
The configuration options for this plugin mirror the [forecast request parameters](https://darksky.net/dev/docs). Please review those docs for more details. This plugin works well with [gatsby-source-googlemaps-geocoding](https://github.com/Matt-Dionis/gatsby-source-googlemaps-geocoding). If using these two plugins together, make sure that the `gatsby-source-darksky` entry appears first in the config. If so, and you omit `latitude` and `longitude` from this config, the weather information will be fetched for the location provided in the `gatsby-source-darksky` config. | ||
@@ -40,4 +40,4 @@ | Option | Default | Description | | ||
| `key` | | **[required]** Your Dark Sky API key | | ||
| `latitude` | | **[required]** The latitude of a location (in decimal degrees). Positive is north, negative is south. | | ||
| `longitude` | | **[required]** The longitude of a location (in decimal degrees). Positive is east, negative is west. | | ||
| `latitude` | | The latitude of a location (in decimal degrees). Positive is north, negative is south. (optional if used with `gatsby-source-darksky`) | | ||
| `longitude` | | The longitude of a location (in decimal degrees). Positive is east, negative is west. (optional if used with `gatsby-source-darksky`) | | ||
| `exclude` | | Exclude some number of data blocks from the API response. This is useful for reducing latency and saving cache space. The value blocks should be a comma-delimeted list (without spaces) of any of the following: "currently", "minutely", "hourly", "daily", "alerts", "flags" | | ||
@@ -44,0 +44,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101707
119