-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
366 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
'use strict' | ||
|
||
const {isEmpty, reduce} = require('lodash') | ||
const { isEmpty, reduce } = require('lodash') | ||
const getData = require('./src/get-data') | ||
const loadHtml = require('./src/html') | ||
const {props, getConnector} = getData | ||
const { props, getConnector } = getData | ||
|
||
module.exports = async ({url, html}) => { | ||
module.exports = async ({ url, html }) => { | ||
const htmlDom = loadHtml(html) | ||
|
||
const value = reduce(props, (acc, conditions, propName) => { | ||
const data = getData({htmlDom, url, conditions}) | ||
acc[propName] = !isEmpty(data) ? data : null | ||
return acc | ||
}, {}) | ||
const value = reduce( | ||
props, | ||
(acc, conditions, propName) => { | ||
const data = getData({ htmlDom, url, conditions }) | ||
acc[propName] = !isEmpty(data) ? data : null | ||
return acc | ||
}, | ||
{} | ||
) | ||
|
||
const connector = await getConnector({htmlDom, url}) | ||
const connector = await getConnector({ htmlDom, url }) | ||
return Object.assign({}, value, connector) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
'use strict' | ||
|
||
const sanitizeHtml = require('sanitize-html') | ||
const {flow, isNil} = require('lodash') | ||
const { flow, isNil } = require('lodash') | ||
const cheerio = require('cheerio') | ||
|
||
const normalizeAttributes = propName => (tagName, attribs) => { | ||
if (!isNil(attribs[propName])) attribs[propName] = attribs[propName].toLowerCase() | ||
return {tagName, attribs} | ||
if (!isNil(attribs[propName])) { | ||
attribs[propName] = attribs[propName].toLowerCase() | ||
} | ||
return { tagName, attribs } | ||
} | ||
|
||
const sanitize = html => sanitizeHtml(html, { | ||
allowedTags: false, | ||
allowedAttributes: false, | ||
transformTags: { | ||
meta: normalizeAttributes('name'), | ||
a: normalizeAttributes('href'), | ||
link: normalizeAttributes('rel') | ||
} | ||
}) | ||
const sanitize = html => | ||
sanitizeHtml(html, { | ||
allowedTags: false, | ||
allowedAttributes: false, | ||
transformTags: { | ||
meta: normalizeAttributes('name'), | ||
a: normalizeAttributes('href'), | ||
link: normalizeAttributes('rel') | ||
} | ||
}) | ||
|
||
const load = cheerio.load.bind(cheerio) | ||
|
||
module.exports = flow([ | ||
sanitize, | ||
load | ||
]) | ||
module.exports = flow([sanitize, load]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'http://www.anandtech.com/show/11591/amd-launches-ryzen-pro-cpus-enhanced-security-longer-warranty-better-quality' | ||
const url = | ||
'http://www.anandtech.com/show/11591/amd-launches-ryzen-pro-cpus-enhanced-security-longer-warranty-better-quality' | ||
|
||
it('anandtech', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'https://arstechnica.com/features/2017/06/youtube-changed-my-life-a-pair-of-original-videostars-ponder-a-life-lived-online' | ||
const url = | ||
'https://arstechnica.com/features/2017/06/youtube-changed-my-life-a-pair-of-original-videostars-ponder-a-life-lived-online' | ||
|
||
it('arstechnica', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'https://audiense.com/twin-peaks-2017-using-the-social-data-audience-consumer-insights-to-create-the-next-big-tv-sensation' | ||
const url = | ||
'https://audiense.com/twin-peaks-2017-using-the-social-data-audience-consumer-insights-to-create-the-next-big-tv-sensation' | ||
|
||
it('audiense', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance' | ||
const url = | ||
'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance' | ||
|
||
it('bloomberg', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'http://www.businesstoday.in/magazine/features/hackerrank-helping-cos-hire-coding-champions-via-online-tests/story/232567.html' | ||
const url = | ||
'http://www.businesstoday.in/magazine/features/hackerrank-helping-cos-hire-coding-champions-via-online-tests/story/232567.html' | ||
|
||
it('business-today', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'http://www.cbronline.com/news/cloud/aas/virtustream-ceo-taking-a-masochistic-approach-to-fighting-in-the-cloud-market-4884858' | ||
const url = | ||
'http://www.cbronline.com/news/cloud/aas/virtustream-ceo-taking-a-masochistic-approach-to-fighting-in-the-cloud-market-4884858' | ||
|
||
it('cbr', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
'use strict' | ||
|
||
const snapshot = require('snap-shot') | ||
const {promisify} = require('util') | ||
const {resolve} = require('path') | ||
const { promisify } = require('util') | ||
const { resolve } = require('path') | ||
|
||
const fs = require('fs') | ||
|
||
const getMetaData = require('../../..') | ||
const readFile = promisify(fs.readFile) | ||
|
||
const url = 'http://www.cio.com/article/2929788/cloud-computing/20-ways-to-measure-the-success-of-your-growing-cloud-investment.html' | ||
const url = | ||
'http://www.cio.com/article/2929788/cloud-computing/20-ways-to-measure-the-success-of-your-growing-cloud-investment.html' | ||
|
||
it('cio', async () => { | ||
const html = await readFile(resolve(__dirname, 'input.html')) | ||
const metadata = await getMetaData({html, url}) | ||
const metadata = await getMetaData({ html, url }) | ||
snapshot(metadata) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.