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.heroImage.alt} />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 |
h | number | Target height in pixels (combined with w, crops to cover the box) |
q | number | Output quality 1–100 (default 85; ignored for PNG) |
f | 'webp' | 'jpeg' | 'png' | 'avif' | Converts the output format |
download | boolean | Forces a browser download via Content-Disposition |
thumbnail | boolean | Extracts the first frame of an animated/video asset before resizing |
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 |
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) | Function | Converts a ContentRichText object to an HTML string |
toCamelCase(str) | Function | The key-normalization function used to match _schema values to registry keys |
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/client |
LocalessApiError | Class | Thrown when the API responds with a non-2xx status code |
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 |