mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Use html decoding when getting values from fetched oembed
If we fetch oembed data from an external source, instead of handling it in readabilityjs we need to html decode it.
This commit is contained in:
parent
3d5a61285c
commit
ff1200f3a1
3 changed files with 35 additions and 6 deletions
|
|
@ -75,6 +75,7 @@
|
|||
"graphql-middleware": "^6.0.10",
|
||||
"graphql-shield": "^7.5.0",
|
||||
"highlightjs": "^9.16.2",
|
||||
"html-entities": "^2.3.2",
|
||||
"intercom-client": "^3.1.4",
|
||||
"jsdom": "^16.4.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { AxiosHandler } from './axios-handler'
|
|||
import { BloombergHandler } from './bloomberg-handler'
|
||||
import { GolangHandler } from './golang-handler'
|
||||
import * as hljs from 'highlightjs'
|
||||
import { decode } from 'html-entities'
|
||||
|
||||
const logger = buildLogger('utils.parse')
|
||||
|
||||
|
|
@ -333,10 +334,10 @@ const getJSONLdLinkMetadata = async (
|
|||
const jsonLd =
|
||||
(await axios.get(jsonLdLink.href, { timeout: 5000 })).data || {}
|
||||
|
||||
result.byline = jsonLd['author_name']
|
||||
result.previewImage = jsonLd['thumbnail_url']
|
||||
result.siteName = jsonLd['provider_name']
|
||||
result.title = jsonLd['title']
|
||||
result.byline = decode(jsonLd['author_name'])
|
||||
result.previewImage = decode(jsonLd['thumbnail_url'])
|
||||
result.siteName = decode(jsonLd['provider_name'])
|
||||
result.title = decode(jsonLd['title'])
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import 'mocha'
|
||||
import { expect } from 'chai'
|
||||
import 'chai/register-should'
|
||||
import { JSDOM } from 'jsdom'
|
||||
import fs from 'fs'
|
||||
import { findNewsletterUrl, isProbablyNewsletter, parsePageMetadata, parsePreparedContent } from '../../src/utils/parser'
|
||||
import nock from 'nock'
|
||||
|
||||
const load = (path: string): string => {
|
||||
return fs.readFileSync(path, 'utf8')
|
||||
|
|
@ -70,4 +70,31 @@ describe('parsePreparedContent', async () => {
|
|||
)
|
||||
expect(result.parsedContent?.publishedDate?.getTime()).to.equal(new Date('2016-04-05T15:27:51+00:00').getTime())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('parsePreparedContent', async () => {
|
||||
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://example.com/',
|
||||
{
|
||||
document: html,
|
||||
pageInfo: { }
|
||||
},
|
||||
)
|
||||
expect(result.parsedContent?.title).to.equal('The Ultimate Guide to Practicing Medicine in Singapore – Part 2')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue