Skip to content

@ogygia/content · API

Configuration

What each @ogygia/content import path holds, every option of the content() Vite plugin and its markdown settings with their defaults, how presets merge, and where the build keeps its caches.

On this page

This page is for looking things up: what each @ogygia/content import path holds, and every option of the content() plugin with its default. The pages after it are generated from the package’s type declarations, with every signature. For ogygia’s own entry points and the options of ogygia(), see API and config.

Import paths

Import pathWhat it holds
@ogygia/contentCollections, sources, conventions, blocks, the site layer and its components (listed below). Safe to import anywhere; what you build with it decides where it may run.
@ogygia/content/serverwithRemotes(collection) for a collection’s remotes, and remotes(site, options?) for a site’s. It imports $app/server, so use it in a .remote.ts.
@ogygia/content/viteThe content() plugin, preprocess() and extensions() for svelte.config.js, and invalidateModuleTree(server, module), which invalidates a module and everything that imports it on a Vite dev server.
@ogygia/content/markdownThe markdown pipeline’s parts: diff_markers(), inline_markers({ classes? }), infostring(), slash_meta(), parseFrontmatter(text), highlight(code, lang, options?), slugify(text), and the remark plugins remarkHeadingId, remarkHeadings, remarkLinks. See Markdown. escape_svelte, wrap_html, normalize_shiki, ogygiaPreprocess, ogygiaPresetPreprocess and extensions are exported too, for the plugin’s own use; you don’t need them.
@ogygia/content/docs-shellThe DocsShell component. See Theming.
@ogygia/content/slotSiteSlot, which markdown with overrides on renders its elements through. Compiled markdown imports it; you don’t.
@ogygia/content/theme.css · /shell.cssThe stock design tokens and the shells’ layout, each an opt-in import. See Style it.
@ogygia/content/themes/*Other token themes: alexandria, daidalos, kalliope, nephele, pyros, selas, thalassa, zephyros (.css).
@ogygia/content/typesThe macro types (import.meta.og.loader, code, md, regions). Reference it from src/ogygia.d.ts.

highlight(code, lang) with no options uses the settings the markdown pipeline set up in the same process. Called before that, or in a process with no markdown, it throws content_highlight_unconfigured; pass the Shiki options as the third argument there.

What @ogygia/content exports

AreaExports
Collectionscontent, fields, parseSchema
Sourcesmarkdown, json, folder, blocks, glob, defineSource, toRawSource, mapRaw, enrich
Folder conventionsnumbered, dated, dateOf, titleCase, stripOrderPrefix, orderOf
Sitesite, mountBase, outline, pick, hrefOf, dimensions, isDimensioned, links
SearchcreateSearch, oramaEngine, buildDocs, splitSections, stripProse, SearchClient
ComponentsFrame, Doc, Sidebar, OnThisPage, Pager, Switcher, Search, SearchPage, BlogShell, BlogList, BlogPost, TabGroup, Tab, CodeChrome, Link, ThemeToggle, Sheet, BottomBar, SiteSlot, getShellContext, roving

parseSchema(schema, data, label) runs one schema the way a collection does. It returns a promise of the validated value, which rejects with content_schema_failed, naming label, when the data doesn’t pass. The types (Entry, ContentRef, RefEntry, ContentHandle, Source, RawSource, Format, Heading, BlockNode, BlockRegistry, PageView and the rest) are on the generated page.

content() plugin

content(options) is the package’s Vite plugin. List it once, beside ogygia() and before sveltekit(). It brings the content macros (import.meta.og.loader, code, md, regions), the markdown pipeline when markdown is set, the dev reload for content files, and the build’s placement and leak checks for collections. It needs nothing in hooks.server.ts.

OptionDefaultWhat it does
markdownoffThe markdown settings for every .svx and .md file. Setting it, even to {}, turns markdown on.
presetsnoneNamed markdown variants a loader can compile a whole collection with. See Presets.
watchDirs[]Extra folders the dev server watches for content, besides src/content, resolved against the working directory. Vite already follows import.meta.glob, so you rarely need it.
hmrDebounceMs50How long, in milliseconds, the dev server waits for more changes before it reloads the page.

The svelte config

preprocess() returns the markdown preprocessor (or nothing, when markdown is off), and extensions() returns ['.svelte'] plus the markdown extensions. Neither takes options; both read what content({ markdown }) set. Keep the rest of your config, such as your adapter, as it is. Kit has to load svelte.config.js after the plugin list is built, or they find nothing, and content({ markdown }) then throws content_config_read_first.

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: {},
      watchDirs: ['../shared-content'],
      hmrDebounceMs: 200
    }),
    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() }
};

Markdown settings

Every key of content({ markdown }), with its default. Markdown shows each one in use.

KeyDefaultWhat it does
extensions['.svx', '.md']The files that compile as markdown.
themes{ light: 'github-light', dark: 'github-dark' }Shiki themes, by name or as theme objects.
defaultColor'light-dark()'Shiki’s defaultColor; false for none.
langsabout forty languagesThe languages Shiki loads. A block in any other renders as plain text. See Highlight code.
wrapperClass'code-only'The class of the <div> around each code block; false for no wrapper.
code{}The code block pipeline: transformers (Shiki transformers, default none), meta (meta parsers, default [infostring()]), variants (default none), cacheSalt.
transformers[]Shiki transformers, the same as code.transformers; code.transformers wins when both are set.
headingIdstrueReads ## Title {#id}.
headingstrueCollects h2 to h4 into meta.headings and gives headings ids from their text; { minDepth, maxDepth } narrows what’s collected. false collects none and makes no ids from text, so only {#id} headings keep one.
headingAnchorstrueAdds a link anchor to each h2 to h6 with an id.
codeIdstrueGives each code block a stable id.
containerstrueReads ::: callouts and ::: details.
tabstrueReads ::: code-group and ::: tabs.
overridesfalsetrue routes a, img and code through a site’s components; { tags } picks the elements.
remark[]Extra remark plugins; { enforce: 'pre', plugin, cache_key?, dependencies? } runs one before the built-in passes. See Extend the pipeline.
rehype[]Extra rehype plugins, staged the same way.
regionfalseCompiles a static .md file to plain HTML data instead of a component. Skipped for every file while overrides is on.
layoutnonePassed to mdsvex’s layout.

Presets

presets names other markdown settings for some collections: a blog with other themes, a corpus with overrides on. A loader macro opts a collection in with { preset: 'name' }, and its files compile with the preset’s markdown merged over the app’s markdown. The merge is per top-level key: a key the preset sets replaces the app’s value whole (a preset’s code: {} drops the app’s transformers), and a key it leaves out keeps the app’s. Each opted-in file compiles as its own module, so the same file read by another collection, with another preset or none, renders independently.

A preset holds one key, markdown. The plugin checks them when it starts:

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: { overrides: true },
       presets: {
        plain: { markdown: { overrides: false } }
      } 
    }),
    sveltekit()
  ]
});
import { content } from '@ogygia/content';

export const blog = content({
  loader: import.meta.og.loader.folder('../content/blog', {
    preset: 'plain'
  })
});

Build caches

The package keeps its build work in node_modules/.ogygia/, so a host that caches node_modules between builds keeps it too. Each entry is addressed by a hash of what made it, so nothing needs clearing by hand, except where noted.

Markdown plugins and transformers are only partly in that hash. Remark and rehype plugins count by how many there are, and Shiki transformers by their name; their options, their package versions and Shiki’s version aren’t in it. After you swap, reconfigure or upgrade any of them, change markdown.code.cacheSalt, which salts both markup/ and fences/. Reuse compiled markdown between builds has the details.

FolderHolds
markup/Each compiled markdown document (documents with islands are always compiled again).
fences/Each highlighted code block and code() snippet.
docs/The HTML of each .md file compiled with region: true.
content/The checkouts of git() loaders.
git/The commit each git() loader last checked out. Delete it to fetch a branch’s newest commit.