@ogygia/cli
Project setup
What `ogygia init` and `ogygia site init` write, file by file. Both merge into the files you already have, can run again, and leave route options and content to you.
On this page
Adding ogygia to a SvelteKit app takes edits in five or six files: the dependencies, the Vite config, both hooks files, a type reference and a .gitignore line. ogygia init makes them for you, and ogygia site init goes on to scaffold a whole docs site. Both edit your files through their syntax tree, so they merge into what you have instead of overwriting it.
Install shows each of these pieces written by hand, for when you’d rather not run a command on your project.
npx ogygia init --no-markdowninit
init works on the app in the current folder. It needs a package.json that lists @sveltejs/kit in dependencies or devDependencies, and a vite.config.ts or vite.config.js. When either is missing it prints why and exits with 1 before it changes anything.
It then asks one question, whether to add markdown content collections. --markdown and --no-markdown answer it up front, and -y answers no. With no terminal to ask in, such as in CI, the answer is no too.
Run with --no-install against a new app whose hooks.server.ts already exports a handle, it starts with these lines, then prints the next steps:
The project is TypeScript when the Vite config is vite.config.ts or there’s a tsconfig.json. A JavaScript project gets src/hooks.js and src/hooks.server.js instead, and no type file.
Dependencies
ogygia goes in dependencies at the CLI’s own version (^0.16.2 for CLI 0.16.2), and @ogygia/cli in devDependencies, so the next npx ogygia runs that copy. With markdown, @ogygia/content joins ogygia. A package already in dependencies keeps its version (for @ogygia/cli, in either list), and the file keeps its indentation. One in devDependencies gets a second entry (Running again).
Vite config
ogygia() goes first in plugins, with its import. With markdown, content({ markdown: {} }) from @ogygia/content/vite follows it.
Svelte config
Only with markdown. extensions() and preprocess() from @ogygia/content/vite join your Svelte options, so .svx and .md files compile. They go in svelte.config.js when you have one, and in the sveltekit({ … }) call in the Vite config when you don’t. An existing extensions array gets ...extensions() added, an existing preprocess gets ...preprocess() added, and a lone preprocessor is wrapped in a list with it.
Hooks
src/hooks.ts exports ogygia’s transport, so a held region can cross a load. An existing transport object gets ...ogygia.transport spread in first, and any other value is wrapped as { ...ogygia.transport, ...yours }.
src/hooks.server.ts gets ogygia.handle(). With no handle yet, it becomes the export. With one, yours runs first and ogygia’s second, in a sequence():
Other ogygia packages add handles that must come before ogygia’s, such as postrender.handle(). Packages shows the order.
Types and .gitignore
In a TypeScript project, src/ogygia.d.ts gets /// <reference types="ogygia/types" />, and the @ogygia/content/types reference with markdown. A reference already in the file isn’t added twice.
.gitignore gets **/.ogygia-keep-client/. The build makes that folder for a moment when every route has csr = false, and removes it when the process exits, so you only see it after a build was killed.
Install step
Last, it runs install with the package manager whose lockfile it finds: pnpm-lock.yaml for pnpm, yarn.lock for yarn, bun.lockb or bun.lock for bun, and npm otherwise. A failed install prints the command to run yourself, and init still exits with 0. --no-install skips it.
Route options
init sets no route options. Islands need a route with csr = false, which you add when you’re ready (Client islands):
ogygia — wiring your project…
✓ dependency ogygia@^0.16.2
✓ vite.config.ts (plugin)
✓ src/hooks.ts (transport)
✓ src/hooks.server.ts (handle)
✓ src/ogygia.d.ts (types){
"name": "app",
"type": "module",
"devDependencies": {
"@sveltejs/kit": "^2.0.0",
"@ogygia/cli": "^0.16.2"
},
"dependencies": {
"ogygia": "^0.16.2"
}
}import { ogygia } from 'ogygia/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [ogygia(), sveltekit()]
});import { preprocess, extensions } from '@ogygia/content/vite';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import adapter from '@sveltejs/adapter-auto';
export default {
kit: { adapter: adapter() },
extensions: extensions(),
preprocess: [vitePreprocess(), ...preprocess()]
};import { sequence } from '@sveltejs/kit/hooks';
import * as ogygia from 'ogygia/server';
import type { Handle } from '@sveltejs/kit';
const originalHandle: Handle = ({ event, resolve }) =>
resolve(event);
const ogygiaHandle: Handle = ogygia.handle();
export const handle = sequence(
originalHandle,
ogygiaHandle
); /// <reference types="ogygia/types" />export const csr = false;Docs site
site init scaffolds a docs site on the content site layer, as ordinary files you own and edit. Nothing is generated at build time.
It first runs the same wiring as init with markdown on, and also turns on Svelte’s async compiler (compilerOptions.experimental.async), because the site’s pages use top-level await. Then it writes the files below, with the routes in the layout’s folder. Pass --layout src/routes/docs/+layout.svelte to mount the site under /docs:
| File | What it holds |
|---|---|
src/lib/docs.ts | The collection, every file under src/content/docs, and its site() with the outline and prev/next. |
src/content/docs/introduction.svx, getting-started.svx | Two starter pages, written only when that folder has no .svx page yet. |
[...slug]/+page.ts, [...slug]/+page.svelte | The doc route: load and entries from the site, prerendered, and the <Doc> that renders a page. |
+layout.ts | csr = false and prerender = true for the whole site; the search page turns prerendering off for itself. |
+layout.svelte | The layout: DocsShell around the page, with theme.css and shell.css imported. |
+page.svelte | A home page that links the first doc. |
search.json, sitemap.xml, llms.txt, [...slug].md | Prerendered endpoints: the search index, the sitemap, the page list for LLMs, and each page as markdown. |
search/+page.server.ts, search/+page.svelte | A search page that works without JavaScript. |
+error.svelte | An error page in the theme’s colors. |
Existing files
A file that already exists is kept and listed as kept, unless you pass --force. With --force, every file above is written again, the two starter pages included even when the folder has pages of its own.
The layout gets more care, since it’s the one file you’re likely to have written yourself:
- No layout yet: it’s written.
- A layout that already imports from
@ogygia/contentand uses its shell: it’s kept, so runningsite initagain changes nothing there. - Any other layout: it’s replaced only with
--force, or a “yes” at the prompt. With-y, or no terminal, the command stops with exit 1 and suggests--forceor another--layout.
The layout is checked partway through: after the wiring, src/lib/docs.ts, the starter pages, the doc route, +layout.ts and the home page are written. A run that stops there hasn’t written the endpoints, the search page or the error page (#2314, item 4). Run it again with --force or a --layout to finish.
npx ogygia site init --layout src/routes/docs/+layout.svelteRunning again
Both commands are meant to run again, for example after you upgrade or when you add markdown later: a dependency, an import, a plugin, a hook or a type reference that’s already there isn’t added twice. Four edits don’t hold to that yet:
- Each run with markdown adds another
...preprocess()to the Sveltepreprocesslist. Remove the copies by hand (#2314, item 2). - Each run with markdown adds another
...extensions()to anextensionsarray you wrote, such as['.svelte']. Remove the copies by hand (#2314, item 14). - Adding markdown to an app that already lists
ogygia()putscontent()before it, where a fresh setup puts it after. Move it afterogygia()to match (#2314, item 3). ogygiaor@ogygia/contentlisted indevDependenciesgets a second entry independencies, at the CLI’s version (#2314, item 13). Keep one of the two.