Astro Starlight
About Jamstack websites
Section titled “About Jamstack websites”The website you are viewing is a 1) JAMstack site, 2) generated using 3) Astro 4) Starlight.
- JAMstack sites are static websites (
HTML/CSS/JS) generated from dynamic content. When you publish a markdown file to Github and it transforms it into a webpage you are making a JAMstack site. JAM stands for Javascript + APIs + markup used to create the static website. - A Static Site Generator (SSG) is a tool that creates a static site using plain text files (usually Markdown
.mdor.mdx) and a collection of templates. - Astro is a Javascript framework capable of generating static (or dynamic) websites. You add content using markdown and Astro manages all the organization, building (creating HTML from MD files using templates), and publishing.
- Starlight is a documentation theme for Astro, adding templates, and components for navigation, search, and other features.
JAMstack benefits
Section titled “JAMstack benefits”- The frontend is static, so it displays information without latency.
- With no backend, the site runs faster, has better security, and hosting is cheap (even free).
- The site can scale easily and traffic static content can be offloaded to a CDN.
Example Astro Starlight websites
Section titled “Example Astro Starlight websites”- The Starlight documentation website https://starlight.astro.build/
- The Starlight site showcase https://starlight.astro.build/resources/showcase/
- Critical Web Design Wiki https://github.com/criticalwebdesign/wiki
- The Pokémon Database https://pokemon-siace.netlify.app/
- Pydocs https://www.pydocs.site/en
- Font Awesome Docs https://docs.fontawesome.com/
Watch an introduction to Astro
Section titled “Watch an introduction to Astro”Tutorial
Section titled “Tutorial”Instructions for creating a Starlight site from scratch
Create an Astro Starlight site
Section titled “Create an Astro Starlight site”Follow these steps from Starlight’s Getting Started tutorial
- Create new folder named
astro-testinside~/Documents/Github/ - Drag the folder into VS Code in the dock (Mac) to open the project.
- Run the following in a VS Code Terminal to start the installation
npm create astro@latest -- --template starlight- Where should we create your new project?
./ - Install dependencies?
Yes - Initialize a new git repository?
Yes - Once finished, run the development server then find your new site at: http://localhost:4321
npm run devUpdate project structure
Section titled “Update project structure”- Make a new folder called
schedulein/src/content/docs/ - Add a new file called
devlog-1-3.mdxinside/src/content/docs/schedule/ - To the top add a “frontmatter” section:
---title: DevLog 1-2description: DevLog page---- Below the frontmatter in
devlog-1-3.mdxadd this outline:
## Outcomes
1. Paste the code from the list ...1. ... of outcomes from the course schedule ...1. ... and update content where noted.
## Context
What ideas resonated with you?
- Citation: Author, Article (year)- Summary:- Quote:- Comment:- Question:
## Tech
What tech did you learn?
- Summary:- Alternatives: "An alternative to this method is ______"- Link(s) to outcomes:- Comments:- Questions:- In VS Code, open
astro.config.mjs - Set
titletoDevLog - Add
{ label: 'Schedule', autogenerate: { directory: 'schedule' }, },into thesidebarproperty
export default defineConfig({ integrations: [ starlight({ title: 'DevLog', ... sidebar: [ { label: 'Schedule', autogenerate: { directory: 'schedule' }, }, ], }), ],})- Add a
.gitignorefile to the main directory with the following
# build outputdist/# generated types.astro/
# dependenciesnode_modules/
# logsnpm-debug.log*yarn-debug.log*yarn-error.log*pnpm-debug.log*
# environment variables.env.env.production
# macOS-specific files.DS_StoreFork an Astro Starlight site
Section titled “Fork an Astro Starlight site”- Fork this repo into your own account https://github.com/omundy/dig345-devlog
- Clone the new repo to your computer. (i.e. Green button > Open in Github Desktop)
- Open the project in VS Code.
- In the terminal, install dependencies using
npm install - Run the development server with
npm run devand find your new site at: http://localhost:4321
Review Project structure
Section titled “Review Project structure”Inside your intial Astro + Starlight project, you’ll see the following folders and files:
- .gitignore
Directorypublic/ Static files
- …
Directorysrc/ All files in here will be processed by Astro
Directoryassets/ Static files processed by Astro
- …
Directorycontent/ In a regular Astro site these become routes
Directorydocs/
Directorycontents/ Folders/Files here become sections/pages in your site
- …
- index.mdx Site home page
- astro.config.mjs Astro Starlight config file
- package.json Meta information and project dependencies
- Starlight publishes
.mdand.mdxfiles in/src/content/docs/to the web using directory/filename (e.g.guides/example) /src/assets/- Place images here then embed them in Markdown with a relative link.public/- This directory is for static assets, like favicons.astro.config.mjs- The Astro config filepackage.json- This file contains your project dependencies as well as a list of commands for installing dependencies, starting, building, and testing Astro.
Publish Astro Starlight using Github Actions
Section titled “Publish Astro Starlight using Github Actions”- In Github Desktop, commit your work and push it to a new repository on Github. Leave it public.
- Open the repo web page Github Desktop > Repository > View on Github. Click Settings > Pages. Choose GitHub Actions as the Source of your site.
- In VS Code, open
astro.config.mjs- Set
siteto the github.io URL for your username. For example my username isomundy - Set
baseto the name of your repo. For example my repo isdig345-devlog
- Set
export default defineConfig({ site: 'https://omundy.github.io', base: '/dig345-devlog', integrations: [ starlight({ title: 'DevLog', sidebar: [ { label: 'Schedule', autogenerate: { directory: 'schedule' }, }, ], }), ],})- Create (or edit) a deploy file:
.github/workflows/deploy.yml. Note the period in front of.github. - Paste the YAML code from this page into
deploy.yml - Go to your published site at https://
USERNAME.github.io/dig345-devlog to verify the site is live.
Add custom CSS to your theme
Section titled “Add custom CSS to your theme”From Astro documentation
- Add a folder called
stylesto your/src/directory. - Add a file called
custom.cssto/src/styles/directory. - Paste in the following code. This will set a wider default column width and improve page titles:
/* set a wider default column width */:root { --sl-content-width: 50rem;}
/* improve headings */main h1 { font-size: 2rem;}main h2 { font-size: 1.8rem;}main h3 { font-size: 1.6rem;}main h4 { font-size: 1.4rem;}main h5 { font-size: 1.2rem;}main h6 { font-size: 1rem;}- Add the path to your CSS file to Starlight’s
customCssarray inastro.config.mjs:
export default defineConfig({ integrations: [ starlight({ title: 'DevLog', ... customCss: [ './src/styles/custom.css', // relative path to custom CSS file ], }), ],})Add an aside
Section titled “Add an aside”Use Starlight’s custom Markdown syntax to add an aside component.
:::caution[Github Actions]If you don't see your site check https://github.com/USERNAME/REPO/actions for issues.:::Import and use a Starlight component
Section titled “Import and use a Starlight component”Use Starlight’s built-in <Icon> component.
- Open an
.mdxfile and paste this content below the frontmatter.
import { Icon } from '@astrojs/starlight/components';
<Icon name="open-book" /> Learn more about [icons](https://starlight.astro.build/reference/icons/#all-icons)- Add this rule to
custom.css
.sl-markdown-content .inline-icon { display: inline;}- You should see this component rendered like so:
Learn more about icons
- Update the icon
References
Section titled “References”- Starlight Docs, Astro Docs
- Starlight Discord
- Starlight uses the Diátaxis approach to technical documentation authoring
- Build and deploy an Astro Starlight Documentation site to GitHub Pages
- Check out Starlight’s docs, read the Astro documentation
- A Complete Guide to Build a Documentation Site with Astro Starlight (2024)
Other static site generators
- Vitepress is a Vite & Vue Powered Static Site Generator
- Comparing docs site builders: VuePress vs Starlight
- Coding the Perfect Documentation: Deciding Between 🚀 Vitepress and ✨ Astro Starlight
Astro Starlight Topics
Section titled “Astro Starlight Topics”Not-Content
Section titled “Not-Content”The not-content CSS class disables Starlight’s default, automatic styling (e.g., margins, spacing) for the content inside it, preventing conflicts when you’re adding custom components or complex layouts that need precise control over spacing. Essentially, it tells Starlight, “Don’t touch these elements with your standard styles; let my component handle it”.
<div class="not-content"> <p>This paragraph won't have default Starlight margins.</p> <button>A custom button</button></div>Override a Starlight component
Section titled “Override a Starlight component”The most up to date instructions can be found here.
- Add a folder in
/src/components/ - Create a new file called
EmailLink.astroin/src/components/and add the following:
---const email = 'houston@example.com';---
<a href=`mailto:${email}`>E-mail Me</a>- Tell Starlight to use your custom component in the components configuration option in
astro.config.mjs:
export default defineConfig({ integrations: [ starlight({ title: 'DevLog', ... components: { // Override the default `SocialIcons` component. SocialIcons: './src/components/EmailLink.astro', }, }), ],});More Astro Notes
Section titled “More Astro Notes”See tutorials/astro