Reference
Assets, rich text, links, error handling, and the full API reference for the Astro SDK for Localess.
Assets
---
import { resolveAsset } from '@localess/astro';
---
<img src={resolveAsset(data.heroImage, { w: 800 })} alt={data.heroImageAlt} />resolveAsset(asset, params?) resolves a ContentAsset to its full CDN URL, delegating to the integration's LocalessClient. Pass an AssetTransformParams object to resize or convert the format:
| Param | Type | Description |
|---|---|---|
w | number | Target width in pixels — whole number, 1–8192. Never upscales: a width above the source redirects to the source width |
h | number | Target height in pixels — same rules as w. Combined with w, the result is governed by fit |
fit | 'cover' | 'contain' | 'inside' | 'outside' | 'fill' | How the image fills the box when both w and h are set (default cover) |
q | number | Output quality, whole number 1–100. Defaults per format: JPEG and WebP 80, AVIF 50 |
f | 'webp' | 'jpeg' | 'png' | 'avif' | Converts the output format. Without it, the stored format is kept |
thumbnail | boolean | Extracts the first frame of an animated/video asset before resizing |
An out-of-range or fractional w, h or q throws a TypeError before the URL is built. For the untouched uploaded file, or to force a browser download, use the original and download links described below rather than a transform parameter.
Original file and download links
A bare resolveAsset(asset) URL is a rendition, not the uploaded file: still images are re-encoded at their format's default quality even with no parameters. When you need the exact bytes that were uploaded, or want the browser to save the file instead of displaying it, use the dedicated helpers:
---
import { resolveAssetDownload, resolveAssetOriginal } from '@localess/astro';
---
<a href={resolveAssetOriginal(data.heroImage)}>View the original file</a>
<a href={resolveAssetDownload(data.brochure)} download>Download</a>Neither accepts transform parameters. A request that adds any is rejected with 400. Downloads keep non-ASCII file names intact.
Rich text
---
import LocalessRichText from '@localess/astro/LocalessRichText.astro';
---
<LocalessRichText content={data.body} />| Prop | Type | Description |
|---|---|---|
content | LocalessRichTextInput | The rich text field value. Accepts a full document, a single node, an array of nodes, or null/undefined, so a field value passes through without casting |
renderers | LocalessRichTextRenderers<string> | Optional per-node/per-mark overrides, keyed by element name |
Supported elements: doc, paragraph, heading (levels 1–6), bulletList, orderedList, listItem, codeBlock, text; marks bold, italic, strike, underline, code, link. An unknown node is skipped and an unknown mark renders its children unwrapped, each with a one-time console.warn outside production.
To render to an HTML string in frontmatter instead of using the component, import renderRichTextToHtml from @localess/astro. Rendering is shared across every Localess SDK by @localess/richtext, so one document renders identically in Astro, React, Angular, Vue, and Svelte.
Links
@localess/astro doesn't re-export findLink yet — import it directly from @localess/client, which works in any Astro frontmatter (it's a pure function, no client instance needed):
---
import { findLink } from '@localess/client';
---
<a href={findLink(content.links, data.ctaLink)}>{data.label}</a>ContentLink.type | Result |
|---|---|
"content" | Looks up link.uri in the links map and returns /<fullSlug> |
"url" | Returns link.uri as-is |
Error handling
getContentBySlug/getContentById throw LocalessApiError (re-exported from @localess/astro) on a non-2xx API response — check error.status to distinguish a missing slug (404) from other failures:
---
import { getLocalessClient, LocalessApiError } from '@localess/astro';
let content;
try {
content = await getLocalessClient().getContentBySlug(slug);
} catch (error) {
if (error instanceof LocalessApiError && error.status === 404) {
return Astro.rewrite('/404');
}
throw error;
}
---API Reference
@localess/astro (default entry point)
| Export | Kind | Description |
|---|---|---|
localess / localessIntegration | Function | The Astro Integration factory — registered in astro.config.mjs |
getLocalessClient() | Function | Returns the LocalessClient built by the integration. Throws if localess() isn't configured |
getLivePayload(astroGlobal) | Function | Retrieves draft content stashed by the live-preview middleware, for the livePreview tier |
resolveAsset(asset, params?) | Function | Resolves a ContentAsset to a full CDN URL, with optional transform params |
resolveAssetOriginal(asset) | Function | Resolves a ContentAsset to the URL of the file exactly as uploaded |
resolveAssetDownload(asset) | Function | Resolves a ContentAsset to a URL that downloads the file as an attachment |
localessEditable(data) | Function | Returns data-ll-id/data-ll-schema attributes to spread on a component's root element |
localessEditableField(fieldName) | Function | Returns a data-ll-field attribute to spread on an editable field |
renderLocalessRichTextToHtml(content) / renderRichTextToHtml(content) | Function | Converts a ContentRichText object to an HTML string |
normalizeComponentKey(key, strategy) | Function | The key normalization used to match _schema values to registry keys under componentNaming |
toCamelCase(str) | Function | camelCase string helper — not used for matching unless componentNaming: 'camelCase' |
handleLocalessMessage(event) | Function | The livePreview tier's sync-event handler, injected automatically — exported for advanced/manual use |
loadLocalessSync(origin) | Function | Loads the Visual Editor sync script; used internally by both sync tiers |
isBrowser() / isIframe() | Function | Environment checks re-exported from @localess/live-preview |
localessClient(options) | Function | Creates a standalone client — for build scripts that run outside the integration |
LocalessApiError | Class | Thrown when the API responds with a non-2xx status code |
LocalessSync, EventToApp, EventToAppOf, EventToAppType, EventCallback | Types | Visual Editor sync event types |
LocalessSchemaProps<T> | Type | Props shape a registered component accepts: data: T, plus optional links/references/assets — use it to type export type Props = LocalessSchemaProps<Page> instead of writing your own interface |
LocalessComponentProps<T> | Type | Props shape of the built-in LocalessComponent renderer itself. Kept separate from LocalessSchemaProps<T> so the renderer can evolve independently of the contract your components implement |
Content<T>, ContentData, ContentAsset, ContentLink, ContentRichText, Links, References, Assets, LocalessClient, LocalessOptions, ... | Types | Re-exported content and configuration types |
Subpath exports (.astro components)
| Export | Description |
|---|---|
@localess/astro/LocalessComponent.astro | Dynamically resolves and renders the registered component for data._schema |
@localess/astro/LocalessDocument.astro | Renders a full Content response via LocalessComponent |
@localess/astro/LocalessRichText.astro | Renders a ContentRichText field to HTML |
@localess/astro/FallbackComponent.astro | The built-in fallback, used when customFallbackComponent is omitted |