@ogygia/content · Docs sites
Theming
DocsShell and BlogShell put a whole docs or blog layout around your pages in one import, and every piece of them is a component you can replace, remove or use on its own. The look is opt-in, from the stock theme, eight other themes or your own CSS on the .og-* classes.
On this page
The site hands your pages plain data: a sidebar tree, a page view, search hits. The components on this page turn that data into a layout. DocsShell is a complete docs layout, with a header, the sidebar, search, a theme toggle and a bottom bar on phones. BlogShell is the same for a blog. Both are built from the public components (Sidebar, Doc, Search and the rest), with nothing private, so anything they do you can rebuild your own way.
The shells ship markup and .og-* class names, and no CSS. You choose the look with one or two stylesheet imports: the stock theme, one of eight other themes, or your own CSS. This site uses DocsShell with its own header and its own skin; the Playground ↗ uses it with the stock parts and a theme picker in the corner.
The plain layout is on the site page. Here it is with links in the header, the site name pointing at a separate home page, and a GitHub link added to the tools:
<script lang="ts">
import DocsShell from '@ogygia/content/docs-shell';
import '@ogygia/content/theme.css';
import '@ogygia/content/shell.css';
import { meta } from '$lib/docs.remote';
let { children } = $props();
const shell = await meta();
</script>
<DocsShell
meta={shell}
base="/docs"
home="/"
title="Example"
links={[{ text: 'Blog', href: '/blog' }]}
>
{#snippet actions()}
<a href="https://github.com/example/example">GitHub</a>
{/snippet}
{@render children()}
</DocsShell>Docs shell
DocsShell is the default export of @ogygia/content/docs-shell. On a wide screen it draws a header (the site name, your links, search, the theme toggle), the sidebar on the left and the page beside it. At 900 pixels wide or less the header and sidebar hide, and a bottom bar takes over: search, the theme toggle and a menu button that opens the sidebar in a sheet.
It needs the site’s data one of two ways. meta is the result of the meta remote, which keeps the corpus on the server; that’s the usual way. site is the site itself, for a layout that renders in the same pass as the site (see Start from the scaffold). Give it exactly one.
| Prop | Default | What it does |
|---|---|---|
meta | none | { nav, switcher, data } from meta(). On a site with dimensions, call it with the slug. |
site | none | The site, in place of meta. |
title | 'Docs' | The site name in the header and the bottom bar, and the end of every page’s <title>. It doesn’t read data.title. |
links | [] | { text, href } links in the header’s nav row. They don’t appear on phones today. |
base | taken from the page | The mount prefix. By default it’s the URL’s path minus the current slug. |
home | base | Where the site name links. Set home="/" when the docs sit under a separate home page. |
DocsShell brings its interactive parts as islands: the sidebar and the bottom bar wake on load and are kept across navigations, so the sidebar’s highlight glides from page to page; the theme toggle and the version switcher wake on load; search wakes when the browser is idle. It also adds a small script to the <head> that applies the saved light or dark choice before the first paint.
The search box needs the index at {base}/search.json and the no-JavaScript page at {base}/search; see Search.
Replace or remove a region
Every region of DocsShell is a snippet prop. Leave it out and the built-in one renders. Pass a snippet and yours renders in its place. Pass null (or a value that turns out undefined) and the region is gone.
| Snippet | Arguments | The built-in |
|---|---|---|
skip | none | A “Skip to content” link to #og-main, the first thing a keyboard reaches. |
header | none | The whole top header. Replacing or removing it switches the shell to the panel form below. |
brand | none | The site name, linking to home. |
nav | none | The row of links. |
tools | none | Search, the language switcher, the theme toggle and actions. |
side | none | Nothing. Content placed at the top of the sidebar, and at the top of the phone menu sheet. |
sidebar | (tree, base) | The Sidebar island with the nav tree. Your snippet gets the same tree and base. |
bar | (tree, base) | The phone bottom bar and its sheet. |
actions | none | Nothing. Extra buttons (a GitHub link, say) at the end of the built-in tools, and in the phone menu sheet. Pass your own tools and render them there yourself. |
The regions nest: replace the whole header, or keep it and replace only its brand, nav or tools. The version switcher sits beside the brand and the language switcher in tools; Let readers switch explains which axes they show.
When you pass header, as a snippet or null, the shell takes its panel form: the sidebar becomes the whole chrome on a wide screen. Its top row holds side and, unless you passed tools, the theme toggle; below it come the tools (the version switcher, search, the language switcher, actions); then the nav. Phones keep the bottom bar either way. This site passes its own header, removes the panel’s tools with tools={null}, and puts its section switcher in side:
Snippets render on the server. actions and side also render in the phone sheet, which is an island, so they cross into it the way snippets cross into islands: as a snapshot of the values they read when the page rendered.
<script lang="ts">
import DocsShell from '@ogygia/content/docs-shell';
import '@ogygia/content/shell.css';
import { meta } from '$lib/docs.remote';
import SiteHeader from '$lib/SiteHeader.svelte';
import SectionPicker from '$lib/SectionPicker.svelte' with {
wake: 'load'
};
let { children } = $props();
const shell = await meta();
</script>
<DocsShell
meta={shell}
base="/docs"
home="/"
title="Example"
tools={null}
>
{#snippet header()}
<SiteHeader />
{/snippet}
{#snippet side()}
<SectionPicker />
{/snippet}
{@render children()}
</DocsShell>Blog shell
BlogShell is a header (the blog’s name, your links, the theme toggle, optional search, actions) over one centered column, with no sidebar. It needs no site data at all. Its props are title (default 'Blog', also the end of each <title>), base, links, search (default false; true adds the search box, which needs {base}/search.json), and the brand and actions snippets. Unlike DocsShell, the blog components carry their own layout in component styles, painted from the same --og-* tokens, so theme.css alone gives the stock look and shell.css isn’t needed. Those styles are scoped to the component and sit outside @layer ogygia (#2287), so a rule of yours needs a more specific selector to win (.og-bmain .og-blog-card, say), and the hover rules are heavier still.
Inside it go two components:
<BlogList posts={…} />is the index: posts newest first, under a heading per year (group={false}for one flat list). Each post is a card with its date, title, summary, author and tags, or whatever youritemsnippet draws.titleandintrohead the page.postsis a list ofBlogPostRef({ href, title, date, summary?, author?, tags? }).<BlogPost view={…} />is one post from a page view: a dateline (date and author), the title, summary and tags, the body, afootersnippet, and links to the previous and next post.backadds a link to the index above the title (backLabelchanges its text). It writes the title, summary, author and date into the<head>.
A blog is a dated collection with its own small site. Its remotes give BlogPost a page and BlogList the list, mapped down to what a card shows:
The layout wraps the blog in the shell, the index renders the list, and the post route mounts like a docs page (export const { load, entries } = blog in src/routes/blog/[slug]/+page.server.ts, with prerender = true):
import { remotes, withRemotes } from '@ogygia/content/server';
import type {
BlogPostRef,
PageFields,
PostFields
} from '@ogygia/content';
import { blog, posts } from './blog.server';
export const { page: post } = remotes(blog, { base: '/blog' });
export const postList = withRemotes<PageFields & PostFields>(
posts
).list({
map: (e): BlogPostRef => ({
href: `/blog/${e.id}`,
title: e.data.title,
date: e.data.date,
summary: e.data.summary,
author: e.data.author,
tags: e.data.tags
})
});<script lang="ts">
import { BlogShell } from '@ogygia/content';
import '@ogygia/content/theme.css';
let { children } = $props();
</script>
<BlogShell
base="/blog"
title="Example blog"
links={[{ text: 'Docs', href: '/docs' }]}
>
{@render children()}
</BlogShell><script lang="ts">
import { BlogList } from '@ogygia/content';
import { postList } from '$lib/blog.remote';
const posts = await postList();
</script>
<BlogList
{posts}
title="Example blog"
intro="Notes from the team."
/><script lang="ts">
import { page } from '$app/state';
import { BlogPost } from '@ogygia/content';
import { post } from '$lib/blog.remote';
const view = (await post(page.params.slug ?? ''))!;
</script>
<BlogPost {view} back="/blog" />Doc component
<Doc {view} /> lays out one page from a page view: the section label above the title, the title and summary, the body, the “keep reading” cards, the previous and next links, and the on-this-page rail on the right. On a phone the rail becomes a list under the title. It also writes the <title> (the page’s title, then the shell’s title) and the description into the <head>, and adds copy and permalink buttons to each code block. It needs no shell.
| Prop | Default | What it does |
|---|---|---|
view | required | The page view. |
crumbs | false | Shows the group path above the title, for deep trees. |
toc | true | The on-this-page rail and the phone list. The rail lists the title even on a page with no headings. |
pager | true | The previous and next links. |
suggested | true | The “keep reading” cards. |
keepReading | view.trail.suggested | The pages the cards show. Pass view.trail.related to show only the pages the page names. |
eyebrow | view.section | The text above the title. |
footer | none | A snippet between the body and the cards: an edit link, a feedback form. |
The body is rendered on the server, so every island the .svx file imports wakes exactly as it would anywhere else. This page is a <Doc>.
<script lang="ts">
import { page } from '$app/state';
import { Doc } from '@ogygia/content';
import * as docs from '$lib/docs.remote';
const view = (await docs.page(page.params.slug ?? ''))!;
</script>
<Doc {view} keepReading={view.trail.related}>
{#snippet footer()}
<a href="https://example.com/edit/{view.slug}"
>Edit this page</a
>
{/snippet}
</Doc>Components
Every component is exported from @ogygia/content (DocsShell from @ogygia/content/docs-shell) and works without a shell. The ones marked as islands run code in the browser: the shells import them as islands already, and when you place one yourself, import it with a wake mark, such as import { Sidebar } from '@ogygia/content' with { wake: 'load' } (named imports).
| Component | Island | What it does |
|---|---|---|
DocsShell, BlogShell | The two layouts above. | |
Frame | A bare sidebar-and-main layout for your own shell. | |
Doc | One docs page. | |
BlogList, BlogPost | The blog index and one post. | |
Sidebar | yes | The nav tree: nav (a tree) and base, or a site to read it from. Marks the current page, centers it when it’s out of view, keeps its scroll position per tab, and is one tab stop with arrow keys inside. item draws a page row yourself ((leaf, active)). |
OnThisPage | yes | The on-this-page rail from headings, with the title first. Highlights the section being read (scrollspy, default true); label and an item snippet change it. |
Pager | Previous and next links from trail, with previousLabel and nextLabel. | |
Search | yes | The search box and ⌘K palette. See Search. |
SearchPage | Search with no JavaScript. See Search. | |
Switcher | yes | The version and language menus from a switcher; for limits it to some axes. See Let readers switch. |
ThemeToggle | yes | Flips the page between light and dark. See Light and dark. |
CodeChrome | yes | Copy and permalink buttons on every code block matching selector (default .og-body pre). Doc and BlogPost include it. |
TabGroup, Tab | Tabbed panels: a TabGroup (group, default 'tabs') holds Tabs, each named by its label. The chosen tab is shared by every group with the same group name and remembered across pages. Markdown’s ::: code-group makes them for you (tabs). | |
Sheet, BottomBar | Sheet | The phone sheet (a dialog with open bindable, a label and a footer snippet) and the bar it opens from (lead and actions snippets and a label), for building your own phone chrome. |
Link | A link whose bare href resolves against the site’s addresses. See Swap how markdown elements render. | |
SiteSlot | What markdown elements render through when overrides is on. You don’t use it directly. |
Two helpers go with them. getShellContext() returns what a shell or Frame shares with the components inside it: base always; title under DocsShell and BlogShell; site and components under Frame and DocsShell site={…}. Frame sets no title, so <Doc> inside it writes the page’s title with no site name after it (#2287). roving({ selector, orientation?, loop? }) is the arrow-key behavior of the sidebar as an attachment ({@attach roving({ selector: 'a' })}), for a nav of your own.
Styling
The components import no CSS, and DocsShell, Frame and the rest of the docs components carry no look of their own. The exceptions keep scoped rules outside any layer: Doc has one that shows its phone heading list at 900 pixels wide or less, ThemeToggle styles its own button (size, border, radius, background, the icon swap), and the blog components are described above (#2287). Each element carries an .og-* class, and two stylesheets paint them:
@ogygia/content/theme.cssis the look: the--og-*tokens (colors, fonts, sizes, motion) and the styles of every component,Doc’s prose and code blocks included.@ogygia/content/shell.cssisDocsShell’s layout: the header, the sidebar column, the grid and the phone chrome. It holds no colors; it reads them from the tokens.
Import them once, in the layout that mounts the shell. Every rule in both, and in the themes, sits in @layer ogygia, so any rule of yours outside a layer beats it, whatever its specificity, with no !important. The components’ own scoped rules above aren’t in the layer; to change those, use a more specific selector. Three levels follow, from a ready theme to your own CSS, and then light and dark.
Pick a theme
Besides the stock theme.css, eight themes ship under @ogygia/content/themes/, each a full replacement for theme.css over the same markup: alexandria (warm paper with serif headings), daidalos (a compact reference manual with numbered sections), kalliope (a two-ink print zine), nephele (a floating glass header and sidebar), pyros (stark monochrome with one signal color), selas (a monospace terminal), thalassa (deep ocean blues) and zephyros (soft shadows and round shapes). The Playground ↗ has a picker that switches between all nine. In the layout above, import shell.css first and the theme after it, in place of theme.css:
Change the tokens
To keep a theme and change its colors, fonts or widths, set the --og-* tokens in a stylesheet of your own. The main ones are --og-accent, the surfaces --og-bg, --og-bg-subtle, --og-bg-raised and --og-bg-inset, the text colors --og-text, --og-text-dim and --og-text-faint, --og-line, the fonts --og-font and --og-mono, and the widths --og-side-w, --og-toc-w and --og-content-w. A token set on :root applies in light and dark alike. For a dark value, set it for a system in dark mode and for an explicit data-theme='dark':
Skin it with your own CSS
To make the docs look like the rest of your site, leave theme.css out, keep shell.css for the layout, and paint the .og-* classes yourself: .og-sidebar, .og-nav-link, .og-active, .og-doc, .og-title, .og-body, .og-pager, .og-search-trigger and the rest. Map your design’s colors onto the handful of tokens shell.css reads (--og-bg, --og-bg-raised, --og-bg-subtle, --og-text, --og-text-dim, --og-text-faint, --og-line, --og-font, --og-mono, --og-accent, --og-side-w, --og-bar-h). This site works this way: it imports only shell.css, bridges its own tokens, and styles the classes in two files of its own. With neither stylesheet, you get the bare markup and write the layout too.
Light and dark
The stock theme and the eight others follow the visitor’s system setting, and data-theme="light" or data-theme="dark" on <html> overrides it. ThemeToggle flips between light and dark. A choice that differs from the visitor’s system setting is set on <html> and stored in localStorage under key (default og-theme). Flipping back to the system’s theme clears both, so the page follows the system again, even when it changes later. The change runs inside a view transition when motion isn’t reduced, as one cross-fade of the whole page, with data-ph-switching on <html> meanwhile so a theme can mute its own transitions. label sets its accessible name (default Dark theme), and the button is pressed while the page is dark.
Both shells add a script to the <head> that applies the stored choice before the first paint, so a dark page doesn’t flash light. In a layout of your own, add the same script with script() from ogygia, using the toggle’s key:
<script lang="ts">
import '@ogygia/content/shell.css';
import '@ogygia/content/themes/thalassa.css';
</script>:root {
--og-accent: #7c3aed;
--og-font: 'Inter Variable', system-ui, sans-serif;
--og-side-w: 18rem;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme='light']) {
--og-accent: #a78bfa;
}
}
:root[data-theme='dark'] {
--og-accent: #a78bfa;
}:root {
--og-bg: var(--surface);
--og-text: var(--ink);
--og-line: var(--rule);
--og-accent: var(--brand);
--og-font: var(--font-body);
}
.og-nav-link.og-active {
color: var(--brand);
font-weight: 600;
}<script lang="ts">
import { script } from 'ogygia';
import { ThemeToggle } from '@ogygia/content' with {
wake: 'load'
};
import '@ogygia/content/theme.css';
let { children } = $props();
const applyTheme = script((key: string) => {
try {
const t = localStorage.getItem(key);
if (t === 'light' || t === 'dark')
document.documentElement.setAttribute('data-theme', t);
} catch {
// no storage, as in some private windows: keep the system theme
}
}, 'og-theme');
</script>
<svelte:head>{@html applyTheme}</svelte:head>
<ThemeToggle />
{@render children()}Custom shells
Frame is the layout with nothing decided for you: a skip link, an optional header, the sidebar, the main area and an optional footer. Each region takes a component (which gets site as a prop), false or null to remove it, or nothing for the default. The default sidebar is the Sidebar island over the site’s tree; there’s no default header or footer. base overrides the mount prefix, which is otherwise taken from the page. Its layout rules are in theme.css (.og-frame, .og-side, .og-main, .og-header, .og-footer), so it doesn’t need shell.css.
Frame takes the site itself, not meta, so the site has to be importable by the layout: an ordinary module, not a .server.ts one. That’s the same-pass shape the scaffold uses, with the same content_collection_not_server_only warning. In return the components inside get the whole site through context, which element overrides need.
To keep the corpus on the server and still lay the page out yourself, skip Frame and place the islands over the meta remote’s data. Sidebar takes the tree as nav. The markup mirrors Frame’s: .og-shell paints the page (its background, text color and font, and border-box sizing inside it), and .og-header, .og-frame, .og-side and .og-main lay it out, all from theme.css. The .og-skip link is Frame’s skip link, and tabindex="-1" keeps <main> focusable so the link can move focus there:
<script lang="ts">
import { Frame } from '@ogygia/content';
import '@ogygia/content/theme.css';
import { docs } from '$lib/docs';
import Header from '$lib/Header.svelte';
let { children } = $props();
</script>
<Frame site={docs} header={Header}>
{@render children()}
</Frame><script lang="ts">
import type { Site } from '@ogygia/content';
import { Search, ThemeToggle } from '@ogygia/content' with {
wake: 'load'
};
let { site }: { site: Site } = $props();
</script>
<a href="/docs">{site.data?.title ?? 'Docs'}</a>
<Search base="/docs" />
<ThemeToggle /><script lang="ts">
import { Sidebar } from '@ogygia/content' with {
wake: 'load',
keep: 'og-sidebar'
};
import { Search, ThemeToggle } from '@ogygia/content' with {
wake: 'load'
};
import '@ogygia/content/theme.css';
import { meta } from '$lib/docs.remote';
let { children } = $props();
const shell = await meta();
</script>
<div class="og-shell">
<a class="og-skip" href="#og-main">Skip to content</a>
<header class="og-header">
<a href="/docs">Docs</a><Search base="/docs" /><ThemeToggle
/>
</header>
<div class="og-frame">
<aside class="og-side">
<Sidebar nav={shell.nav} base="/docs" />
</aside>
<main class="og-main" id="og-main" tabindex="-1">
{@render children()}
</main>
</div>
</div>Element overrides
A site can render chosen markdown elements with your own components: every image as a figure with a caption, every code span with a tooltip. It takes three things:
- Turn on
overridesin the content plugin’s markdown settings.truecoversa,imgandcode;{ tags: ['a', 'img', 'table'] }picks the elements. Each chosen element then compiles to a slot that looks up its component when the page renders. (Withoverrideson,markdown.regionis skipped for every file.) - Map tags to components with
site({ components }), using the components themselves, not import paths. A component gets the element’s attributes as props and its content aschildren. - Render the body inside a shell given the site. The map reaches the slot through the shell’s context, so it applies where
DocsShell site={…}orFramewraps the page in the same pass.
The route’s +page.server.ts mounts docs.load and docs.entries from $lib/docs as usual. The layout gives the shell the site itself, and the page reads its view with docs.page() in the same pass, not through the page remote, so the body renders inside the shell:
Without a map entry, a renders through Link. A bare href in prose, with no scheme and not starting with /, # or . ([routing](guides/routing)), resolves against the site’s addresses and old addresses and gets the shell’s base in front, so prose never hardcodes the mount. An address the site doesn’t know is left as written. On a site with dimensions, a bare address resolves in the default version and language, not the page’s own (#2286).
On the remotes path, a page’s body is rendered by the page remote, outside any shell, so neither the map nor Link’s resolving reaches it: elements render as plain HTML and a bare href stays as written, where the browser reads it as a relative link (#2284).
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 } }),
sveltekit()
]
});import { content, site } from '@ogygia/content';
import Figure from './Figure.svelte';
const guides = content({
loader: import.meta.og.loader.folder('../content/docs')
});
export const docs = site({
outline: guides,
components: { img: Figure }
});<script lang="ts">
let { src, alt }: { src?: string; alt?: string } = $props();
</script>
<figure>
<img {src} {alt} />
<figcaption>{alt}</figcaption>
</figure><script lang="ts">
import DocsShell from '@ogygia/content/docs-shell';
import '@ogygia/content/theme.css';
import '@ogygia/content/shell.css';
import { docs } from '$lib/docs';
let { children } = $props();
</script>
<DocsShell site={docs} base="/docs" title="Example">
{@render children()}
</DocsShell><script lang="ts">
import { page } from '$app/state';
import { Doc } from '@ogygia/content';
import { docs } from '$lib/docs';
const view = (await docs.page(
page.params.slug ?? '',
{ base: '/docs' }
)) !;
</script>
<Doc {view} />Do and don’t
- Do start from
DocsShelland replace regions with snippets before you reach forFrame. - Do import the stylesheets once, in the layout that mounts the shell. The components import none themselves.
- Do import a component with a
wakemark when you place an interactive one yourself. - Don’t fight specificity over the stylesheets. A plain unlayered rule already beats every rule in
theme.css,shell.cssand the themes. - Don’t rebuild the on-this-page list or the pager by hand.
view.headingsandview.trailcarry the data, and<Doc>draws both.