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.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:

ParamTypeDescription
wnumberTarget width in pixels — whole number, 1–8192. Never upscales: a width above the source redirects to the source width
hnumberTarget 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)
qnumberOutput 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
thumbnailbooleanExtracts 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.

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} />
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
resolveAssetOriginal(asset)FunctionResolves a ContentAsset to the URL of the file exactly as uploaded
resolveAssetDownload(asset)FunctionResolves a ContentAsset to a URL that downloads the file as an attachment
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) / renderRichTextToHtml(content)FunctionConverts a ContentRichText object to an HTML string
normalizeComponentKey(key, strategy)FunctionThe key normalization used to match _schema values to registry keys under componentNaming
toCamelCase(str)FunctioncamelCase string helper — not used for matching unless componentNaming: 'camelCase'
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/live-preview
localessClient(options)FunctionCreates a standalone client — for build scripts that run outside the integration
LocalessApiErrorClassThrown when the API responds with a non-2xx status code
LocalessSync, EventToApp, EventToAppOf, EventToAppType, EventCallbackTypesVisual Editor sync event types
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