Skip to content

Astro

Install

bash
npm install alap astro

Setup

The Astro adapter wraps the <alap-link> web component with typed .astro components.

astro
---
import { AlapSetup, AlapLink } from 'alap/astro';
import config from '../alap-config';
---
<AlapSetup config={config} />

<p>Check out these <AlapLink query=".coffee">cafes</AlapLink>.</p>

The web component (<alap-link>) also works directly in Astro with zero extra code — it's a custom element, so Astro treats it as static HTML with a client-side script.

Components

<AlapSetup>

PropTypeDescription
configAlapConfigThe link configuration
configNamestringNamed config slot (for multi-config)
PropTypeDescription
querystringExpression to evaluate
configstringNamed config to use
Any HTML attributePassed through to <alap-link>

Examples

Multi-config:

astro
---
import { AlapSetup, AlapLink } from 'alap/astro';
import docsConfig from '../configs/docs-links';
import blogConfig from '../configs/blog-links';
---
<AlapSetup config={docsConfig} configName="docs" />
<AlapSetup config={blogConfig} configName="blog" />

<p>See the <AlapLink query=".api" config="docs">API docs</AlapLink>.</p>
<p>Or read <AlapLink query="@latest" config="blog">the latest post</AlapLink>.</p>

Direct web component (no Astro adapter):

astro
---
import { registerConfig, defineAlapLink } from 'alap';
import config from '../alap-config';
---

<script>
  registerConfig(config);
  defineAlapLink();
</script>

<alap-link query=".coffee">cafes</alap-link>

Styling

Since the Astro adapter renders <alap-link> web components, styling works the same way — --alap-* custom properties and ::part() selectors. See Web Component for the full CSS reference.