feat: ability to add custom extractors via api (#484)
* feat: ability to add custom extractors via api * docs: updating readme * fix: example.com was being used in another test * fix: timezone was messing up date_published test * fix: using a unique site for testing * fix: updated custom extractor api * docs: updating readme * fix: removing unused fixture * fix: updating test description * feat: ability to add custom extractors via clidx-upgrade-rollup-and-eslint
parent
f95947fe88
commit
e12c916499
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,16 @@
|
||||
import mergeSupportedDomains from '../utils/merge-supported-domains';
|
||||
|
||||
export const apiExtractors = {};
|
||||
|
||||
export default function addExtractor(extractor) {
|
||||
if (!extractor || !extractor.domain) {
|
||||
return {
|
||||
error: true,
|
||||
message: 'Unable to add custom extractor. Invalid parameters.',
|
||||
};
|
||||
}
|
||||
|
||||
Object.assign(apiExtractors, mergeSupportedDomains(extractor));
|
||||
|
||||
return apiExtractors;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
import assert from 'assert';
|
||||
|
||||
import addExtractor from './add-extractor';
|
||||
|
||||
describe('addExtractor(extractor)', () => {
|
||||
it('can add multiple custom extractors', () => {
|
||||
addExtractor({ domain: 'www.site1.com' });
|
||||
addExtractor({ domain: 'www.site2.com' });
|
||||
const result = addExtractor({ domain: 'www.site3.com' });
|
||||
assert.equal(Object.keys(result).length, 3);
|
||||
});
|
||||
|
||||
it('returns error if an extractor is not provided', () => {
|
||||
const result = addExtractor();
|
||||
assert.equal(result.error, true);
|
||||
});
|
||||
|
||||
it('returns error if a domain key is not included within the custom extractor', () => {
|
||||
const result = addExtractor({ test: 'abc' });
|
||||
assert.equal(result.error, true);
|
||||
});
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
var customExtractor = {
|
||||
domain: 'postlight.com',
|
||||
title: {
|
||||
selectors: ['h1'],
|
||||
},
|
||||
author: {
|
||||
selectors: ['.byline-name'],
|
||||
},
|
||||
content: {
|
||||
selectors: ['article'],
|
||||
},
|
||||
extend: {
|
||||
uniqueKeyFromFixture: {
|
||||
selectors: ['.single__hero-category'],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = customExtractor;
|
Loading…
Reference in New Issue