Skip to content
Search
Search the documentation
Configuration
GitHub
12 min read

Configuration

Package exports, the docsmith() options, and the two shell components.

Everything you wire up once: what the package exports, the one docsmith() call that configures the whole site, and the two page-level components that own the site chrome. Props for the authoring components (Callout, Tabs, Badge, and the rest) live on their own pages in the Components section.

Package exports

  • svelte-docsmith: every component, plus createSearchEngine and the types. Components are documented in Components; the rest is below.
  • svelte-docsmith/server: ready route handlers for the files a site serves besides its pages: sitemap, changelogFeed, llmsTxt, llmsFullTxt, agentMarkdown (the .md page twins), ogImages and mcpServer. Each is one line in a +server.ts that reads your site config itself (see SEO, Changelog and MCP server). Server-only.
  • svelte-docsmith/vite: the docsmith() Vite plugin, the one place a site is configured. It compiles markdown pages, builds the content, search, llms and changelog indexes, and serves the ?source and ?props imports.
  • svelte-docsmith/site: your site config, the site options of docsmith(), exported as site, with the resolved outside paths as outside and the repo’s star count as githubStars. DocsShell, ErrorPage and the route handlers read it themselves; import it when a page of your own needs the title or links.
  • svelte-docsmith/reader-events: your reader event handler, the default export of the module readerEvents names, which the components report to. You never import it directly.
  • svelte-docsmith/content: the generated sidebar index. Its content export (the pages as docs plus the version manifest as versions) is what DocsShell and ErrorPage take.
  • svelte-docsmith/search: the generated full-text search index, exported as docs (lazy-load it; see Search).
  • svelte-docsmith/llms: the generated per-page agent markdown index, with props tables and example code written out, exported as docs (see SEO).
  • svelte-docsmith/changelog: the generated release index, exported as releases, with the route it is served at as changelogPath (see Changelog).
  • svelte-docsmith/mermaid: the diagram component, imported for you by a ```mermaid fence. You never import it directly.
  • svelte-docsmith/theme.css: the base style contract.
  • svelte-docsmith/themes/*.css: the presets as theme files. Choose one with theme rather than importing it (see Theming).

docsmith()

From svelte-docsmith/vite, added to plugins in vite.config.ts before sveltekit(). It is the only place your docs are configured: it compiles your markdown pages, scans them into the generated indexes, serves the ?source imports that Live Examples use and the ?props imports behind generated Props Tables, and serves your site config to the shell and the route handlers. Only site.title is required.

vite.config.ts
			import { docsmith } from 'svelte-docsmith/vite';

export default defineConfig({
	plugins: [
		docsmith({
			site: {
				title: 'My Library',
				description: 'A short tagline, used as the default meta description.',
				url: 'https://my-library.dev',
				github: 'https://github.com/you/my-library'
			},
			markdown: { lineNumbers: true }
		}),
		tailwindcss(),
		sveltekit({ extensions: ['.svelte', '.md'], adapter: adapter() })
	]
});
		

The options are checked when Vite starts, so a mistyped option fails dev and build with a message that names it. Because they live in vite.config.ts, editing them restarts the dev server.

docsmith()
site required DocsmithSite
The site config: title, links, SEO defaults. See site below.
content string default 'src/routes/docs'
Directory scanned for doc pages.
routes string default 'src/routes'
Routes root, used to derive each page's URL from its location.
versions DocsVersions
The current version and the archived ones. See Versioning. Experimental.
theme string default 'darkmatter'
The site's theme: a preset name ('ocean') or a path to a theme file ('./src/theme.css'), relative to the Vite root. See Theming.
codeTheme { light: string; dark: string }
An exact pair of Shiki themes, one per colour mode, for every code block: markdown fences and the source panels of Live Examples alike. Leave it out and code blocks follow the theme. Replaces themes, which still works until the next minor.
markdown DocsmithMarkdownOptions
How markdown pages are compiled. See markdown below.
changelog { file?: string; path?: string }false
Where the changelog comes from and where it is served. file is the changelog that feeds the release index (default 'CHANGELOG.md'; point it at the package you publish). path is the route it is served at (default '/changelog'): the feed from changelogFeed() links there, and hand-written per-release pages are found under it. false skips the changelog.
tsconfig string default 'tsconfig.json'
The tsconfig used to read prop types for ?props imports, relative to the Vite root. Experimental.
schema StandardSchemaV1
A schema for your pages' custom fields: Zod, Valibot, ArkType or any other Standard Schema. The built-in fields are checked with or without one. See Validating frontmatter.
links DocsmithLinksOptions
How the links doc pages write are checked, and which paths something other than this app serves. See links below.
readerEvents string
Path to your reader event handler module, relative to the Vite root. Its default export receives every reader event (feedback votes, searches, 404s, copies) in the browser, to forward to your analytics. A missing file fails at startup. See Reader events.

site

What the header, footer and head tags show. The plugin serves it as svelte-docsmith/site, where DocsShell, ErrorPage and the route handlers read it, so you never pass it around. It reaches the browser as JSON, so it must be plain data: strings, numbers, booleans, arrays and plain objects.

site
title required string
Site title, shown in the header/sidebar and as the <title> suffix.
description string
Default meta description, used for pages without their own. See SEO.
url string
Canonical site origin. Enables <link rel="canonical"> and absolute Open Graph URLs.
ogImage string
Default social-share image (absolute, or a path resolved against url). With ogImages set, only pages that aren't doc pages use it.
ogImages string
Path your OG images are served under, e.g. /og. Each doc page's social-share image becomes its own, at /og/<page path>.png.
editUrl string
Base URL for the per-page “Edit this page” link, e.g. https://github.com/you/repo/edit/main/apps/docs. Each page's source path is appended. (“Last updated” is added from git automatically.)
mcp string
Path of your MCP server, e.g. /mcp, or a full URL. Adds “Connect to your editor” to the copy-page menu. Experimental.
github string
GitHub URL; renders a link in the header when set. A https://github.com/owner/repo URL also shows the repo's star count.
githubStars boolean default true
Show the star count beside the header GitHub link. Set false to skip both the build-time fetch and the browser fallback, and show the bare link.
version string
Version string shown in the header.
logo string
Logo image src; falls back to the built-in book mark.
nav DocsmithLink[]
Top-level header navigation links.
announcement { text, tag?, href?, external?, id?, dismissible? }
A thin bar above the header. text is required; add a tag for a leading pill (e.g. "New") and an href to link it. It's dismissible by default and stays dismissed until you change id (or the text), so bump id to re-show a new announcement.
footer { copyright?, columns?, poweredBy? }
Footer copyright line, titled link columns, and the “Powered by” toggle.

This site runs one: the thin bar above the header is site.announcement. Its id tracks the library version, so it returns after each release and stays out of the way in between. Dismiss it and it holds until the next version.

A page of your own can read the same config, for example a landing page that shows the site title:

			<script lang="ts">
	import { site } from 'svelte-docsmith/site';
</script>

<h1>{site.title}</h1>
		

GitHub stars

When github is a https://github.com/owner/repo URL, the header GitHub link shows the repo’s star count, like this site’s. Readers star the repo by clicking through to GitHub.

The plugin asks the GitHub API for the count once per build, and once each time vite dev starts, then serves it with the site config, so readers get it with the page and their browsers never call GitHub. Other hosts, and GitHub URLs that name no repo, get the plain link with no count.

GitHub allows 60 unauthenticated requests an hour per IP address, and CI and hosting build machines (Vercel, Netlify, GitHub Actions) often share one that has already used them up. When the build can’t get the count, it logs a warning and the header falls back to asking GitHub from each reader’s browser instead: one request per reader, cached in their browser for a day, so it stays well inside each reader’s own allowance. The count then appears just after the page loads. A failure there leaves the plain link, and never fails the build.

To bake the count in and skip the browser request, set a GITHUB_TOKEN environment variable in your build; the plugin sends it, which raises the limit to 5,000 an hour. A fine-grained token with no permissions is enough for a public repo. Set githubStars: false to turn the count off entirely, build and browser both.

A page of your own can show the build-time count too. githubStars is undefined whenever the build had none to show:

			<script lang="ts">
	import { githubStars, site } from 'svelte-docsmith/site';
</script>

{#if githubStars !== undefined}
	<a href={site.github}>★ {githubStars.toLocaleString('en')} on GitHub</a>
{/if}
		

markdown

How markdown pages are compiled. The plugin runs mdsvex, Shiki, heading anchors and the page layout over every .md file before SvelteKit compiles it, so markdown pages are real routes and there is no preprocessor to register. Every option has a working default.

markdown
extensions string[] default ['.md']
File extensions compiled as markdown. SvelteKit has to route them too, so list the same extensions in sveltekit({ extensions }); the plugin warns when one is missing.
langs string[]
Extra Shiki languages on top of the built-in set. An unknown fence language falls back to plain text rather than failing the build.
layout stringfalse
Absolute path to a custom mdsvex layout, or false for none. A custom layout must export a pre component from its module script, since code fences render through it. Under a custom layout, images are plain (no zoom or captions) and install blocks show their npm commands.
lineNumbers boolean default false
Number every code block. A fence overrides it either way with showLineNumbers or noLineNumbers.
twoslash boolean default false
Enable Twoslash on fences marked twoslash. Needs the optional peer dependencies; see Code blocks.
math boolean default false
Render $…$ and $$…$$ as formulas, written as MathML at build time. Needs the optional peer dependency temml; see Math.
remarkPlugins PluggableList
Extra remark plugins, appended after DocSmith's own.
rehypePlugins PluggableList
Extra rehype plugins, appended after DocSmith's own (slug, sectionize).

How the links your doc pages write are treated. vite build checks every link to a path under the docs base and, by default, fails on one with no page or anchor behind it. See Links for what counts as a broken link and a worked example of outside paths.

vite.config.ts
			docsmith({
	site: { title: 'My Library' },
	links: { broken: 'warn', outside: ['/playground'] }
});
		
links
broken 'error''warn''ignore' default 'error'
What a broken link does to vite build: 'error' prints every one and fails, 'warn' prints them and builds, 'ignore' skips the check. vite dev only ever warns.
outside string[] default []
Outside paths: same-origin path prefixes that something other than this app serves, like a Worker or a reverse proxy. Each starts with / and matches whole segments. A link to one is never broken, and doc pages and the shell's site config links mark it rel="external". See Outside paths.

DocsShell

The full documentation shell: header, sidebar, content area, and table of contents.

			<DocsShell {content}>
	{@render children()}
</DocsShell>
		

It reads the site config from svelte-docsmith/site itself. To replace its sidebar, table of contents, page header or pager, pass an override.

content required DocsContent
The content export of svelte-docsmith/content: every page, which the sidebar is derived from, and the version manifest, which scopes the sidebar, search, prev/next and breadcrumbs to the version being read (see Versioning). A bare docs array still works.
children required Snippet
The rendered page.
versions deprecated ResolvedVersion[] default []
Only read when content is a bare docs array. Pass the content export instead, which carries the versions.
search (versionId?: string) => Promise<SearchDoc[]>
Enable the ⌘K search palette by lazily providing the generated index, e.g. () => import('svelte-docsmith/search').then((m) => m.docs). Receives the active version id on a versioned site. See Search.
seo { title?: string; description?: string }
Override the head tags for this page (title, meta description). Doc pages get these from frontmatter automatically. See SEO.
logo Snippet
Custom logo mark for the header and mobile menu.
actions Snippet
Extra header controls, before the theme toggle.
footer Snippet
Content rendered below the page column.
pattern boolean default false
Render the decorative grid-and-glow page background.
copyPage boolean default false
Show the "Copy page" split button on doc pages (copy as Markdown, view the raw .md, or open in ChatGPT / Claude). Needs the .md endpoint. See SEO. With site.mcp set, it also offers “Connect to your editor”.
readingTime boolean default true
Show the estimated reading time on doc pages (computed at build time from the page's word count). Set false to hide it.
feedback boolean
Show the "Was this page helpful?" widget at the foot of doc pages. Omit to hide it. Votes reach your handler as feedback reader events. Passing a callback (vote, path) => void still works but is deprecated, and stops working in the next minor.
layout 'docs''page' default 'docs'
docs is the three-column shell; page is full-bleed content with the same header and footer but no sidebar or TOC.
sidebar Snippet<[SidebarProps]>
Override the sidebar, here and in the mobile menu. Receives { nav }. See Overrides.
toc Snippet<[TableOfContentsProps]>
Override the table of contents, here and in the mobile popover. Receives { items, activeId }. See Overrides.
pageHeader Snippet<[PageHeaderProps]>
Override the row above the page: breadcrumbs, reading time and Copy page. Receives { path, breadcrumbs, readingMinutes, copyPage }. See Overrides.
pager Snippet<[PagerProps]>
Override the previous and next links. Receives { prev, next }. See Overrides.

Colour mode needs no setup

ModeProvider and ModeToggle handle light and dark with no consumer wiring. DocsShell mounts the provider internally, so you never touch mode-watcher yourself. Use ModeProvider directly to wrap a page you build outside DocsShell. (They were called ThemeProvider and ThemeToggle; the old names still work until the next minor.)

ErrorPage

A styled 404 / error screen that keeps the site chrome (header, search, footer, theme). Drop it into a SvelteKit +error.svelte:

src/routes/+error.svelte
			<script lang="ts">
	import { content } from 'svelte-docsmith/content';
	import { ErrorPage } from 'svelte-docsmith';
</script>

<ErrorPage {content} home="/docs" homeLabel="Back to the docs" />
		

Like DocsShell, it reads the site config itself, so the chrome matches.

content DocsContent
Same content as DocsShell, so the header and footer nav still work, and an error under an archived prefix keeps that version's search scope and noindex.
status number default page.status
HTTP status. Defaults to the current page's status.
title string default from status
Heading. Defaults to “Page not found” for 404, else “Something went wrong”.
message string default page.error.message
Body line. Defaults to the error message, then a status-appropriate default.
home string default '/'
Where the primary action links.
homeLabel string default 'Back to home'
Label of the primary action.
versions deprecated ResolvedVersion[] default []
Only read when content is a bare docs array, as for DocsShell.
search (versionId?: string) => Promise<SearchDoc[]>
Enable the ⌘K palette on the error page (same loader as DocsShell).

Types

  • DocsmithSite: the site options above, as svelte-docsmith/site serves them.
  • DocsmithOptions / DocsmithMarkdownOptions / DocsmithChangelogOptions / DocsmithLinksOptions / BrokenLinksLevel: the options of docsmith(), from svelte-docsmith/vite.
  • DocsContentItem: a content-index entry with title, path, and optional section, order, description, toc, and data.
  • DocsCustomFields: the type of data, a page’s custom fields. Extend it to type yours. See Custom fields.
  • SearchDoc / SearchResult / SearchEngine: the search index entry and the shape returned by createSearchEngine.
  • ResolvedVersion: one entry of the generated version manifest. See Versioning.
  • DocsContent: the content export, { docs, versions }, that DocsShell and ErrorPage take.
  • SitemapOptions / SitemapEntry: what sitemap() in svelte-docsmith/server takes.
  • CalloutVariant / BadgeVariant: the intent unions for Callout and Badge.
  • ReaderEvent / ReaderEventHandler: a reader event and the handler’s type. Each event type is exported too (FeedbackEvent, FeedbackLinkEvent, SearchEvent, NotFoundEvent, PageActionEvent, CopyCodeEvent), with PageAction for the Copy page menu’s actions.
  • SidebarProps / TableOfContentsProps / PageHeaderProps / PagerProps: what each override receives, and the props of Sidebar, TableOfContents, PageHeader and Pager. NavGroup, NavItem, NavNode, Breadcrumb and TocItem are what they carry.

The vendored shadcn primitives and internal helpers (the TOC engine, the clipboard utility, the markdown renderer map) are not part of the public API and may change between releases.

Was this page helpful?