-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 cli
- Loading branch information
Showing
10 changed files
with
3,186 additions
and
3 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -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; | ||
} |
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 |
---|---|---|
@@ -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); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -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; |
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