Ox Content

ogp.ts

Source

getAttribute

function

Get element attribute value.

Source

function getAttribute(el: Element, name: string): string | undefined

Returns

string | undefined -


extractDomain

function

Extract domain from URL.

Source

function extractDomain(url: string): string

Returns

string -


getFaviconUrl

function

Get favicon URL for a domain.

Source

function getFaviconUrl(url: string): string

Returns

string -


parseOgpFromHtml

function

Parse OGP metadata from HTML.

Source

function parseOgpFromHtml(html: string, url: string): OgpData

Returns

OgpData -


fetchOgpData

function

Fetch OGP data for a URL.

Source

export async function fetchOgpData(
  url: string,
  options: Required<OgpOptions>,
  ): Promise<OgpData | null>

Returns

Promise<OgpData | null> -


createOgpCard

function

Create OGP card element.

Source

function createOgpCard(data: OgpData): Element

Returns

Element -


createFallbackCard

function

Create fallback element when OGP data is unavailable.

Source

function createFallbackCard(url: string): Element

Returns

Element -


collectOgpUrls

function

Collect all OGP URLs from HTML for pre-fetching.

Source

export async function collectOgpUrls(html: string): Promise<string[]>

Returns

Promise<string[]> -


prefetchOgpData

function

Pre-fetch all OGP data.

Source

export async function prefetchOgpData(
  urls: string[],
  options?: OgpOptions,
  ): Promise<Map<string, OgpData | null>>

Returns

Promise<Map<string, OgpData | null>> -


rehypeOgp

function

Rehype plugin to transform OgCard components.

Source

function rehypeOgp(ogpDataMap: Map<string, OgpData | null>)

transformOgp

function

Transform OgCard components in HTML.

Source

export async function transformOgp(
  html: string,
  ogpDataMap?: Map<string, OgpData | null>,
  options?: OgpOptions,
  ): Promise<string>

Returns

Promise<string> -