qwik-docs generates your site's pages from your content, with layout and metadata controlled through Markdown frontmatter. Pages render through Qwik City, so you also have full access to Qwik City's file-based routing for anything the content collection does not cover. This guide shows how page generation works in qwik-docs.

Content pages

File formats

qwik-docs supports authoring content in Markdown and MDX with no configuration required. See the authoring content guide for the supported syntax.

Add pages

Content lives in collection directories that are mapped to URL prefixes in qwik-docs.config.ts. See Project Structure and the configuration reference for how directories map to URLs.

To add a page, create a .md or .mdx file in a collection directory. Use sub-folders to organize your files and to create multiple path segments.

For example, with the guides collection mapped under /docs/guides, the following files generate pages at example.com/docs/guides/hello-world and example.com/docs/guides/reference/faq:

  • content/
    • guides/
      • hello-world.mdx
      • reference/
        • faq.mdx

Validated frontmatter

All qwik-docs pages share a customizable common set of frontmatter properties to control how the page appears:

---
title: Hello, World!
description: This is a page in my qwik-docs-powered site
---

qwik-docs validates frontmatter at build time. A malformed optional field falls back to its default; a structural error fails the build and names the file.

Unlike Astro Starlight, there is no slug frontmatter field. A content page's slug comes from its file path and its collection's URL prefix.

Custom pages

For pages the content collection does not cover, add a normal Qwik City route under src/routes/. Qwik City uses file-based routing: a src/routes/<path>/index.tsx file becomes a page at /<path>. This is helpful when you need a completely custom layout or a page generated from an alternative data source.

The documentation content itself renders through one catch-all route at src/routes/docs/[...slug]/index.tsx. Any route you add beside it is a custom page:

  • src/
    • routes/
      • docs/
        • [...slug]/
          • index.tsx
      • custom/
        • index.tsx

Read more in the "Routing" guide in the Qwik docs.

Using the docs design in custom pages

Astro Starlight wraps custom pages in a <StarlightPage> component. qwik-docs has no single wrapper component. Instead, build the page's route data with generateRouteData and render it inside <DocsProvider> and <Page> — the same pieces the catch-all route uses. This is helpful when you generate content dynamically but still want the docs design.

// src/routes/custom/index.tsx
import { component$ } from '@builder.io/qwik';
import { routeLoader$ } from '@builder.io/qwik-city';

import { entries } from 'virtual:qwik-docs/content';
import siteConfig from 'virtual:qwik-docs/config';
import { generateRouteData } from '@qwik-docs/framework';
import { DocsProvider, Page } from '@qwik-docs/framework/components';

export const useRouteData = routeLoader$((event) =>
	generateRouteData({
		config: siteConfig as any,
		entries,
		// `title` is the only field that matters here; the rest take their defaults.
		page: { frontmatter: { title: 'My custom page' } as any, headings: [], slug: 'custom' },
		pathname: event.pathname,
		base: import.meta.env.BASE_URL,
	}),
);

export default component$(() => {
	const data = useRouteData();
	return (
		<DocsProvider data={data.value}>
			<Page>
				<div class="sl-markdown-content">
					<p>This is a custom page with the docs layout.</p>
				</div>
			</Page>
		</DocsProvider>
	);
});

The following behaviors differ from content pages:

  • The slug is not derived for you. Pass it explicitly. It sets the raw-Markdown URL and the current-page match.
  • The edit link needs a source file. Without a sourcePath, no edit link is generated unless you set frontmatter editUrl to a string.
  • A custom page is not part of a content collection, so it will not appear in autogenerated sidebar groups. Add it to the sidebar config manually.
  • The draft option excludes the page from production builds. It is served in dev.

generateRouteData options

generateRouteData builds the full route data — sidebar, pagination, table of contents, edit URL, and head tags — from a page and the site config. It accepts the following options.

config

required
type: resolved site config

The resolved site config, imported from virtual:qwik-docs/config.

entries

required
type: ContentEntryMap

The content entry map, imported from virtual:qwik-docs/content. Used to derive the sidebar and prev/next navigation.

page

required
type: { frontmatter: DocsFrontmatter; headings: MarkdownHeading[]; slug: string; sourcePath?: string }

The current page. frontmatter.title is required; all other frontmatter fields take their defaults. Provide headings to generate a table of contents.

pathname

required
type: string

The request pathname. Pass event.pathname from the route loader. Used to mark the current sidebar entry and to derive prev/next links.

base

type: string
default: '/'

The deploy base path. Pass import.meta.env.BASE_URL so links stay correct when the site is served from a subfolder.

locale

type: string
default: none

The active locale, when the site is localized.

<AnchorHeading> component

In Markdown and MDX, qwik-docs adds anchor links to headings automatically through its rehype pass. Headings you hand-author as JSX in a custom route do not pass through that pass, so they get no anchor link and do not match the Markdown heading styling.

Use the <AnchorHeading> component for this case. It renders a heading with a clickable anchor link that matches the Markdown styles. It is ported from Astro Starlight.

import { AnchorHeading } from '@qwik-docs/components/qwik/AnchorHeading';

<AnchorHeading level={2} id="learn-more" html="Learn more" anchorLabel="Section titled Learn more" />;

The component takes an explicit id because there is no auto-slugging in a custom page. Its props differ from Astro Starlight's version, because Mitosis cannot render a dynamic heading tag: the heading renders as a <div role="heading"> with the matching aria-level, not a native <h1>–<h6>, and the content is passed as an HTML string rather than as children.

level

required
type: number

The heading level, 1 to 6. Sets the size class and the aria-level.

id

required
type: string

The anchor target. The link points at #<id>.

html

required
type: string

The heading content, as an HTML string. It is rendered through innerHTML; there is no children slot.

anchorLabel

type: string

Accessible label for the anchor link, read by screen readers.