/** * Names the site a link points at, as the app shows it: a link dump's title * when its page has none, a preview's site name, the digest's domain line and * the tint of a card without artwork. The server's link checks key on it too * (`canonical-url.ts`), so a link reads as the same site everywhere. * * @module */ /** * Returns `url`'s host without a leading `www.`; `URL` has already lowered * its case. `www.youtube.com` and `youtube.com` give `youtube.com`. */ export function siteHostOf(url: URL): string { return url.hostname.replace(/^www\./, ""); } /** * Returns {@link siteHostOf} the URL `raw`, or undefined when `raw` isn't * one. */ export function siteHost(raw: string): string | undefined { try { return siteHostOf(new URL(raw)); } catch { return undefined; } }