interface ProductOgMetaProps { /** Positive price, already formatted to two decimals; null when it cannot be determined. */ priceAmount: string | null; currency: string; /** Purchasable right now (`canPurchase`), backorders included. */ inStock: boolean; /** * Purchasable while out of stock: `canPurchase && !inStock`, i.e. the merchant * allowed backorders. Maps to the same state the SDK's JSON-LD calls BackOrder. * Only read when `inStock` is true. */ backorder?: boolean; brandName?: string; } /** * Open Graph `product` object: the type tag plus the price, availability, condition * and brand tags that Facebook, Pinterest and Google Merchant Center read off a * product page. * * Rendered as real `` elements instead of through Next's * `metadata` for two reasons, both about what ends up in the HTML: * - `openGraph.type` only accepts a fixed list of values and `product` is not on * it, so the metadata API cannot emit `og:type: product`. * - `metadata.other` renders ``, and these tags are read from * `property=`. Emitting them as `name=` looks right in the source and is * ignored by the crawlers they exist for. * React hoists a `` rendered in a component into `
`. * * The product page must NOT also set `openGraph.type`, or the page carries two * `og:type` tags. * * Skips the price pair entirely when no positive amount is known, rather than * shipping "0", which turns every link preview into a free product. */ export function ProductOgMeta({ priceAmount, currency, inStock, backorder, brandName, }: ProductOgMetaProps) { // `product:availability` takes the catalog vocabulary Meta and Pinterest read, // not schema.org URLs. "available for order" is that vocabulary's word for a // product that can be bought while out of stock, the state the SDK's // JSON-LD builder reports as BackOrder. "in stock" would advertise stock that // does not exist; "out of stock" would hide a product that can be bought. const availability = !inStock ? 'out of stock' : backorder ? 'available for order' : 'in stock'; return ( <> {priceAmount ? ( <> > ) : null} {brandName ? : null} > ); }