diff --git a/built/general.d.ts b/built/general.d.ts index 95fe685..6ef5746 100644 --- a/built/general.d.ts +++ b/built/general.d.ts @@ -1,4 +1,4 @@ import * as URL from 'node:url'; -import Summary from './summary.js'; +import type { default as Summary } from './summary.js'; declare const _default: (url: URL.Url, lang?: string | null) => Promise; export default _default; diff --git a/built/general.js b/built/general.js index ac1d711..43ad500 100644 --- a/built/general.js +++ b/built/general.js @@ -2,7 +2,74 @@ import * as URL from 'node:url'; import clip from './utils/clip.js'; import cleanupTitle from './utils/cleanup-title.js'; import { decode as decodeHtml } from 'html-entities'; -import { head, scpaping } from './utils/got.js'; +import { get, head, scpaping } from './utils/got.js'; +import * as cheerio from 'cheerio'; +/** + * Contains only the html snippet for a sanitized iframe as the thumbnail is + * mostly covered in OpenGraph instead. + * + * Width should always be 100%. + */ +async function getOEmbedRich($, pageUrl) { + const href = $('link[type="application/json+oembed"]').attr('href'); + if (!href) { + return null; + } + // XXX: Use global URL object instead of the deprecated `node:url` + // Disallow relative URL as no one seems to use it + const oEmbed = await get(URL.resolve(pageUrl, href)); + const body = (() => { + try { + return JSON.parse(oEmbed); + } + catch { } + })(); + if (!body || body.version !== '1.0' || body.type !== 'rich') { + // Not a well formed rich oEmbed + return null; + } + if (!body.html.startsWith('