To build a knowledge base with Astro, store each help article as Markdown in a content collection, group articles by category with a typed schema, generate one static page per article and category, and add Pagefind for full-text search after the build. You get a help center that loads instantly, costs almost nothing to host, and is easy for both search engines and AI assistants to read.
This guide walks through a knowledge base Astro setup from an empty project to a deployed help center, with the code for each piece and the decisions that matter: when to use Starlight, how to structure categories, and how to keep articles current.
Key Takeaways
- A knowledge base is a set of short, task-focused articles grouped by category. Content collections model that directly.
- Use Starlight if you want a docs-style layout today; use plain Astro if the help center has to match your marketing site.
- Pagefind gives you static, client-side search with no server or paid search service.
- Add
updatedDateand a “was this helpful” link to every article so stale content is easy to spot.- Deploy
dist/to any static host. There’s no database to run.
Knowledge base vs documentation site
A knowledge base answers “how do I do X” for customers. Documentation explains how a product works for people building with it. The two overlap, but the shape is different, and that changes how you build it.
| Knowledge base | Documentation site | |
|---|---|---|
| Reader | Customers, support agents | Developers, integrators |
| Article length | Short, one task each | Long, reference-heavy |
| Navigation | Categories, search first | Sidebar, versioned sections |
| Typical pages | Home with search, category lists, articles | Guides, API reference, changelog |
| Success metric | Fewer support tickets | Successful integrations |
If your content is mostly reference material with a sidebar, Starlight is the faster route; the Starlight docs site guide covers that path. If it’s customer-facing help with a search box on the home page and articles grouped into topics, the custom approach below gives you more control.
Create the project
# Terminal
npm create astro@latest help-center
cd help-center
npx astro add sitemap
npm install -D pagefind
npm run dev
If you’d rather start from a finished design, the Astro documentation themes category has nine themes at the time of writing. Docs is built as a company support and help center, and Documentise is a documentation and knowledge base template for software products with a structured help center. Free options are good too: Starlight is Astro’s official docs framework with search, sidebar and dark mode built in, and Astro’s own starter templates give you a clean base to shape yourself.
Model articles and categories
Two collections cover most help centers: categories (a small data file) and articles (Markdown files that reference a category).
// src/content.config.ts
import { defineCollection, reference } from 'astro:content';
import { glob, file } from 'astro/loaders';
import { z } from 'astro/zod';
const categories = defineCollection({
loader: file('src/data/categories.json'),
schema: z.object({
title: z.string(),
description: z.string(),
order: z.number(),
}),
});
const articles = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/articles' }),
schema: z.object({
title: z.string(),
summary: z.string().max(160),
category: reference('categories'),
updatedDate: z.coerce.date(),
related: z.array(reference('articles')).default([]),
popular: z.boolean().default(false),
}),
});
export const collections = { categories, articles };
// src/data/categories.json
[
{ "id": "billing", "title": "Billing", "description": "Invoices, payment methods and refunds.", "order": 1 },
{ "id": "account", "title": "Your account", "description": "Sign-in, profile and security.", "order": 2 }
]
Making updatedDate required is deliberate. Help articles go stale when the product changes, and a required date forces someone to think about it on every edit. The content collections guide explains reference() and the file() loader in more depth.
A typical article stays short and task-focused:
---
# src/content/articles/update-payment-method.md
title: "Update your payment method"
summary: "Change the card or bank account used for your subscription."
category: "billing"
updatedDate: 2026-10-30
related: ["download-invoices"]
popular: true
---
1. Open **Settings > Billing**.
2. Select **Payment method**, then **Replace**.
3. Enter the new card and select **Save**.
The new method is used from your next invoice.
Build category and article pages
Each category gets a page listing its articles, and each article gets its own URL.
---
// src/pages/help/[category]/index.astro
import { getCollection } from 'astro:content';
import BaseLayout from '../../../layouts/BaseLayout.astro';
export async function getStaticPaths() {
const categories = await getCollection('categories');
const articles = await getCollection('articles');
return categories.map((category) => ({
params: { category: category.id },
props: {
category,
articles: articles
.filter((a) => a.data.category.id === category.id)
.sort((a, b) => a.data.title.localeCompare(b.data.title)),
},
}));
}
const { category, articles } = Astro.props;
---
<BaseLayout title={`${category.data.title} help`} description={category.data.description}>
<h1>{category.data.title}</h1>
<p>{category.data.description}</p>
<ul>
{articles.map((a) => (
<li><a href={`/help/${category.id}/${a.id}/`}>{a.data.title}</a><p>{a.data.summary}</p></li>
))}
</ul>
</BaseLayout>
---
// src/pages/help/[category]/[article].astro
import { getCollection, getEntries, getEntry, render } from 'astro:content';
import BaseLayout from '../../../layouts/BaseLayout.astro';
export async function getStaticPaths() {
const articles = await getCollection('articles');
return articles.map((article) => ({
params: { category: article.data.category.id, article: article.id },
props: { article },
}));
}
const { article } = Astro.props;
const { Content } = await render(article);
const category = await getEntry(article.data.category);
const related = await getEntries(article.data.related);
const updated = article.data.updatedDate.toLocaleDateString('en-US', { dateStyle: 'long' });
---
<BaseLayout title={article.data.title} description={article.data.summary}>
<nav aria-label="Breadcrumb"><a href="/help/">Help</a> / <a href={`/help/${category.id}/`}>{category.data.title}</a></nav>
<article data-pagefind-body>
<h1>{article.data.title}</h1>
<p class="meta">Updated {updated}</p>
<Content />
</article>
{related.length > 0 && (
<aside>
<h2>Related articles</h2>
<ul>{related.map((r) => <li><a href={`/help/${r.data.category.id}/${r.id}/`}>{r.data.title}</a></li>)}</ul>
</aside>
)}
</BaseLayout>
The data-pagefind-body attribute tells Pagefind to index only the article, so headers, footers and related links don’t pollute search results.
Add search with Pagefind
Search is the main way people use a knowledge base. Pagefind indexes your built HTML and ships a small client-side search UI, so you don’t need a search server or an API key.
// package.json (scripts)
{
"scripts": {
"dev": "astro dev",
"build": "astro build && pagefind --site dist",
"preview": "astro preview"
}
}
---
// src/components/HelpSearch.astro
---
<link href="/pagefind/pagefind-ui.css" rel="stylesheet" />
<div id="help-search"></div>
<script is:inline src="/pagefind/pagefind-ui.js"></script>
<script is:inline>
window.addEventListener('DOMContentLoaded', () => {
new PagefindUI({ element: '#help-search', showSubResults: true });
});
</script>
Put the search box at the top of the help home page, above the category grid. The index only exists after a build, so test search with npm run build && npm run preview rather than the dev server. The Pagefind search guide covers filters and styling, and Pagefind vs Algolia helps if you outgrow it.
The help center home page
The home page has three jobs: search, popular articles, and a way into each category.
---
// src/pages/help/index.astro
import { getCollection } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';
import HelpSearch from '../../components/HelpSearch.astro';
const categories = (await getCollection('categories')).sort((a, b) => a.data.order - b.data.order);
const popular = await getCollection('articles', ({ data }) => data.popular);
---
<BaseLayout title="Help center" description="Answers to common questions about billing, your account and more.">
<h1>How can we help?</h1>
<HelpSearch />
<h2>Popular articles</h2>
<ul>{popular.map((a) => <li><a href={`/help/${a.data.category.id}/${a.id}/`}>{a.data.title}</a></li>)}</ul>
<h2>Browse by topic</h2>
<div class="grid">
{categories.map((c) => (
<a href={`/help/${c.id}/`} class="card"><strong>{c.data.title}</strong><span>{c.data.description}</span></a>
))}
</div>
</BaseLayout>
Keep the popular list to five to eight articles and review it monthly against your support ticket tags. The articles people search for most should be one click from the home page.
Feedback and keeping articles current
A knowledge base rots without a feedback loop. The simplest version needs no JavaScript: a “Was this helpful?” pair of links that open your support tool or a form backend with the article slug prefilled.
---
// src/components/ArticleFeedback.astro
const { slug } = Astro.props;
const formUrl = import.meta.env.PUBLIC_FEEDBACK_URL ?? '/contact/';
---
<div class="feedback">
<p>Was this article helpful?</p>
<a href={`${formUrl}?article=${slug}&helpful=yes`}>Yes</a>
<a href={`${formUrl}?article=${slug}&helpful=no`}>No, I still need help</a>
</div>
Pair it with a review routine: once a quarter, list every article whose updatedDate is older than six months and check it against the current product. Because the date is in frontmatter, a short script or a filtered getCollection() call can produce that list. The form backends guide lists services that accept these submissions on a static site.
SEO and AI citations for help content
Help articles answer specific questions, which is exactly what search engines and AI answer engines look for. A few habits make them easier to cite:
- Put the answer in the first paragraph or the first numbered step.
- Use the customer’s wording in titles: “Update your payment method”, not “Payment instrument management”.
- Give every article a unique
summaryand use it as the meta description. - Add breadcrumbs and
ArticleorFAQPagestructured data where it fits. - Publish an
llms.txtthat lists your help categories so AI tools can find them.
The Astro SEO guide covers meta tags and sitemaps, and the llms.txt guide shows how to generate the file from your collections.
Deploy the knowledge base
Run npm run build (which now also builds the Pagefind index) and deploy dist/ to Cloudflare Pages, Netlify, Vercel or GitHub Pages. Our static deployment docs walk through each host. If the help center lives on a subdomain such as help.example.com, set site in astro.config.mjs to that URL so canonical links and the sitemap are correct.
For the official reference on collections and loaders, see the Astro content collections docs, and for search options, the Pagefind documentation.
FAQ
Is Astro good for a knowledge base?
Yes. A knowledge base is mostly static text organized by category, which is what Astro’s content collections and static output handle best. Pages load quickly, search runs client-side with Pagefind, and there’s no database or login to maintain.
Should I use Starlight or plain Astro for a help center?
Use Starlight if a documentation layout with a sidebar suits your content and you want search, navigation and dark mode working on day one. Use plain Astro when the help center needs a custom home page, category cards, or a design that matches your marketing site.
How do I add search to an Astro knowledge base?
Install Pagefind, run it after astro build with pagefind --site dist, and load its UI script on your help pages. It indexes your static HTML and searches in the browser, so it works on any static host without a search server.
Can non-developers edit an Astro knowledge base?
Yes, if you add a Git-based CMS such as Decap CMS, Keystatic or TinaCMS on top of your Markdown files. Editors get a form-based interface, and every change still becomes a commit that triggers a fresh static build.
How many articles can an Astro knowledge base handle?
Thousands. Content collections cache parsed entries between builds, and each article is a small static page. Build time grows with the number of pages, but a help center with a few thousand articles builds comfortably on standard CI and hosting plans.