Looking for our logo?
If you’re building a documentation site, your content needs to be easy to write and easy to search. Combining Astro’s Starlight framework with Algolia gives you the best of both! Let’s look at each of these tools, see when Algolia is the right fit, and learn how Starlight’s plugin system lets you add Algolia DocSearch.
Astro is a full-stack JS framework for building content-focused websites. Its claim to fame has been its support for any UI component framework (React, Vue, Svelte, etc), letting you bring the tools you know to build marketing sites, blogs, and yes, docs.
Starlight is an Astro theme specifically focused on documentation. This meta-framework offers first-class styling, internationalization, and support for popular content authoring formats like Markdown and MDX. The framework is also extensible, with options to override built-in components and introduce “plugins” that configure deeper internals.
Algolia DocSearch is a search service focused on dev tool documentation, trusted by popular web development tools like Vue.js and Laravel. Algolia crawls your site as a regular cron job. For search, you can embed Algolia’s ReactJS widget on your documentation site, and let Algolia manage search results for you.
Starlight uses a built-in, open-source search client by default, which works for anyone trying it for the first time or working on very small projects. However, Algolia DocSearch is worth the upgrade if:
Algolia DocSearch has an application form for free access. Once you’ve been approved, you can visit the DocSearch dashboard to set up your first website.
You will need a Starlight project deployed to production to try DocSearch. This should be the production URL you used when applying to DocSearch.
If you need a Starlight project, you can visit the quick start guide or clone our own Starwoof example. This is home to the Astro team’s diverse family of pets, meows and oinks included 🐷
The DocSearch Starlight plugin is available on npm:
# npm
npm install @astrojs/starlight-docsearch
# yarn
yarn add @astrojs/starlight-docsearch
# pnpm
pnpm install @astrojs/starlight-docsearch
Apply this plugin to the Starlight plugins
array in your astro.config.mjs
file:
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import starlightDocSearch from '@astrojs/starlight-docsearch';
export default defineConfig({
integrations: [
starlight({
title: 'Site with DocSearch',
plugins: [
starlightDocSearch({
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indexName: 'YOUR_INDEX_NAME',
}),
],
}),
],
});
You may prefer to load these variables from a
.env
file. Astro recommends using theloadEnv
utility for this (see documentation).
Note you will need three variables: an App ID, a Search API Key, and an index name.
The index name is attached to your crawler. This is created while registering your DocSearch account to scrape your website content and generate a search index. You’ll find your index name on your Algolia dashboard under the “Search” tab:
For your Application ID and API Key, visit the “Settings” tab:
Once these variables are defined, start the development server. You should see the Algolia search dialog appear when you hit /
on your keyboard:
Algolia DocSearch is an upgrade to Starlight’s built-in search for growing docs sites. If you need the analytics and SSR flexibility, apply to the DocSearch program. Happy doc-ing! 👋
Jaden Baptista
Technical WriterPowered by Algolia AI Recommendations