Media / foldkit-media

Providers

  • Provider.cdnCgi({ zone?, widths?, quality? }) — Cloudflare's resizing on a zone that has it on. It picks the format from Accept, so it offers no sources. A key may be a path on the zone or an absolute URL.

  • Provider.fromFiles(files, { sources, fallback }) — variants a build already wrote, as a table of { width, format, url }. Its ladder is the widths it has; a variant it lacks is left out of srcset.

  • Provider.hosted({ baseUrl?, widths?, sources?, fallback?, quality? }) — this package's own server, for originals no CDN can fetch. A variant's URL is /_image/<sha-256>/w640.avif: the original is named by its content hash, so an asset without hash has no hosted URL. The format is in the URL, so every cache can key on it.

  • detect(url, { widths?, sources?, fallback?, quality? }) from foldkit-media/unpic — an image on a host that resizes it (Shopify, Cloudinary, imgix, Contentful, and the rest unpic knows), through unpic, an optional peer. It answers Option<Provider>: none for a host unpic does not know. By default the img asks for auto and the host picks the format from Accept; a format asked as a source is left out on a host that ignores it (Shopify's), and an asset on another host gets no URL. The asset's key is the image's URL, and its size comes from factsOf(url) (see Facts, below).

    ts
    import { Option } from 'effect'
    import { detect } from 'foldkit-media/unpic'
    
    const shopify = detect('https://cdn.shopify.com/s/files/1/0/products/shirt.jpg')
    Option.isSome(shopify) // true

A provider is a plain value (Provider.Provider): widths, the sources formats offered before the img, the img's own fallback encoding, and a url function answering Option<string>.