Reads a link preview's metadata out of a page's HTML. parsePage scans the page once for the tags that carry it (<meta>, <link>, <img>, <title> and JSON-LD scripts) without building a document, and returns a Page that the providers' genericPreview picks from. Every field is undefined when the page doesn't say.

Functions

f
absoluteHttpUrl(
raw: string | undefined,
base: string
): string | undefined

Returns raw resolved against base as an absolute http(s) URL; undefined for a data: URI, another scheme or a URL that doesn't parse. Every URL a page names goes through it, so /og.png and //cdn/og.png work.

f
decodeHtmlEntities(str: string): string

Decodes the entities in str in a single pass, so &amp;quot; reads &quot;. An entity it doesn't know, or a code point that doesn't exist, is left as written. Also used by bandcamp-tralbum.ts on the JSON a page carries in an attribute.

f
normalizeCssColor(raw: string | undefined): string | undefined

Returns raw as a lowercase #rrggbb, from a hex, rgb(), rgba() or common named color; undefined for any other form. The generic preview stores it as the preview's accentColor, a tint over the app's own surface, so alpha is dropped, and a fully transparent one is no color at all.

f
parsePage(
html: string,
pageUrl: string
): Page

Reads html, served from pageUrl, in one pass. The generic preview and the providers built on it read a page through it.

Interfaces

I
JsonLdResult

Returned by the JSON-LD reading of parsePage, which the generic preview ranks below the page's OG and Twitter tags.

I
Page

Returned by parsePage: what a page says about itself, entities decoded, values trimmed and URLs absolute.