Astro
Add cited search to an Astro site with one component. It registers a framework-free custom element, needs no React island, and works on static and server-rendered pages.
On this page
1Install
# Needs @docslurp/sdk 0.2.0 or newer.
npm install @docslurp/sdk@^0.3.0# The same component as a dedicated package.
npm install @docslurp/contrib-astro
# Then import:
# import DocSlurpSearch from '@docslurp/contrib-astro';2Create a browser key
On API keys, create a browser key with the search scope and add your site to its allowed websites. Only expose a workspace whose content is meant to be public.
# .env — PUBLIC_ values ship to the browser. Use a browser key (dslp_pub_), never a server key.
PUBLIC_DOCSLURP_CLIENT_KEY=dslp_pub_…3Add the component
---
import DocSlurpSearch from '@docslurp/sdk/astro';
---
<DocSlurpSearch
clientKey={import.meta.env.PUBLIC_DOCSLURP_CLIENT_KEY}
workspaceId="product-docs"
placeholder="Search the documentation…"
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
clientKey | string | Required | Browser key with the search scope, limited to your allowed websites. |
workspaceId | string | "default" | Workspace slug, UUID or default. |
apiUrl | string | "https://docslurp.io" | DocSlurp origin, for self-hosted deployments. |
placeholder | string | "Search documents…" | Input placeholder text. |
Styling
The element renders in a shadow root, so your site’s CSS won’t leak in. Theme it with two custom properties.
docslurp-search-box {
--docslurp-text: #e2e8f0;
--docslurp-background: #0b1220;
}Behavior
- Debounced search, Enter to submit
- Stale requests cancelled
- Accessible live status
- Source citations with page numbers
- Recoverable error state
- Reduced-motion waiting state
- No-JavaScript fallback text
- Results rendered as text, never HTML
Need a different look or your own result markup? Use one of the search adapters with your own component instead.
Hand off to an agent
Working in a real codebase? Copy a prompt that tells a coding agent exactly what to change for Astro: which entry point to use, the supported contract, and what to validate before shipping. It contains no keys or secrets.
Review agent instructions
Before switching traffic, run through the go-live checklist. Stuck? See troubleshooting.