feat: getExtractor returns generic extractor

pull/1/head
Adam Pash 8 years ago
parent c40b702b93
commit a022252a14

@ -1,7 +1,9 @@
#!/usr/bin/env node
var fs = require('fs')
var Iris = require('./dist/bundle')
var url = process.argv[2]
var result = Iris.parse(url).then(function(result) {
var html = fs.readFileSync('../file.html', 'utf8')
var result = Iris.parse(url, html).then(function(result) {
console.log(result.content)
})

@ -0,0 +1,7 @@
import GenericExtractor from './generic'
const Extractors = {
'*': GenericExtractor
}
export default Extractors

@ -8,6 +8,9 @@ import GenericDekExtractor from './dek/extractor'
import GenericLeadImageUrlExtractor from './lead-image-url/extractor'
const GenericExtractor = {
// This extractor is the default for all domains
domain: '*',
parse: (url, html, $) => {
if (html) {
$ = cheerio.load(html)

@ -0,0 +1,10 @@
import URL from 'url'
import Extractors from './all'
export default function getExtractor(url) {
const parsedUrl = URL.parse(url)
const { hostname } = parsedUrl
return Extractors[hostname] || Extractors['*']
}

@ -0,0 +1,11 @@
import assert from 'assert'
import getExtractor from './get-extractor'
describe('getExtractor(url)', () => {
it('returns GenericExtractor if no custom extractor is found', () => {
const extractor = getExtractor('http://example.com')
assert.equal(extractor.domain, '*')
})
})

@ -0,0 +1,5 @@
const Extractor = {
}
export default Extractor
Loading…
Cancel
Save