-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detectors for matching extractors for publishing platforms. Currently supporting Medium and Blogger.
- Loading branch information
Showing
5 changed files
with
58 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
MediumExtractor, | ||
BloggerExtractor, | ||
} from './custom/'; | ||
|
||
const Detectors = { | ||
'meta[name="al:ios:app_name"][value="Medium"]': MediumExtractor, | ||
'meta[name="generator"][value="blogger"]': BloggerExtractor, | ||
}; | ||
|
||
export default function detectByHtml($) { | ||
const selector = Reflect.ownKeys(Detectors).find(s => $(s).length > 0); | ||
|
||
return Detectors[selector]; | ||
} |
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,24 @@ | ||
import assert from 'assert'; | ||
import cheerio from 'cheerio'; | ||
|
||
import detectByHtml from './detect-by-html'; | ||
|
||
describe('detectByHtml', () => { | ||
it('detects a medium post from the html', () => { | ||
const html = | ||
'<head><meta name="al:ios:app_name" value="Medium" /></head>'; | ||
|
||
const $ = cheerio.load(html); | ||
|
||
assert.equal(detectByHtml($).domain, 'medium.com'); | ||
}); | ||
|
||
it('returns nothing if no match is found', () => { | ||
const html = | ||
'<div></div>'; | ||
|
||
const $ = cheerio.load(html); | ||
|
||
assert.equal(detectByHtml($), null); | ||
}); | ||
}); |
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