SvelteKit
SvelteKit passes web-standard Request objects to endpoints, so content.handler() plugs in with a one-line +server.ts. Server load functions can also skip HTTP entirely and read the Content instance in-process.
Install the packages
pnpm add comark-content @comark/sveltenpm install comark-content @comark/svelteyarn add comark-content @comark/sveltebun add comark-content @comark/svelteCreate the Content instance
Put the instance under $lib/server so SvelteKit guarantees it never reaches the browser bundle:
import { comarkContent } from 'comark-content'
import fs from 'comark-content/sources/fs'
export const content = comarkContent({
source: fs('./content'),
})Mount the handler
A catch-all endpoint hands SvelteKit's native Request straight to the handler:
import { content } from '$lib/server/content'
export const GET = ({ request }) => content.handler(request)Load and render a page
Server load functions read the Content instance in-process — no round-trip through the endpoint:
import { error } from '@sveltejs/kit'
import { content } from '$lib/server/content'
export async function load() {
const page = await content.get('/')
if (!page) error(404, 'content not found')
return { page }
}<script lang="ts">
import { MarkdownDocument } from '@comark/svelte'
let { data } = $props()
</script>
<MarkdownDocument value={data} />Map Markdown components to your own Svelte components through the components prop — see the Svelte renderer.
Optional: read from the browser
For client-side reads (e.g. instant search or navigation without a load round-trip), consume the endpoint with the browser client:
import { createContentClient } from 'comark-content/client'
export const contentClient = createContentClient()
// contentClient.get('/'), contentClient.list(), contentClient.navigation()Generate source types
Type content.get() from your frontmatter by generating source types:
npx comark-content prepare --config src/lib/server/content.tsAdd comark-content.d.ts to your tsconfig.json include — see Type Safety.