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.
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.
Decodes the entities in str in a single pass, so &quot; reads
". 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.
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.
Reads html, served from pageUrl, in one pass. The generic preview and
the providers built on it read a page through it.
Returned by the JSON-LD reading of parsePage, which the generic preview ranks below the page's OG and Twitter tags.
- description: string
-
thumbnailUrl: string
From
image, or elsethumbnailUrlorthumbnail. -
title: string
From
name, or elseheadline.
Returned by parsePage: what a page says about itself, entities decoded, values trimmed and URLs absolute.
-
bestIcon: string
The largest icon the page links, which the thumbnail placeholder draws.
-
firstContentImage: string
The first image that doesn't look like page furniture.
- jsonLd: JsonLdResult
-
largeImage: string
The first image declared at least 200 pixels both ways.
-
maskIconColor: string
The
colorof the Safari pinned-tab icon, as written. -
meta(key: string): string | undefined
Returns the
contentof the first<meta>whosepropertyornameiskey, in any case: sites writeog:tags under either attribute, and Twitter's too. -
themeColor: string
The
theme-color, as written: pass it to normalizeCssColor. -
title: string
The text of the
<title>element.
Usage
import * as mod from "api/remote/html.ts";