Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/metascraper-author/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const toAuthor = toRule(author)
* @return {Function} stricter
*/

const strict = rule => $ => {
const value = rule($)
return REGEX_STRICT.test(value) && value
const strict = rule => async $ => {
const value = await rule($)
return REGEX_STRICT.test(value) ? value : undefined
}

module.exports = () => {
Expand Down
29 changes: 29 additions & 0 deletions packages/metascraper-author/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const metascraper = require('metascraper')([
require('metascraper-readability')()
])

const metascraperAuthor = require('metascraper')([require('..')()])

test('twitter:creator is used when no other author markup exists', async t => {
const metadata = await metascraper({
html: `
Expand All @@ -30,3 +32,30 @@ test('meta author wins over twitter:creator', async t => {
})
t.is(metadata.author, 'Nina Totenberg')
})

test('single-word matches from strict rules are rejected', async t => {
const metadata = await metascraperAuthor({
html: '<span class="author">Newsvilla</span>',
url: 'https://example.com/'
})
t.is(metadata.author, null)
})

test('multi-word matches from strict rules are kept', async t => {
const metadata = await metascraperAuthor({
html: '<span class="author">Jane Doe</span>',
url: 'https://example.com/'
})
t.is(metadata.author, 'Jane Doe')
})

test('a non-matching strict rule falls through to the next rule', async t => {
const metadata = await metascraperAuthor({
html: `
<a href="/author/banksy">Banksy</a>
<meta name="twitter:creator" content="@banksy">
`,
url: 'https://example.com/'
})
t.is(metadata.author, 'banksy')
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Generated by [AVA](https://avajs.dev).

{
audio: null,
author: 'HackerYou',
author: 'wesbos',
date: null,
description: 'A premium training course to learn to build apps with Node.js, Express, MongoDB, and friends.',
image: 'https://learnnode.com/images/NODE/poster.jpg',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Generated by [AVA](https://avajs.dev).

{
audio: null,
author: 'lsariasfstandard.com',
author: 'Lauren Saria',
date: '2024-06-24T18:59:54.000Z',
description: 'Diners hate them. Owners say they need them. But in the raging battle over restaurant service fees, it’s servers and cooks who are on the front lines.',
image: 'https://content.sfstandard.com/wp-content/uploads/2024/06/featured_20240621-junkfeeban.jpg?resize=1200%2C630',
Expand Down
Binary file not shown.
Loading