sveltekit demo

Source API

The source API is your interface to compiled documentation. Import the collection and use its methods in your SvelteKit load functions.

import { docs } from "virtual:docvia/source";

getPage

Fetch a single page by its slug segments:

const page = await docs.getPage(["getting-started"]);

// page.data      — frontmatter (title, description, tags, ...)
// page.content   — pre-compiled RenderOutput tree
// page.manifest  — hydration entries for interactive components
// page.headings  — array of { depth, text, id } for TOC
// page.url       — resolved URL path
// page.slugs     — slug segments as array

Usage in SvelteKit

// +page.server.ts
import { docs } from "virtual:docvia/source";
import { error } from "@sveltejs/kit";

export const load = async ({ params }) => {
  const slugs = params.slug?.split("/") || [];
  const page = await docs.getPage(slugs);
  if (!page) throw error(404, "Page not found");
  return { page };
};

getPages

Returns metadata for all pages in the collection:

const pages = docs.getPages();
// [{ slugs: ["getting-started"], url: "/getting-started", data: { title: "..." } }]

pageTree

A lazily-built navigation tree derived from your file structure:

const tree = docs.pageTree;
// { name: "docs", children: [...] }

Node types

TypeFieldsDescription
pagename, url, $idA navigable page
foldername, children, index?A directory with child pages
separatornameA visual divider

generateParams

Generates route parameters for SvelteKit prerendering:

// +page.server.ts
export const entries = () => {
  return docs.getPages().map(p => ({
    slug: p.slugs.join("/") || undefined,
  }));
};

TypeScript types

The collection is fully typed:

import type { docs_Frontmatter, docs_RouteKey } from "./.docvia/types";