Starlight setup
Starlight is a documentation theme built on Astro that provides a complete solution for creating technical documentation sites. This guide covers the setup process used in this repository, including project initialization, content organization, and automated deployment to GitHub Pages.
Prerequisites
Section titled “Prerequisites”- Node.js (version 18 or higher)
- npm or another Node.js package manager
- Git repository hosted on GitHub
- Basic familiarity with markdown
Initial setup
Section titled “Initial setup”Install dependencies
Section titled “Install dependencies”Create a docs/ directory in your repository and initialize an Astro project with Starlight:
mkdir docscd docsnpm create astro@latest . -- --template starlightThe Starlight template includes the necessary dependencies:
{ "dependencies": { "@astrojs/starlight": "^0.36.2", "astro": "^5.6.1", "sharp": "^0.34.2" }}The sharp package is required by Astro for image optimization.
Project structure
Section titled “Project structure”The Starlight template creates this structure:
docs/├── astro.config.mjs # Astro and Starlight configuration├── package.json # Dependencies and build scripts├── tsconfig.json # TypeScript configuration├── public/ # Static assets (favicon, images)│ └── favicon.svg└── src/ ├── assets/ # Images to embed in markdown ├── content.config.ts # Content collections configuration └── content/ └── docs/ # All documentation markdown files └── index.mdx # HomepageAll documentation content goes in src/content/docs/. This directory can contain markdown files (.md or .mdx) organized in subdirectories.
Basic configuration
Section titled “Basic configuration”Edit astro.config.mjs to configure your documentation site:
import { defineConfig } from 'astro/config';import starlight from '@astrojs/starlight';
export default defineConfig({ integrations: [ starlight({ title: 'My Documentation', description: 'Site description for SEO',
social: [ { icon: 'github', label: 'GitHub', href: 'https://github.com/username/repository' }, ],
sidebar: [ { label: 'Guides', items: [ { label: 'Getting started', slug: 'guides/getting-started' }, ], }, ], }), ],});Configuration options:
title: Site title displayed in the headerdescription: Site description for search enginessocial: Social links displayed in the header (supports github, gitlab, discord, twitter, and more)sidebar: Manual navigation configuration
Development and build scripts
Section titled “Development and build scripts”The template includes npm scripts in package.json:
{ "scripts": { "dev": "astro dev", "build": "astro build", "preview": "astro preview" }}Run the development server:
npm run devBuild for production:
npm run buildThe build output is generated in the dist/ directory.
Content organization
Section titled “Content organization”Directory structure
Section titled “Directory structure”Organize documentation files in topic-based subdirectories:
src/content/docs/├── index.mdx├── guides/│ ├── getting-started.md│ └── advanced.md├── api/│ ├── overview.md│ └── reference.md└── examples/ └── basic-usage.mdEach subdirectory can represent a navigation category in the sidebar.
File naming conventions
Section titled “File naming conventions”- Use lowercase with underscores for multi-word file names:
getting_started.md - File names become URL slugs:
getting_started.md→/getting_started/ - Use
.mdfor standard markdown files - Use
.mdxwhen importing components
Markdown frontmatter
Section titled “Markdown frontmatter”Each markdown file requires frontmatter with at least a title:
---title: Page titledescription: Page description for SEO and previews---
Content starts here.For the homepage, use the splash template:
---title: Site titledescription: Site descriptiontemplate: splashhero: title: Hero title tagline: Hero subtitle or description actions: - text: Primary action link: /path/to/page/ icon: right-arrow variant: primary - text: Secondary action link: https://external-site.com icon: external variant: secondary---The splash template provides a hero section with call-to-action buttons.
Sidebar configuration
Section titled “Sidebar configuration”Configure the sidebar navigation in astro.config.mjs:
sidebar: [ { label: 'Category name', items: [ { label: 'Page title', slug: 'directory/filename' }, { label: 'Another page', slug: 'directory/other-file' }, ], }, { label: 'Another category', items: [ { label: 'Page', slug: 'other-directory/page' }, ], },],Sidebar features:
- Groups are defined with
labelanditems - Items reference content using
slug(file path without extension, relative tosrc/content/docs/) - Order is explicitly controlled
- Nesting is supported for subcategories
Starlight components
Section titled “Starlight components”Starlight provides built-in components for common documentation patterns. To use them, import in .mdx files:
---title: Page title---
import { Card, CardGrid } from '@astrojs/starlight/components';
<CardGrid> <Card title="Feature one" icon="puzzle"> Description of the first feature. </Card> <Card title="Feature two" icon="pencil"> Description of the second feature. </Card></CardGrid>Available components:
CardandCardGrid: Display features or links in a grid layoutTabsandTabItem: Create tabbed content sectionsAside: Highlight notes, tips, warnings, or cautionsCode: Enhanced code blocks with additional features
Refer to the Starlight components documentation for the complete list.
GitHub Pages deployment
Section titled “GitHub Pages deployment”Repository configuration
Section titled “Repository configuration”Enable GitHub Pages in your repository settings:
- Navigate to Settings → Pages
- Under “Build and deployment”, select “GitHub Actions” as the source
GitHub Actions workflow
Section titled “GitHub Actions workflow”Create .github/workflows/deploy.yml:
name: Deploy to GitHub Pages
on: push: branches: [ main ] workflow_dispatch:
permissions: contents: read pages: write id-token: write
jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v5
- name: Install, build, and upload site uses: withastro/action@v5 with: path: ./docs
deploy: needs: build runs-on: ubuntu-latest environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4Workflow explanation:
on.push.branches: Triggers on pushes to the main branchon.workflow_dispatch: Allows manual workflow executionpermissions: Grants necessary permissions for GitHub Pages deploymentwithastro/action@v5: Handles Node.js setup, dependency installation, Astro build, and artifact uploadpath: ./docs: Specifies the subdirectory containing the Astro projectdeploy-pages@v4: Deploys the built site to GitHub Pages
The withastro/action simplifies the workflow by combining multiple steps:
- Set up Node.js
- Install dependencies with npm
- Run
npm run build - Upload the build artifact
Site URL configuration
Section titled “Site URL configuration”For GitHub Pages deployment, configure the site URL in astro.config.mjs:
export default defineConfig({ site: 'https://username.github.io', base: '/repository-name',
integrations: [ starlight({ // ... other configuration }), ],});Configuration:
site: Base URL for GitHub Pages (organization or user URL)base: Repository name as subpath
Internal links in content must include the base path:
[Link to page](/repository-name/guides/getting-started/)Customization
Section titled “Customization”External links configuration
Section titled “External links configuration”Configure external links to open in new tabs using rehype plugins. Install the plugin:
npm install rehype-external-linksConfigure in astro.config.mjs:
import { defineConfig } from 'astro/config';import starlight from '@astrojs/starlight';import rehypeExternalLinks from 'rehype-external-links';
export default defineConfig({ markdown: { rehypePlugins: [ [ rehypeExternalLinks, { target: '_blank', rel: ['noopener', 'noreferrer'] } ] ], },
// ... rest of configuration});This configuration:
- Opens external links in new tabs (
target: '_blank') - Adds security attributes (
rel: ['noopener', 'noreferrer']) - Applies to all markdown content automatically
Favicon customization
Section titled “Favicon customization”Replace the default favicon in public/favicon.svg with your own icon. Supported formats:
- SVG (recommended, adapts to light/dark mode)
- PNG or ICO (standard formats)
For SVG favicons that adapt to the color scheme:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"> <style> path { fill: #000; } @media (prefers-color-scheme: dark) { path { fill: #fff; } } </style> <path d="..." /></svg>Theme customization
Section titled “Theme customization”Starlight provides theming options in astro.config.mjs:
starlight({ customCss: [ './src/styles/custom.css', ],
expressiveCode: { themes: ['github-dark', 'github-light'], },})Customization options:
customCss: Load custom CSS files for styling overridesexpressiveCode.themes: Configure code block themes for light and dark modeslogo: Add a custom logo to the headerfavicon: Specify a custom favicon path
Refer to the Starlight customization documentation for advanced theming options.
Related guides
Section titled “Related guides”- GitHub Actions basics: Understanding GitHub Actions workflows
- Semantic commits: Commit message conventions for documentation changes