Merge pull request #2937 from omnivore-app/fix/api-disable-jsonld-fetch

Disable JSONLD fetching which can be quite slow
This commit is contained in:
Jackson Harper
2023-10-16 12:35:38 +08:00
committed by GitHub
2 changed files with 29 additions and 34 deletions

View File

@ -332,18 +332,13 @@ export const parsePreparedContent = async (
DOMPurify.addHook('uponSanitizeElement', domPurifySanitizeHook)
const clean = DOMPurify.sanitize(article?.content || '', DOM_PURIFY_CONFIG)
const jsonLdLinkMetadata = (async () => {
return getJSONLdLinkMetadata(dom)
})()
Object.assign(article || {}, {
content: clean,
title: article?.title || (await jsonLdLinkMetadata).title,
previewImage:
article?.previewImage || (await jsonLdLinkMetadata).previewImage,
siteName: article?.siteName || (await jsonLdLinkMetadata).siteName,
title: article?.title,
previewImage: article?.previewImage,
siteName: article?.siteName,
siteIcon: article?.siteIcon,
byline: article?.byline || (await jsonLdLinkMetadata).byline,
byline: article?.byline,
language: article?.language,
})
logRecord.parseSuccess = true

View File

@ -78,32 +78,32 @@ describe('parsePreparedContent', () => {
})
})
describe('parsePreparedContent', () => {
nock('https://oembeddata').get('/').reply(200, {
version: '1.0',
provider_name: 'Hippocratic Adventures',
provider_url: 'https://www.hippocraticadventures.com',
title:
'The Ultimate Guide to Practicing Medicine in Singapore – Part 2',
})
// describe('parsePreparedContent', () => {
// nock('https://oembeddata').get('/').reply(200, {
// version: '1.0',
// provider_name: 'Hippocratic Adventures',
// provider_url: 'https://www.hippocraticadventures.com',
// title:
// 'The Ultimate Guide to Practicing Medicine in Singapore – Part 2',
// })
it('gets metadata from external JSONLD if available', async () => {
const html = `<html>
<head>
<link rel="alternate" type="application/json+oembed" href="https://oembeddata">
</link
</head>
<body>body</body>
</html>`
const result = await parsePreparedContent('https://blog.omnivore.app/', {
document: html,
pageInfo: {},
})
expect(result.parsedContent?.title).to.equal(
'The Ultimate Guide to Practicing Medicine in Singapore Part 2'
)
})
})
// it('gets metadata from external JSONLD if available', async () => {
// const html = `<html>
// <head>
// <link rel="alternate" type="application/json+oembed" href="https://oembeddata">
// </link
// </head>
// <body>body</body>
// </html>`
// const result = await parsePreparedContent('https://blog.omnivore.app/', {
// document: html,
// pageInfo: {},
// })
// expect(result.parsedContent?.title).to.equal(
// 'The Ultimate Guide to Practicing Medicine in Singapore Part 2'
// )
// })
// })
describe('isProbablyArticle', () => {
let user: User