Guide

How to Build and Deploy a Docs Site With Astro Starlight

10 min read
How to Build a Starlight Docs Site: create the project, shape the sidebar, search with Pagefind, add languages, deploy from Git
Summarize with:
Share:

Astro Starlight is the official documentation theme for Astro. You create a project with npm create astro@latest -- --template starlight, write pages as Markdown in src/content/docs/, and get a sidebar, Pagefind search and multi-language support without extra setup. The build is plain static files in dist/, so you can deploy it from GitHub to any web server.

Writing docs is the easy part. The questions start when you want the sidebar in a specific order, search that works, a second language, and a site that updates every time someone merges a pull request. If you are new to Astro itself, our beginner’s guide to Astro JS covers the basics first.

This guide walks through each of those, then deploys the finished site from GitHub on xCloud.

TL;DR

  • Starlight is a docs theme built on Astro. Install it with the starlight template or npx astro add starlight.
  • Every .md, .mdx or .mdoc file in src/content/docs/ becomes a page. The sidebar is built from those files unless you configure it.
  • Search uses Pagefind with no setup, but only in a production build. It will not work under npm run dev.
  • Languages come from defaultLocale and locales in astro.config.mjs, with one folder per language.
  • Versioning is not built in. Use the community starlight-versions plugin or a folder per version.
  • A Starlight site needs no adapter. On xCloud it is detected as Astro and set to Static build with dist as the web root, with nothing to change in your repo.

A Starlight Repo Deploys on xCloud With No Changes

Here is the part most Starlight tutorials skip. When you connect a repository, xCloud reads your package.json. If it lists astro and no adapter, xCloud sets the site up as a Static build, runs npm run build and serves dist/. A fresh Starlight project is exactly that: astro, @astrojs/starlight, and a build script.

That matters for search. Pagefind builds its index during astro build, into the same dist/ folder. So the build xCloud runs on every push also rebuilds your search index. There is no second step to remember.

What your Starlight repo has What xCloud sets up What you need to do
astro + @astrojs/starlight, no adapter (the default) Static build, web root dist, build command npm run build Nothing. Deploy as is
A @astrojs/vercel, @astrojs/netlify or @astrojs/cloudflare adapter Static build, with a warning that the adapter is removed at deploy Nothing, unless some pages must render on request
The @astrojs/node adapter SSR (Node process) with node ./dist/server/entry.mjs Only add it if you have on-request pages
No build script in package.json A warning on the review screen Add "build": "astro build"

We use the same stack ourselves. xcloud.host is built with Astro, and the search on our docs runs on Pagefind, the engine Starlight ships with.

What Starlight Gives You

Starlight is a theme and an Astro integration in one. You write Markdown, and it supplies the documentation layout around it.

Out of the box you get:

  • A sidebar built from your files, with groups, badges and collapsible sections.
  • Full-text search through Pagefind, with no external service and no API key.
  • Multi-language pages, including right-to-left languages.
  • An “On this page” menu from your ## and ### headings, plus previous and next links.
  • Optional Edit page links (editLink) and Last updated dates from Git history (lastUpdated).

Because it is still Astro, you can drop components, MDX and your own pages into the same project. That is the main reason to pick Starlight over a docs-only tool. If you are weighing it against a React-based option, we also have a guide to deploying Docusaurus on xCloud.

What You Need Before You Start

You need Why
Node.js and npm on your computer To create the project and preview it
A GitHub, GitLab or Bitbucket repository xCloud deploys from Git
An xCloud server with the Nginx or OpenLiteSpeed stack To serve the built site (you can create one while you deploy)
A domain (optional) You can test on a free staging domain first

Check the Node.js version your Astro release requires before you start. If the server builds with an older version, you can change the site’s Node version later.

Create the Starlight Project

Run the Astro setup with the Starlight template:

npm create astro@latest -- --template starlight
cd my-docs
npm run dev

Already have an Astro site? Add Starlight to it with npx astro add starlight.

The parts of the project you will touch most:

Path What it holds
astro.config.mjs The Starlight integration and its options: title, sidebar, languages
src/content.config.ts The docs collection that Starlight reads
src/content/docs/ Your pages. Each .md, .mdx or .mdoc file becomes a URL
src/content/i18n/ Optional translations for interface text
public/ Files copied as is, such as a favicon or images

If you set Starlight up by hand, src/content.config.ts needs the docs collection:

import { defineCollection } from 'astro:content';
import { docsLoader } from '@astrojs/starlight/loaders';
import { docsSchema } from '@astrojs/starlight/schema';

export const collections = {
  docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
};

The only required option in the integration is title. Commit the project and push it to a new repository before you go further.

Shape the sidebar

With no sidebar config, Starlight lists every page using its title, sorted by file name. That works for ten pages. For more, group them in astro.config.mjs:

import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

export default defineConfig({
  integrations: [
    starlight({
      title: 'Acme Docs',
      sidebar: [
        { label: 'Start here', items: ['getting-started', 'install'] },
        { label: 'Guides', autogenerate: { directory: 'guides' } },
        { label: 'Reference', collapsed: true, autogenerate: { directory: 'reference' } },
        { label: 'Status page', link: 'https://status.example.com/' },
      ],
    }),
  ],
});

A plain string such as 'install' is a page slug, and its label defaults to the page title. autogenerate keeps a folder in sync as you add files. collapsed: true closes a group until the reader opens it.

To reorder or rename a page inside an autogenerated group, use its frontmatter:

---
title: Install the CLI
sidebar:
  label: Install
  order: 1
  badge:
    text: New
    variant: tip
---

Lower order numbers show higher up. These frontmatter options apply to autogenerated and slug entries, not to link entries.

Search that works after deploy

Search needs no setup: Starlight uses Pagefind by default. The catch is that Pagefind indexes your built HTML, so search is only available in a production build. Seeing “Search is only available in production builds” under npm run dev is expected.

To test it locally, run:

npm run build
npm run preview

To keep a page out of results, add pagefind: false to its frontmatter. To hide part of a page, add the data-pagefind-ignore attribute to that element. If you would rather use Algolia DocSearch, Starlight has an official plugin, @astrojs/starlight-docsearch.

Add a second language

Set a default language and list the others:

starlight({
  title: 'Acme Docs',
  defaultLocale: 'en',
  locales: {
    en: { label: 'English' },
    de: { label: 'Deutsch' },
    ar: { label: 'العربية', dir: 'rtl' },
  },
});

Then put each language in its own folder with the same file names: src/content/docs/en/install.md, src/content/docs/de/install.md. If a translation is missing, Starlight shows the default-language page with a notice that it is not translated yet. Want English without an /en/ prefix? Use a root locale and keep those pages directly in src/content/docs/.

Versioned docs

Starlight has no built-in versioning. You have two options:

  1. The starlight-versions plugin. It is listed in Starlight’s community plugins and adds versioned pages.
  2. A folder per version. Keep src/content/docs/v1/ and src/content/docs/v2/, and give each its own autogenerated sidebar group. This is simple and needs no plugin, but every fix has to be copied by hand.

For most products, documenting the current version and marking older behavior with a badge is enough. Add versioning when customers really run several major versions at once.

Deploy the Starlight Site From GitHub on xCloud

This is the same Astro flow covered in our Astro deployment doc, shortened for a Starlight repo.

Step 1: Choose Astro

Go to Sites and click Add New Site. On What would you like to host today?, click the Astro card. Then pick the server under Where should it run?

Click the Astro card on the “What would you like to host today?” screen in xCloud

Step 2: Add your repository

Paste your repository URL, or switch to Private Repository and pick it from your connected Git account. xCloud shows Native app with an Astro label and sets App Type to Node.js, because Astro builds with Node.js even when the result is static.

xCloud detects the repository as an Astro native app with the Node.js app type

Keep the free Staging domain (no DNS) to test first, and check that Branch is the branch you publish from.

Step 3: Check Build & serving

Under Build & serving, a Starlight repo shows Static build with Web root dist. Leave it unless you changed outDir.

Build & serving shows Static build with dist as the web root for a static Astro site

Click Deploy. xCloud pulls the code, installs dependencies, runs npm run build and publishes dist/. Open Deployments on the site: the latest one shows Deployed and LIVE.

The Deployments page shows the first Astro deployment as Deployed and LIVE

Now open the staging URL and search for a word from one of your pages. If results appear, the Pagefind index was built and served with the site.

Step 5: Publish on every merge

Turn on Auto-deploy on push (webhook). Each push to your branch then rebuilds the docs and the search index. Writers can edit Markdown in a pull request, and the docs update when it is merged. When you are ready, add your own domain and xCloud sets up a free SSL certificate. The one-click Git deployment guide covers the DNS options.

Common Starlight Deploy Problems

Symptom Likely cause Fix
Search works on the live site but not locally Pagefind only runs in a production build Use npm run build and npm run preview
Build fails on the server but works on your laptop The server builds with an older Node.js version Change the site’s Node version, then click Deploy Now
“No build script found” on the review screen package.json has no build script Add "build": "astro build"
A new page is missing from the sidebar Your sidebar is manual and the page is not listed List it, or use autogenerate for that folder
Last updated dates look wrong lastUpdated reads Git history, which can be inaccurate on shallow clones Check the dates after your first deploy, or turn the option off
A push does not start a deploy Webhook missing or branch mismatch See troubleshooting Git deployments

For more build failures, read why your Git deploy failed on xCloud. Missing URLs showing your homepage instead of a 404 is covered in our Astro deploy guide, with the Nginx rule that fixes it.

What xCloud Does (and Doesn’t Do) for a Starlight Site

✅ What xCloud does ❌ What it doesn’t do
Detects Astro and picks Static build with dist for a Starlight repo Write or translate your docs, or set up versioning for you
Runs npm run build on every push, so the search index stays current Serve from many regions by default: the site lives on your server (add a CDN if you need that)
Lists each deployment with its build steps Keep serverless adapter features: those adapters are removed and the site builds static
Free SSL, your own domain, and a staging domain to test Provide a docs editor: your writers work in Git or the CMS you connect

Nothing in your repository changes when you deploy on xCloud. If you move later, the same repo builds anywhere that runs astro build.

Host your docs next to your product

  1. Push your Starlight project to GitHub.
  2. Add it as an Astro site and check Static build with dist.
  3. Deploy to the staging domain, test search, then add docs.yourdomain.com.

Ready to ship? See Astro hosting on xCloud or static site hosting. Need a CMS for non-technical writers? Our list of the best CMS for Astro shows which ones rebuild your site on publish. Still choosing a framework? Read Astro vs Next.js.

Ship Your Starlight Docs This Week

Starlight takes care of the parts that usually eat a docs project: navigation, search and translations. Your job is to write the pages and choose a sidebar that matches how readers think.

Start with the template and a sidebar with two or three groups. Deploy it to a staging domain and test search on the built site. Then turn on auto-deploy, so every merged pull request updates the docs without anyone touching a server.

If you have found this blog helpful, feel free to subscribe to our blogs for valuable tutorials, guides, knowledge, and tips on web hosting and server management. You can also join our Facebook community to share insights and engage in discussions.

Sources: Starlight getting started, Starlight site search, Astro deploy guide.

Frequently Asked Questions

Is Astro Starlight free?

Yes. Starlight is an open-source documentation theme for Astro, installed from npm as @astrojs/starlight. You pay only for where you host the built site.

Does Starlight need a server or an adapter?

No. Starlight pre-renders every page by default, so astro build writes a folder of static files to dist/. You only need an adapter if you add pages that render on request.

Why does search not work when I run npm run dev?

Starlight’s built-in Pagefind search is only available in production builds. Run npm run build and npm run preview to test it locally, or check it on your deployed site.

Does Starlight support versioned documentation?

Not out of the box. Starlight’s plugin list includes the community plugin starlight-versions for versioned pages, or you can keep each version in its own folder and give it its own sidebar group.

How do I update my Starlight docs after they are live on xCloud?

Push to the branch you deployed. With Auto-deploy on push turned on, xCloud pulls the change, runs npm run build again and publishes the new dist/ folder, search index included. You can also click Deploy Now on the site.

← All articles