gatsby-source-pinboard
Advanced tools
Comparing version 0.1.2 to 0.1.3
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
var crypto = require("crypto"); | ||
var fetch = require("node-fetch"); | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
exports.sourceNodes = function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref, _ref2) { | ||
var boundActionCreators = _ref.boundActionCreators; | ||
var authToken = _ref2.authToken, | ||
tags = _ref2.tags; | ||
var createNode, tagsQuery, res, data; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
createNode = boundActionCreators.createNode; | ||
tagsQuery = tags ? "&tag=" + tags : ""; | ||
_context.next = 4; | ||
return fetch( | ||
// https://pinboard.in/api/#posts_recent | ||
"https://api.pinboard.in/v1/posts/recent?auth_token=" + authToken + "&format=json&count=100" + tagsQuery); | ||
const crypto = require("crypto"); | ||
case 4: | ||
res = _context.sent; | ||
_context.next = 7; | ||
return res.json(); | ||
const fetch = require("node-fetch"); | ||
case 7: | ||
data = _context.sent; | ||
exports.sourceNodes = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* ({ | ||
actions | ||
}, { | ||
authToken, | ||
tags | ||
}) { | ||
const { | ||
createNode | ||
} = actions; | ||
const tagsQuery = tags ? `&tag=${tags}` : ""; | ||
const res = yield fetch( // https://pinboard.in/api/#posts_recent | ||
`https://api.pinboard.in/v1/posts/recent?auth_token=${authToken}&format=json&count=100${tagsQuery}`); | ||
const data = yield res.json(); // Process data into nodes. | ||
// Process data into nodes. | ||
data.posts.forEach(function (post) { | ||
var jsonString = JSON.stringify(post); | ||
var gatsbyNode = { | ||
// Fields from Pinboard | ||
href: post.href, | ||
description: post.description, | ||
extended: post.extended, | ||
time: post.time, | ||
shared: post.shared, | ||
toread: post.toread, | ||
tags: post.tags, | ||
// Required Gatsby fields | ||
id: "Pinboard bookmark for " + post.href, | ||
parent: "__SOURCE__", | ||
children: [], | ||
internal: { | ||
type: "PinboardBookmark", | ||
contentDigest: crypto.createHash("md5").update(jsonString).digest("hex") | ||
} | ||
}; | ||
createNode(gatsbyNode); | ||
}); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
data.posts.forEach(post => { | ||
const jsonString = JSON.stringify(post); | ||
const gatsbyNode = { | ||
// Fields from Pinboard | ||
href: post.href, | ||
description: post.description, | ||
extended: post.extended, | ||
time: post.time, | ||
shared: post.shared, | ||
toread: post.toread, | ||
tags: post.tags, | ||
// Required Gatsby fields | ||
id: `Pinboard bookmark for ${post.href}`, | ||
parent: "__SOURCE__", | ||
children: [], | ||
internal: { | ||
type: "PinboardBookmark", | ||
contentDigest: crypto.createHash("md5").update(jsonString).digest("hex") | ||
} | ||
} | ||
}, _callee, undefined); | ||
})); | ||
}; | ||
createNode(gatsbyNode); | ||
}); | ||
}); | ||
return function (_x, _x2) { | ||
return _ref3.apply(this, arguments); | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); |
{ | ||
"name": "gatsby-source-pinboard", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Grab recent bookmarks from Pinboard for use within Gatsby.", | ||
"scripts": { | ||
"start": "babel src --out-dir .", | ||
"precommit": "lint-staged", | ||
"release": "yarn start && yarn publish" | ||
"test": "eslint . --ignore-path .gitignore --ext .jsx --ext .js", | ||
"prepublishOnly": "babel src --out-dir .", | ||
"release": "git checkout master && git pull && yarn test && yarn publish && git push --follow-tags" | ||
}, | ||
@@ -16,17 +16,32 @@ "main": "gatsby-node.js", | ||
"crypto": "^1.0.1", | ||
"node-fetch": "^1.7.3" | ||
"node-fetch": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^4.2.3", | ||
"prettier": "^1.7.4" | ||
"@babel/cli": "^7.1.0", | ||
"@babel/core": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"eslint": "^5.6.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-config-prettier": "^3.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"husky": "^1.0.0-rc.15", | ||
"lint-staged": "^7.3.0", | ||
"prettier": "1.14.3" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"pinboard", | ||
"gatsby-plugin" | ||
], | ||
"lint-staged": { | ||
"*.{js,json,css}": [ | ||
"*.{js,jsx,json,css,scss,md}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
} | ||
} |
# gatsby-source-pinboard | ||
Note: This plugin requires Gatsby v2. | ||
To use, install the package and add to `gatsby-config.js`: | ||
```bash | ||
yarn add gatsby-source-pinboard | ||
npm install gatsby-source-pinboard | ||
``` | ||
```js | ||
{ | ||
resolve: "gatsby-source-pinboard", | ||
options: { | ||
authToken: "", // required authentication token | ||
tags: "" // optional tag to filter links | ||
} | ||
} | ||
``` | ||
You can query the data with: | ||
```js | ||
allPinboardBookmark(limit: 3) { | ||
edges { | ||
node { | ||
href | ||
description | ||
} | ||
} | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
5064
7
92
34
10
2
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
Updatednode-fetch@^2.2.0