Skip to content

@ogygia/content · Docs sites

Sidebar

The outline decides a site's structure, its sidebar groups, page order and addresses, from your file names or from a list you write. Every page is placed exactly once, and a page left out, picked twice or given a clashing address fails the build by name.

On this page

A site needs one answer to “what goes where”: which pages sit in which sidebar group, in what order, at which address, and what comes next. The outline is that answer. It’s the outline option of site(), and everything else the site does reads from it: the sidebar, prev and next, section labels, search, the sitemap and the prerender list are all views of one tree.

Most sites need nothing on this page beyond the first section. A folder collection already carries its order and section names in its file names, so passing it as it is builds the whole tree. You write an outline by hand when a site combines several collections, puts a few pages in a hand-picked order, or adds plain links to the sidebar.

import { content, site } from '@ogygia/content';

const guides = content({
  loader: import.meta.og.loader.folder('../content/docs')
});

export const docs = site({ outline: guides });

Folder convention

A collection passed on its own is arranged from its entries’ ids and order:

  • Groups come from the id’s folders. start/install and start/overview share a Start group; a top-level id is a page outside any group.
  • Order comes from each entry’s order, which a folder collection reads from NN- prefixes. Siblings without an order go last, by id.
  • Group labels come from the folder’s +meta.json ({ "label": "Getting started" }), or from the folder name in title case (data-state becomes Data State).
  • Page names come from the entry’s title, or its id when there’s none. A badge field shows after the name.
  • A folder with its own page (guide beside guide/one) becomes a group led by that page.

How NN- prefixes are checked, and how dated() orders by a date instead, belongs to the collection: see Order a docs folder and Folder options. An address is the entry’s id, so 03-routing/+doc.svx is served at /routing.

content/docs/
  00-start/
    +meta.json            { "label": "Getting started" }
    00-overview/+doc.svx  → /start/overview, first in "Getting started"
    01-install/+doc.svx   → /start/install
  01-guides/
    00-routing/+doc.svx   → /guides/routing, first in "Guides"

Manual outline

outline() takes a list, and each item in it is one of five things. They nest and mix freely:

  • A collection: every entry of it not placed yet, arranged as in Let a folder arrange itself.
  • pick(collection, ...patterns): chosen entries of one collection, flat, in the order you list them.
  • { label, items }: a sidebar group. items is a collection, a pick(), a function, or a list of more items.
  • { label, href }: a plain link. Its href is used as written; the mount prefix isn’t added.
  • () => items: a function that returns items (or a promise of them), called each time the outline is built.

You can pass the list straight to site({ outline: [...] }), or wrap it in outline(list, options?) when you want to pass redirect options.

Pick pages in order

pick() takes exact ids and globs. A * matches one part of an id and ** matches any depth, so guides/* is every page directly in guides and guides/** is every page anywhere below it. A glob’s matches come in the collection’s own order; the patterns come in the order you write them, so the order you write is the order readers get.

Put a collection under a path

A group takes four more options:

OptionWhat it does
baseA path in front of every address in the group: base: 'api' serves the entry button at /api/button. Use it when two collections have entries with the same id.
slug(id) => string, the address for an entry before base is added. slug: (id) => id.split('/').pop()! serves runes/state at /state while the sidebar keeps the Runes group. A nested group without its own slug uses this one.
badgeA label after the group’s name in the sidebar.
collapsedCarried into the tree as collapsed: true for a sidebar you draw yourself. The built-in Sidebar shows every group open today (#2284).
import { content, outline, pick, site } from '@ogygia/content';

const guides = content({
  loader: import.meta.og.loader.folder('../content/docs')
});
const api = content({
  loader: import.meta.og.loader.json('../content/api')
});

export const docs = site({
  outline: outline([
    {
      label: 'Start here',
      items: pick(guides, 'overview', 'install', 'quickstart')
    },
    guides,
    { label: 'API', items: api, base: 'api', collapsed: true },
    { label: 'Changelog', href: '/changelog' }
  ])
});
import { content, pick, site } from '@ogygia/content';

const guides = content({
  loader: import.meta.og.loader.folder('../content/docs')
});

export const docs = site({
  outline: [
    {
      label: 'Start here',
      items: pick(guides, 'quickstart', 'guides/**')
    },
    guides
  ]
});

Placement

Every entry lands in the tree exactly once. The outline reads your list from top to bottom: an item takes the entries it names, a later item that names an entry already placed skips it, and a bare collection takes whatever of it is left. So you can pick() a few pages into a “Start here” group and then list the collection to sweep up the rest, without either one showing twice.

Build errors

When the outline can’t be built, every read of it (the sidebar, a page, the prerender list) throws one error that lists each problem. The error carries no message code yet (#2284); its text contains outline could not be built:

  • pick id '…' not found: a pick() names an id the collection doesn’t have, or hides with its filter.
  • pick pattern '…' matched nothing: a glob matches no entry.
  • slug collision '…': two entries end up at one address. Give one of their groups a base.
  • unplaced entries: a collection appears only through pick(), and some of its entries are in no pick. List the collection itself somewhere, or pick them. The line reads collection #0 has 2 unplaced entries: …; collections are numbered in the order the outline first meets them, as in the other lines that name one.
  • redirect_from '…' shadows a live page or claimed by both: see Move a page without breaking links.
  • unrecognized outline node: an item that is none of the five kinds.

During a prerender this fails the build, and in dev it fails the page you open. Moving a file is safe because of it: the tree follows the file, or the build names the pick() that no longer matches. The link check covers the links that pointed at the old address.

When a live source or an edit in dev changes the content and the new content can’t be arranged, the site keeps the last tree that worked and logs content_outline_weave_failed with the same list. It tries again at the next change.

Dated posts

A blog orders by date, not by number. Pass dated() as the folder loader’s convention: a file named 2026-08-13-release.md sorts by its date, oldest first, and is served at /release. A blog folder holds .md files rather than +doc.svx folders, so the loader also needs page (which files are posts) and meta (which files label sections). Without page, every post fails with content_folder_unexpected_file. Folder options covers dated(), dateOf() and the rest.

import { content, dated, fields, site } from '@ogygia/content';

export const posts = content({
  loader: import.meta.og.loader.folder(
    '../content/blog/**/*.md',
    {
      page: /\.md$/,
      meta: /(^|\/)index\.md$/,
      convention: dated()
    }
  ),
  schema: fields.post
});

export const blog = site({ outline: posts });

Redirects

When a page moves, list its old addresses in its frontmatter under redirect_from, as one string or a list. Each old address joins the group’s base the same way the page’s own address does.

The site then serves a 308 from each old address to the new one: docs.load answers it, and docs.entries() lists the old addresses so a prerendered site bakes a redirect page for each. The link check warns about links that still use an old address.

Keep the field in your schema (fields.page does). A schema that doesn’t list it drops it, and the redirect silently never exists. Two mistakes fail the build: an old address that is also a live page’s address, and one old address claimed by two pages.

To read old addresses from somewhere else, pass redirects: (entry) => … returning a string, a list or nothing. Where it goes depends on how you pass the outline. With a collection or a plain list, it’s site({ redirects }). With an outline() value it’s outline(list, { redirects }), because site() doesn’t change an outline that’s already built and ignores its own redirects then (#2284). Inside dimensions(), return outline(list, { redirects }) from resolve.

---
title: Routing
redirect_from:
  - router
  - guides/navigation
---
import { content, outline, site } from '@ogygia/content';

const guides = content({
  loader: import.meta.og.loader.folder('../content/docs')
});

export const docs = site({
  outline: outline([guides], {
    redirects: (entry) =>
      entry.data.aliases as string[] | undefined
  })
});

Previous and next

Every page view carries trail.prev and trail.next: the pages before and after it in the sidebar, read from top to bottom. The <Pager> at the bottom of <Doc> shows them. Two site() options change them:

  • trail: 'site' (default) runs the reading order through the whole site. trail: 'group' stops it at the edge of each top-level group, so a site with several topics never links from the last page of one into the first page of the next.
  • prevNext picks the “keep reading” cards (trail.suggested). 'order' (default) suggests the next page. 'graph' suggests the pages the page names in its related field, or the next page when it names none. false suggests nothing.

'graph' needs the collection to turn related ids into entries: add relations: (self) => ({ related: self }) to it (Link entries to each other). Without that, trail.related is always empty and 'graph' acts like 'order'.

import { content, fields, site } from '@ogygia/content';

const guides = content({
  loader: import.meta.og.loader.folder('../content/docs'),
  schema: fields.page,
  relations: (self) => ({ related: self })
});

export const docs = site({
  outline: guides,
  prevNext: 'graph',
  trail: 'group'
});

Outline API

docs.outline is the built outline. Custom chrome and custom checks use it to look up addresses. Each method takes an optional read context, {} (the public view) by default: last, except neighbors, which takes it third, before scope ('site' or 'group', as trail):

MethodReturns
tree(base?)The sidebar tree, with each href built for base.
resolve(slug){ record, collection } for an address, or null. record holds entryId, section, crumbs and filePath.
addresses()Every page’s address, in reading order.
neighbors(slug, base?){ prev?, next? } for an address.
slug_for(collection, id)The address of one collection’s entry, or undefined. It’s how related ids become links.
alias(slug)The current address for an old one, or undefined.
aliases()Every old address mapped to its current one.

On a site with dimensions, docs.outline is a Dimensioned outline, and its tree is different: tree(base?, coordinate?, context?) takes the coordinate second. Code written for a plain outline that calls tree(base, ctx) there passes the read context as the coordinate and gets the default coordinate’s public tree, with no error (#2286). It also has five more members:

MemberWhat it is
axesThe axes you declared.
coordinateOf(slug)The coordinate an address names, with every axis filled in ({ version: 'v2', locale: 'de' }).
switcher(slug, base?, ctx?)The switcher data for that address.
fallbackOf(slug, ctx?){ axis, from, to } when the address is shown through fallback, else null.
canonicalAddresses(ctx?)The default coordinate’s addresses, the set search indexes.

isDimensioned(outline) tells the two apart, so code that can run on either kind checks first:

The outline is built on its first read, once per read context, and kept. Readers at the same moment share one build. It’s built again only when a collection it read has changed, which happens with a live source or an edit in dev.

hrefOf(base, slug) joins a mount prefix and an address into a link, with one slash between them: hrefOf('/docs', 'routing') is '/docs/routing' and hrefOf('', 'routing') is '/routing'. Use it in custom chrome so links stay right under any prefix. Here an endpoint sends visitors to the site’s first page:

import {
  isDimensioned,
  type NavTree,
  type Outline,
  type ReadContext
} from '@ogygia/content';

export function treeOf(
  outline: Outline,
  base: string,
  ctx: ReadContext
): Promise<NavTree> {
  return isDimensioned(outline)
    ? outline.tree(base, undefined, ctx)
    : outline.tree(base, ctx);
}
import { redirect } from '@sveltejs/kit';
import { hrefOf } from '@ogygia/content';
import { docs } from '$lib/docs.server';

export const GET = async () => {
  const [first] = await docs.outline.addresses();
  redirect(307, hrefOf('/docs', first ?? ''));
};

Do and don’t

  • Do let a bare collection sweep up what you didn’t place. Pick only the pages that need a particular home.
  • Do treat an outline error as a real mistake: a page nobody can reach, or two pages at one address.
  • Do add redirect_from when you move a page, and keep the field in your schema.
  • Don’t keep a separate list of pages by hand. A new file joins the sidebar as soon as the collection sees it.
  • Don’t put order in +meta.json. Order comes from the NN- prefix (or the date); the sidebar file names the section, and "ordered": false in it turns the prefix check off (Folder options).