Media / foldkit-media
Providers
Provider.cdnCgi({ zone?, widths?, quality? })— Cloudflare's resizing on a zone that has it on. It picks the format fromAccept, so it offers nosources. Akeymay 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 ofsrcset.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 withouthashhas no hosted URL. The format is in the URL, so every cache can key on it.detect(url, { widths?, sources?, fallback?, quality? })fromfoldkit-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 answersOption<Provider>: none for a host unpic does not know. By default theimgasks forautoand the host picks the format fromAccept; a format asked as asourceis left out on a host that ignores it (Shopify's), and an asset on another host gets no URL. The asset'skeyis the image's URL, and its size comes fromfactsOf(url)(see Facts, below).tsimport { 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>.