Localess
Astro

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:

ParamTypeDescription
wnumberTarget width in pixels
hnumberTarget height in pixels (combined with w, crops to cover the box)
qnumberOutput quality 1–100 (default 85; ignored for PNG)
f'webp' | 'jpeg' | 'png' | 'avif'Converts the output format
downloadbooleanForces a browser download via Content-Disposition
thumbnailbooleanExtracts the first frame of an animated/video asset before resizing

Rich text

---
import LocalessRichText from '@localess/astro/LocalessRichText.astro';
---

<LocalessRichText content={data.body} />
PropTypeDescription
contentLocalessRichTextInputThe 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
renderersLocalessRichTextRenderers<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.

@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.typeResult
"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)

ExportKindDescription
localess / localessIntegrationFunctionThe Astro Integration factory — registered in astro.config.mjs
getLocalessClient()FunctionReturns the LocalessClient built by the integration. Throws if localess() isn't configured
getLivePayload(astroGlobal)FunctionRetrieves draft content stashed by the live-preview middleware, for the livePreview tier
resolveAsset(asset, params?)FunctionResolves a ContentAsset to a full CDN URL, with optional transform params
localessEditable(data)FunctionReturns data-ll-id/data-ll-schema attributes to spread on a component's root element
localessEditableField(fieldName)FunctionReturns a data-ll-field attribute to spread on an editable field
renderLocalessRichTextToHtml(content)FunctionConverts a ContentRichText object to an HTML string
toCamelCase(str)FunctionThe key-normalization function used to match _schema values to registry keys
handleLocalessMessage(event)FunctionThe livePreview tier's sync-event handler, injected automatically — exported for advanced/manual use
loadLocalessSync(origin)FunctionLoads the Visual Editor sync script; used internally by both sync tiers
isBrowser() / isIframe()FunctionEnvironment checks re-exported from @localess/client
LocalessApiErrorClassThrown when the API responds with a non-2xx status code
LocalessSchemaProps<T>TypeProps 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>TypeProps 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, ...TypesRe-exported content and configuration types

Subpath exports (.astro components)

ExportDescription
@localess/astro/LocalessComponent.astroDynamically resolves and renders the registered component for data._schema
@localess/astro/LocalessDocument.astroRenders a full Content response via LocalessComponent
@localess/astro/LocalessRichText.astroRenders a ContentRichText field to HTML
@localess/astro/FallbackComponent.astroThe built-in fallback, used when customFallbackComponent is omitted

On this page