gatsby-source-hire-with-google
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -1,90 +0,96 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _crypto = _interopRequireDefault(require("crypto")); | ||
let getJob = (() => { | ||
var _ref = _asyncToGenerator(function* (jobUrl) { | ||
const response = yield _axios2.default.get(jobUrl); | ||
const $ = _cheerio2.default.load(response.data); | ||
var _axios = _interopRequireDefault(require("axios")); | ||
return { | ||
id: jobUrl, | ||
url: jobUrl, | ||
title: $(jobTitleSelector).text(), | ||
department: $(jobDepartmentSelector).text(), | ||
location: $(jobLocationSelector).text(), | ||
content: $(jobContentSelector).html() | ||
}; | ||
}); | ||
var _cheerio = _interopRequireDefault(require("cheerio")); | ||
return function getJob(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
let getJobs = (() => { | ||
var _ref2 = _asyncToGenerator(function* (companyName) { | ||
const response = yield _axios2.default.get(`${BASE_URL}${companyName}`); | ||
const $ = _cheerio2.default.load(response.data); | ||
const jobLinks = $(jobSelector).map(function (i, elm) { | ||
return $(elm).attr('href'); | ||
}).get(); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
return yield Promise.all(jobLinks.map(function (l) { | ||
return getJob(l); | ||
})); | ||
}); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
return function getJobs(_x2) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
})(); | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); 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 { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; } | ||
var _crypto = require('crypto'); | ||
const jobSelector = 'a.bb-public-jobs-list__job-item-title.ptor-jobs-list__item-job-title'; | ||
const BASE_URL = 'https://hire.withgoogle.com/public/jobs/'; | ||
const jobTitleSelector = '.bb-jobs-posting__job-title.ptor-job-view-title'; | ||
const jobDepartmentSelector = '.bb-jobs-posting__job-details-item.ptor-job-view-department'; | ||
const jobLocationSelector = '.bb-jobs-posting__job-details-item.ptor-job-view-location'; | ||
const jobContentSelector = '.bb-rich-text-editor__content.ptor-job-view-description'; | ||
var _crypto2 = _interopRequireDefault(_crypto); | ||
function getJob(_x, _x2) { | ||
return _getJob.apply(this, arguments); | ||
} | ||
var _axios = require('axios'); | ||
function _getJob() { | ||
_getJob = _asyncToGenerator(function* (jobUrl, options) { | ||
const response = yield _axios.default.get(jobUrl); | ||
var _axios2 = _interopRequireDefault(_axios); | ||
const $ = _cheerio.default.load(response.data); | ||
var _cheerio = require('cheerio'); | ||
const content = $(jobContentSelector).html(); | ||
return { | ||
id: jobUrl.split('/').pop(), | ||
url: jobUrl, | ||
title: $(jobTitleSelector).text(), | ||
department: $(jobDepartmentSelector).text(), | ||
location: $(jobLocationSelector).text(), | ||
content: options.replaceDivs ? content.replace(/div>/g, 'p>') : content | ||
}; | ||
}); | ||
return _getJob.apply(this, arguments); | ||
} | ||
var _cheerio2 = _interopRequireDefault(_cheerio); | ||
function getJobs(_x3) { | ||
return _getJobs.apply(this, arguments); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getJobs() { | ||
_getJobs = _asyncToGenerator(function* ({ | ||
companyName, | ||
replaceDivs = true | ||
}) { | ||
const response = yield _axios.default.get(`${BASE_URL}${companyName}`); | ||
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"); }); }; } | ||
const $ = _cheerio.default.load(response.data); | ||
const jobSelector = 'a.bb-public-jobs-list__job-item-title.ptor-jobs-list__item-job-title'; | ||
const BASE_URL = 'https://hire.withgoogle.com/public/jobs/'; | ||
const jobLinks = $(jobSelector).map((i, elm) => { | ||
return $(elm).attr('href'); | ||
}).get(); | ||
return yield Promise.all(jobLinks.map(l => getJob(l, options))); | ||
}); | ||
return _getJobs.apply(this, arguments); | ||
} | ||
const jobTitleSelector = '.bb-jobs-posting__job-title.ptor-job-view-title'; | ||
const jobDepartmentSelector = '.bb-jobs-posting__job-details-item.ptor-job-view-department'; | ||
const jobLocationSelector = '.bb-jobs-posting__job-details-item.ptor-job-view-location'; | ||
const jobContentSelector = '.bb-rich-text-editor__content.ptor-job-view-description'; | ||
exports.sourceNodes = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* ({ | ||
boundActionCreators | ||
}, options) { | ||
const createNode = boundActionCreators.createNode; | ||
const jobs = yield getJobs(companyName, options); | ||
jobs.forEach(job => { | ||
const jsonString = JSON.stringify(job); | ||
exports.sourceNodes = (() => { | ||
var _ref3 = _asyncToGenerator(function* ({ boundActionCreators }, { companyName }) { | ||
const createNode = boundActionCreators.createNode; | ||
const gatsbyNode = _objectSpread({}, job, { | ||
parent: '__SOURCE__', | ||
children: [], | ||
internal: { | ||
type: 'hireWithGoogleJob', | ||
content: jsonString, | ||
contentDigest: _crypto.default.createHash('md5').update(jsonString).digest('hex') | ||
} | ||
}); | ||
const jobs = yield getJobs(companyName); | ||
createNode(gatsbyNode); | ||
}); | ||
}); | ||
jobs.forEach(function (job) { | ||
const jsonString = JSON.stringify(job); | ||
const gatsbyNode = _extends({}, job, { | ||
parent: '__SOURCE__', | ||
internal: { | ||
type: 'hireWithGoogleJob', | ||
content: jsonString, | ||
contentDigest: _crypto2.default.createHash('md5').update(jsonString).digest('hex') | ||
} | ||
}); | ||
createNode(gatsbyNode); | ||
}); | ||
}); | ||
return function (_x3, _x4) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
})(); | ||
return function (_x4, _x5) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); |
{ | ||
"name": "gatsby-source-hire-with-google", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Gatsby source plugin for loading job openings from hire.withgoogle.com", | ||
@@ -30,6 +30,6 @@ "main": "gatsby-node.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.6.0" | ||
"@babel/cli": "^7.0.0-beta.51", | ||
"@babel/core": "^7.0.0-beta.51", | ||
"@babel/preset-env": "^7.0.0-beta.51" | ||
} | ||
} |
# gatsby-source-hire-with-google | ||
> Loads job openings from hire.withgoogle.com/public/jobs/{companyName} into Gatsby.js. Based on [gatsby-source-greenhouse](https://github.com/diegolamanno/gatsby-source-greenhouse). | ||
> Loads job openings from hire.withgoogle.com/public/jobs/{companyName} into Gatsby.js source system. | ||
@@ -7,14 +7,15 @@ ## Installation | ||
```bash | ||
# npm | ||
npm install gatsby-source-hire-with-google | ||
``` | ||
or | ||
```bash | ||
# yarn | ||
yarn add gatsby-source-hire-with-google | ||
``` | ||
## Usage | ||
## How to Use | ||
To use this source you need to supply the company name used in `hire.withgoogle.com/public/jobs/{companyName}`. | ||
First, find the company name used in your public jobs url: `hire.withgoogle.com/public/jobs/{companyName}`. | ||
Next, edit `gatsby-config.js` to use the plugin: | ||
Next, add `companyName` in your `gatsby-config.js`: | ||
``` | ||
@@ -29,2 +30,4 @@ { | ||
companyName: '{COMPANY_NAME}', | ||
replaceDivs: false // true is default. Hire defaults to use <div> instead of <p> for paragrahs, so if you prefer this, set this to false. | ||
}, | ||
@@ -36,15 +39,18 @@ }, | ||
## Querying | ||
## How to Query | ||
You can query the nodes created by the plugin as follows: | ||
```graphql | ||
{ | ||
allHireWithGoogleJob { | ||
edges { | ||
node { | ||
... | ||
} | ||
edges { | ||
node { | ||
id | ||
url | ||
title | ||
department | ||
content | ||
} | ||
} | ||
} | ||
} | ||
``` |
@@ -13,8 +13,9 @@ import crypto from 'crypto' | ||
async function getJob(jobUrl) { | ||
async function getJob(jobUrl, options) { | ||
const response = await axios.get(jobUrl) | ||
const $ = cheerio.load(response.data); | ||
const content = $(jobContentSelector).html() | ||
return { | ||
id: jobUrl, | ||
id: jobUrl.split('/').pop(), | ||
url: jobUrl, | ||
@@ -24,7 +25,7 @@ title: $(jobTitleSelector).text(), | ||
location: $(jobLocationSelector).text(), | ||
content: $(jobContentSelector).html() | ||
content: options.replaceDivs ? content.replace(/div>/g,'p>') : content | ||
} | ||
} | ||
async function getJobs(companyName) { | ||
async function getJobs({companyName, replaceDivs = true}) { | ||
const response = await axios.get(`${BASE_URL}${companyName}`) | ||
@@ -36,8 +37,8 @@ const $ = cheerio.load(response.data) | ||
return await Promise.all(jobLinks.map(l => getJob(l))) | ||
return await Promise.all(jobLinks.map(l => getJob(l, options))) | ||
} | ||
exports.sourceNodes = async ({ boundActionCreators }, { companyName }) => { | ||
exports.sourceNodes = async ({ boundActionCreators }, options) => { | ||
const { createNode } = boundActionCreators | ||
const jobs = await getJobs(companyName) | ||
const jobs = await getJobs(companyName, options) | ||
@@ -44,0 +45,0 @@ jobs.forEach(job => { |
Sorry, the diff of this file is not supported yet
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
8979
128
54