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
2 changes: 1 addition & 1 deletion packages/metascraper-instagram/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const test = memoizeOne(

const getDescription = memoizeOne(
(_, $) => $meta('og:description')($),
memoizeOne.EqualityFirstArgument
memoizeOne.EqualityUrlAndHtmlDom
)

module.exports = () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/metascraper-instagram/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ test('from story', async t => {
const metadata = await metascraper({ url, html })
t.snapshot(metadata)
})

test('a second document at the same url is read on its own', async t => {
const url = 'https://www.instagram.com/p/same-url/'
const page = day =>
`<html><head><meta property="og:description" content="10 likes - someone on ${day}, 2024: caption"></head><body></body></html>`

const first = await metascraper({ url, html: page('March 1') })
const second = await metascraper({ url, html: page('June 2') })

t.true(first.date.startsWith('2024-03-01'))
t.true(second.date.startsWith('2024-06-02'))
})
2 changes: 1 addition & 1 deletion packages/metascraper-readability/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const readability = asyncMemoizeOne(async (url, html, readabilityOpts) => {
} finally {
await teardown()
}
}, memoizeOne.EqualityFirstArgument)
}, memoizeOne.EqualityUrlAndHtmlDom)

module.exports = ({ readabilityOpts } = {}) => {
const getReadbility = composeRule(($, url) =>
Expand Down
15 changes: 15 additions & 0 deletions packages/metascraper-readability/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,18 @@ test('extracts lang from <html lang> attribute', async t => {
const metadata = await metascraper({ html, url })
t.is(metadata.lang, 'en')
})

test('a second document at the same url is read on its own', async t => {
const url = 'https://example.com/post'
const article = `<html><head><title>Post</title></head><body><article><p>${'This domain is for use in illustrative examples in documents. '.repeat(
8
)}</p></article></body></html>`
const shell =
'<html><head><title>Shell</title></head><body><p>Nothing here.</p></body></html>'

const first = await metascraper({ html: article, url })
const second = await metascraper({ html: shell, url })

t.true(first.description.includes('illustrative'))
t.false(String(second.description).includes('illustrative'))
})
2 changes: 1 addition & 1 deletion packages/metascraper-tiktok/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const getAuthorAndUsername = memoizeOne((url, $) => {
?.trim()
const username = url.split('@')[1]?.split('/')[0]
return { authorName, username }
}, memoizeOne.EqualityFirstArgument)
}, memoizeOne.EqualityUrlAndHtmlDom)

module.exports = () => {
const rules = {
Expand Down
13 changes: 13 additions & 0 deletions packages/metascraper-tiktok/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ test('fallback date extraction when video id is invalid', async t => {

t.truthy(metadata.date)
})

test('a second document at the same url is read on its own', async t => {
const url = 'https://www.tiktok.com/@someone/video/1'
const page = name =>
`<html><head><meta property="og:title" content="${name} on TikTok"></head><body></body></html>`
const metascraper = createMetascraper()

const first = await metascraper({ url, html: page('First Author') })
const second = await metascraper({ url, html: page('Second Author') })

t.is(first.author, 'First Author')
t.is(second.author, 'Second Author')
})