Initializing an Astro + Starlight Project
Initializing an Astro + Starlight Project
Section titled “Initializing an Astro + Starlight Project”Overview
Section titled “Overview”This section walks through the exact steps to create a new Astro + Starlight documentation site from scratch. By the end, you’ll have a running local development server with a working documentation site.
Q: What do I need before starting?
Section titled “Q: What do I need before starting?”A: Ensure you have:
- Node.js v22+ installed (check with
node --version) - npm (comes with Node.js)
- A code editor (VS Code recommended, with the Astro extension)
Q: How do I create the project?
Section titled “Q: How do I create the project?”A: Use the official Astro CLI to scaffold the project:
# Create a new Astro project with Starlight templatenpm create astro@latest my-docs -- --template starlight
# Navigate into the projectcd my-docs
# Install dependenciesnpm install
# Start the development servernpm run devThe CLI will ask a few questions:
- TypeScript: Choose “Strict” for type safety
- Install dependencies: Yes
- Git repository: Yes (initialize a Git repo)
Once running, open http://localhost:4321 to see your new documentation site.
Q: What does the initial project structure look like?
Section titled “Q: What does the initial project structure look like?”A: After scaffolding, your project contains:
my-docs/├── src/│ ├── content/│ │ └── docs/ # Your documentation content goes here│ │ ├── index.md # Homepage│ │ └── guide.md # Example guide page│ └── content.config.ts # Content collection configuration├── public/ # Static assets (images, favicon, etc.)├── astro.config.mjs # Astro + Starlight configuration├── package.json└── tsconfig.jsonQ: How do I configure the basic site settings?
Section titled “Q: How do I configure the basic site settings?”A: Edit astro.config.mjs:
import { defineConfig } from 'astro/config';import starlight from '@astrojs/starlight';
export default defineConfig({ site: 'https://docs.yourcompany.com', integrations: [ starlight({ title: 'My Product Docs', social: [ { icon: 'github', label: 'GitHub', href: 'https://github.com/yourcompany' }, ], sidebar: [ { label: 'Guides', items: [{ autogenerate: { directory: 'guides' } }], }, { label: 'Reference', items: [{ autogenerate: { directory: 'reference' } }], }, ], }), ],});Key settings:
site: Your production URL (used for sitemaps and SEO metadata)title: Displayed in the header and browser tabsidebar: Defines the navigation structureautogenerate: Automatically generates sidebar items from a directory of Markdown files
Q: How do I add my first content page?
Section titled “Q: How do I add my first content page?”A: Create a Markdown file in src/content/docs/:
---title: Getting Starteddescription: Learn how to set up and configure the product.---
## Getting Started
Welcome to the documentation! This guide will help you get up and running.
### Installation
Install the software using npm:
\```bashnpm install my-product\```
### Configuration
Create a configuration file `config.yaml`:
\```yamlport: 8080database: host: localhost port: 5432\```
### Next Steps
- Read the [API Reference](/reference/api/)- Check out [example projects](/guides/examples/)The title in the frontmatter is required. Starlight uses it for the page title, sidebar label, and SEO metadata.
Q: What is the difference between index.md and other files?
Section titled “Q: What is the difference between index.md and other files?”A: Each directory can have an index.md that serves as the directory’s landing page:
src/content/docs/├── index.md # Site homepage (with hero section)├── guides/│ ├── index.md # Guides section landing page│ ├── setup.md # /guides/setup/│ └── examples.md # /guides/examples/└── reference/ └── api.md # /reference/api/The root index.md can use the splash template for a hero landing page:
---title: Hometemplate: splashhero: title: My Product Documentation tagline: Everything you need to build with My Product. actions: - text: Get Started link: /guides/setup/ variant: primary - text: View on GitHub link: https://github.com/yourcompany variant: secondary---We provide ESP32 ODM design-to-manufacturing services. From prototype to production — the team behind this tutorial can build it with you.
Talk to us →