Skip to content

@ogygia/content

Content

@ogygia/content keeps what an ogygia app publishes as typed collections, from markdown, JSON, a CMS or another repository, and arranges them into pages and whole docs sites. The corpus stays on the server, and only plain data and rendered HTML reach the browser.

On this page

@ogygia/content is where an ogygia app keeps what it publishes: docs, blog posts, changelogs, product pages, entries in a CMS. You define a collection once, from a folder of markdown, JSON files, a CMS or a feed, and every entry comes out typed by your schema with an id, its data, and a body that renders as a region. An island imported inside a markdown file hydrates like any other island, and the rest of the prose ships none.

On top of collections, site() arranges them into a site: a sidebar, prev/next links, full-text search, a sitemap, llms.txt and a shell around each page. This docs site is built with it.

The whole design rests on one split. The corpus (compiled markdown, often megabytes) lives in server modules and never enters a browser bundle. What crosses to the browser is plain data, or a body already rendered to HTML.

Install

Install the package and list its content() plugin beside ogygia(). The markdown option turns on .md and .svx files; a collection of JSON or CMS data needs only content(). Its peer dependencies are shiki, @ogygia/core and @ogygia/compiler (plus Kit, Svelte and Vite, which you have). ogygia already brings the two @ogygia ones, so install shiki too if your package manager doesn’t add peers for you.

Markdown compiles through the svelte config, which takes the plugin’s preprocess() and extensions(); keep the rest of your config (your adapter, say) as it is. They take no options: every setting lives in content({ markdown }). Kit must load svelte.config.js after the plugin list is built; importing it at the top of vite.config.ts makes the plugin throw content_config_read_first.

The macros (import.meta.og.loader, code, md, regions) bring their own types: add the second line to src/ogygia.d.ts.

Nothing goes in hooks.server.ts. npx ogygia init --markdown writes all of this for a new app, and npx ogygia site init scaffolds a whole docs site (CLI commands).

pnpm add @ogygia/content
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { content } from '@ogygia/content/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    content({ markdown: {} }),
    sveltekit()
  ]
});
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { preprocess, extensions } from '@ogygia/content/vite';

export default {
  extensions: extensions(),
  preprocess: [vitePreprocess(), ...preprocess()],
  kit: { adapter: adapter() }
};
/// <reference types="ogygia/types" />
/// <reference types="@ogygia/content/types" />

First collection

Define the collection in a server module. The loader macro reads every .svx and .md file under the folder, and the schema checks each file’s frontmatter:

A page can’t import a server module, so it reads a post through a remote function. Awaiting the body renders it to HTML on the server, which is the form of a body that can cross to the browser. This needs Kit’s remote functions (kit.experimental.remoteFunctions), Svelte’s async mode (compilerOptions.experimental.async), and ogygia’s transport hook:

The page renders the body with <Region>. A component imported with a mark inside the markdown is an island, and nothing else in the post ships JavaScript:

Collections covers 404s, prerendering, lists for the browser and the rest of the read surface.

import { content } from '@ogygia/content';
import * as v from 'valibot';

export const posts = content({
  loader: import.meta.og.loader.markdown('../content/posts'),
  schema: v.object({ title: v.string(), date: v.string() })
});
import { query } from '$app/server';
import * as v from 'valibot';
import { posts } from './posts.server';

export const post = query(v.string(), async (id) => {
  const e = await posts.get(id);
  return e
    ? { data: e.data, body: e.body ? await e.body : undefined }
    : null;
});
<script lang="ts">
  import { page } from '$app/state';
  import { Region } from 'ogygia';
  import { post } from '$lib/posts.remote';

  const view = (await post(page.params.slug ?? ''))!;
</script>

<h1>{view.data.title}</h1>
{#if view.body}<Region of={view.body} />{/if}
---
title: Hello
date: 2026-01-01
---

<script>
  import Like from '$lib/Like.svelte' with { wake: 'visible' };
</script>

Everything here is static HTML, except this button: <Like />

Package contents

PartWhat it’s for
Collectionscontent(): typed entries from any source, schemas, filters for drafts and previews, relations and backlinks, lists for the browser, live sources.
MarkdownHow .md and .svx compile: frontmatter, heading ids, callouts, tab groups, highlighted code, diff marks, islands in prose, and extending the pipeline.
BlocksPages a visual editor or a CMS builds as a tree of components, rendered through a registry, each page loading only the blocks it uses.
Loadersimport.meta.og.loader.markdown, .folder, .json and .git: a collection from files in one line, or from another repository.
Code highlighting and Inline markdownA highlighted snippet, or a markdown passage, rendered at build time for a component.
Block registryA block registry made from a folder of components.
Docs sitessite(): collections arranged into a docs site or blog, with read functions for the nav, a page, search and prerendering.
SidebarThe sidebar tree and page order, from file names or arranged by hand.
Versioning and i18nOne site across versions or locales, with a switcher.
ThemingDocsShell, BlogShell, Doc, Sidebar and the rest, with opt-in themes, and swapping how markdown elements render.
Remote functionsremotes(site): the site’s nav, page and search as Kit remote functions.
SearchFull-text search on the server or in a worker, with a no-JavaScript fallback.
Sitemap and RSSsitemap.xml, llms.txt, RSS and raw markdown per page.
Link checkingA broken link in the prose fails the build, not the reader.
ConfigurationEvery import path, every plugin and markdown option with its default, presets and the build caches.

Integrations

  • @ogygia/postrender. A page built from a collection is usually the same for every visitor, so postrender can store it on its first request. A CMS webhook calls postrender.invalidate(path) when an entry changes.
  • @ogygia/router. When paths come from a collection rather than from files, a route table can map them, and a page’s entries lists the ids to prerender: '/blog/[slug]': page(Post, { load, entries: async () => (await posts.refs()).map((p) => ({ slug: p.id })) }).
  • @ogygia/image. With its plugin listed, a local image in markdown becomes a responsive <Img>, and a frontmatter path to an image becomes an image you can render. See Markdown images.
  • @ogygia/devtools. The profiler shows how long the markdown and the shell take in a server render.