Guides
From an empty database to an indexed, deployed search endpoint.
astro-d1-search turns your markdown into a Cloudflare D1
full-text index and gives your Astro site a search API on top of it.
There are three moving parts, and these guides walk through them in order:
- The integration — added to
astro.config.mjs. It injects the/api/searchroute and hands your ranking config to it. - The indexer — a build-time script that parses your content, generates SQL, and pushes it to
D1 through
wrangler. - The query layer — either the injected HTTP endpoint, or
searchIndex()called directly from a server-rendered page.
Prerequisites
- An Astro project using the
@astrojs/cloudflareadapter.output: 'static'is fine — only the search endpoint is server-rendered. - A Cloudflare account with
wranglerauthenticated locally (wrangler login). - Content as markdown or MDX files on disk. Astro content collections work as-is: the indexer reads the files directly rather than going through Astro's collection APIs.
In this section
Getting started
Install the package, create a D1 database, and get a working search endpoint.
Indexing content
How sources map files to URLs, which frontmatter is read, and what the markdown stripper keeps.
Search pages
Query D1 directly from a server-rendered Astro page, or hit the injected endpoint from the client.
Deploying
CI ordering, API token scopes, local development, and sharing one database across sites.
Examples
A real site running the package end to end, with links to every file involved.
Agent skill
Install the packaged skill so Claude Code and other coding agents can set this up for you.