Images And Variants
Reference an image by its path in the release. FOLD can also build smaller copies of an image for you.
Display An Image
In Markdown, write . In HTML, write <img src="/press/cover-small.webp" alt="Front cover">. Root-relative and page-relative paths both work. In a private preview, images load with the preview's own cookie.
The build adds width and height to an image that has neither, from the size of its src file, so the browser reserves space before the image loads. Set both yourself to override them. An image keeps its loading, decoding and fetchpriority attributes.
Offer More Than One Size
In HTML, use srcset to offer the same image at different pixel densities. This example uses the smaller file as the fallback and offers the original to denser displays.
<img
src="/press/cover-small.webp"
srcset="/press/cover.jpg 2x"
alt="Front cover"
/>
For a layout that changes with the width of the window, label each file with its real pixel width and describe the displayed width in sizes.
<img
src="/press/cover-small.webp"
srcset="/press/cover-small.webp 480w, /press/cover.jpg 1200w"
sizes="(max-width: 640px) 100vw, 640px"
alt="Front cover"
/>
Use densities or widths in one list, not both. Every file must be an image in the release. An invalid list leaves the fallback image in place.
To offer a newer format with a fallback, wrap the image in <picture>. The browser uses the first source it supports and otherwise loads the <img>.
<picture>
<source srcset="/press/cover-small.avif" type="image/avif" />
<img src="/press/cover-small.webp" alt="Front cover" loading="lazy" />
</picture>
Generate Variants
Add a file named _images at the root of the directory. Each item names an uploaded image, a new output path and a maximum width in pixels.
[
{
"source": "press/cover.jpg",
"path": "press/cover-small.webp",
"width": 480
}
]
- A release accepts up to 16 variants.
- The width is from 1 to 2048. The output extension is AVIF, JPEG, PNG or WebP.
- Resizing keeps the aspect ratio. An image smaller than the width keeps its size, so check the real width of a file before you label it in
srcset. - An animated image produces a still.
- Each result must fit the 8 MiB limit.
Open a variant in the preview at its output path, such as /press/cover-small.webp. Publishing and rollback serve the bytes saved during the build.
Find And Compare Media
List the media in a ready release, narrowed by folder, type, filename prefix or hash.
pnpm fold media list RELEASE_ID press --mime 'image/*' --query cover
Each item has the authored path, content type, SHA-256 hash, size and the permanent path for that release. A variant also names the original it was generated from.
Before you publish, compare a candidate release with the live one. The result lists added and removed paths, and paths whose bytes changed.
pnpm fold media compare BEFORE_RELEASE_ID AFTER_RELEASE_ID
To reuse a file in a draft without uploading it again, attach it by its hash.
pnpm fold draft attach DRAFT_ID REVISION press/cover.avif HASH
Next: Site asset library