Skip to content

@ogygia/content · Docs sites

Versioning and i18n

dimensions() runs one site across several versions, languages or both. Each one gets its own sidebar under a URL prefix, a switcher keeps the reader on the same page, and an untranslated page shows the default language instead of a 404.

On this page

Docs for v1 and v2, or a site in English and German, usually share one structure: the same page exists once per edition. Building a separate site for each edition repeats the sidebar, the search and every link between them. dimensions() treats a version or a language as an axis of one site instead. Each combination of values is a coordinate ({ version: 'v1', locale: 'de' }), each coordinate has its own outline, and the coordinate is written at the front of the URL.

The Playground ↗ has a version switcher (v1, v2) and a language switcher (English, Hindi) in its header; its v1 and Hindi corpora are small on purpose, so you can watch the fallback and the switcher at work.

If your versions are different content with different structures, give them separate sites; dimensions are for one structure read in several editions.

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

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

export const docs = site({
  outline: dimensions({
    axes: {
      version: {
        values: ['v2', 'v1'],
        default: 'v2',
        label: 'Version'
      }
    },
    resolve: ({ version }) => (version === 'v1' ? v1 : v2)
  })
});
// /docs/routing     → v2, the default, at the bare address
// /docs/v1/routing  → v1

Axes

dimensions({ axes, resolve }) takes the axes as an object keyed by name, and a resolve function that returns the outline for one coordinate. Each axis takes:

OptionDefaultWhat it does
valuesrequiredEvery value, in the order the switcher lists them.
defaultthe first of valuesThe value served at the bare address, with nothing in the URL.
fallbackfalsetrue shows the default value’s page when a page is missing in another value. See Fall back.
labelthe axis name, capitalizedThe switcher’s label.

dimensions() checks the axes when you call it. No axes at all throws content_dimensions_no_axis, and a default that isn’t in values throws content_axis_default_missing.

Two axes compose. Here every version has an English and a German corpus, and resolve picks the right one:

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

const corpora = {
  v2: {
    en: content({
      loader: import.meta.og.loader.folder('../content/v2/en')
    }),
    de: content({
      loader: import.meta.og.loader.folder('../content/v2/de')
    })
  },
  v1: {
    en: content({
      loader: import.meta.og.loader.folder('../content/v1/en')
    }),
    de: content({
      loader: import.meta.og.loader.folder('../content/v1/de')
    })
  }
};

export const docs = site({
  outline: dimensions({
    axes: {
      version: {
        values: ['v2', 'v1'],
        default: 'v2',
        label: 'Version'
      },
      locale: {
        values: ['en', 'de'],
        default: 'en',
        label: 'Language',
        fallback: true
      }
    },
    resolve: ({ version, locale }) =>
      corpora[version as 'v2' | 'v1'][locale as 'en' | 'de']
  })
});

URLs

The default value of each axis is left out of the URL. Every other value is a leading segment, in the order the axes are declared. With the two axes above:

AddressCoordinate
/docs/routingv2, English
/docs/de/routingv2, German
/docs/v1/routingv1, English
/docs/v1/de/routingv1, German

The segments must come in declaration order: /docs/de/v1/routing reads as German v2 with a page called v1/routing. A default value written out is not a coordinate either, so /docs/en/routing looks for a page called en/routing and is a 404. Because a leading segment that matches a value is always read as a coordinate, don’t give a page an address that starts with one of the values.

Nothing changes in your routes. The same [...slug] catch-all serves every coordinate, and docs.load and docs.entries read the coordinate off the slug.

Fallbacks

Missing translations are the usual state of a translated site. On an axis with fallback: true, a page that is missing in a value is shown from the default value, at the address that was asked for, instead of a 404. Every page therefore exists at every coordinate of that axis, and the switcher can always link to the same page.

The page view says when it happened: view.fallback is { axis, from, to } ({ axis: 'locale', from: 'de', to: 'en' }), or null for a page native to its coordinate. <Doc> shows a note above the body on its own, naming both values, styled by the .og-fallback class. view.coordinate holds the coordinate the address names; the page below puts the version in the eyebrow above the title.

Turn fallback on for languages, and usually not for versions. A page missing from v1 most often didn’t exist in v1, and a 404 says so.

A fallback page is shown, but it isn’t part of its coordinate’s tree: it doesn’t appear in that coordinate’s sidebar, and it has no previous or next page (#2284).

<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 ?? ''))!;
  const eyebrow = view.coordinate
    ? `${view.coordinate.version} · ${view.section}`
    : view.section;
</script>

<Doc {view} {eyebrow} />

Switcher

docs.switcher(slug, { base? }) returns the picker for the coordinate in slug: one entry per axis with its axis name (what <Switcher for> matches), its label, its current value and its options. Each option has a value, an href, current, and missing. The href is the same page in that value, or the fallback page when the axis falls back. When the page doesn’t exist there at all, the href is that coordinate’s first page and missing is true, so a link never dead-ends. On a site without dimensions, switcher() returns null.

You rarely call it yourself. docs.meta({ slug }), and the meta remote as meta(slug), include it, and DocsShell renders it with the <Switcher> component: a dropdown per axis that navigates on choice. DocsShell places two axes by name: version beside the brand, and locale with the search and theme toggle. An axis with any other name doesn’t appear in DocsShell’s header, and the phone bottom bar shows no switcher today (#2284).

In the shell layout, pass the current slug to the meta remote, so the shell gets that coordinate’s sidebar and switcher. With an axis named anything other than version or locale, also render the switcher yourself in the tools region; for limits it to the axes you name. Replacing tools drops what it held (search, the language switcher, the theme toggle, actions), so put back the ones you want:

<script lang="ts">
  import { page } from '$app/state';
  import DocsShell from '@ogygia/content/docs-shell';
  import {
    Search,
    Switcher,
    ThemeToggle
  } from '@ogygia/content' with { wake: 'load' };
  import '@ogygia/content/theme.css';
  import '@ogygia/content/shell.css';
  import { meta } from '$lib/docs.remote';

  let { children } = $props();
  const shell = await  meta(
    page.params.slug ?? ''
  ); 
</script>

<DocsShell meta={shell} base="/docs" title="Example">
  {#snippet tools()}
    <div class="og-cheader-tools">
      <Search base="/docs" />
      {#if shell.switcher}<Switcher
          switcher={shell.switcher}
          for="framework"
        />{/if}
      <ThemeToggle />
    </div>
  {/snippet}
  {@render children()}
</DocsShell>

Cross-version behavior

Each read decides which coordinate it serves:

  • nav and meta build the tree for the coordinate in the slug you pass; a bare prefix like 'v1/' works too. With no slug they serve the default coordinate. As prerendered remotes, each distinct slug is one stored answer.
  • page resolves the coordinate from the slug and falls back where the axis allows.
  • entries() lists every address at every coordinate, fallback pages included, so a page that exists in one coordinate only still prerenders there. Old addresses from redirect_from get their coordinate’s prefix. They don’t follow fallback: an old address of a page that exists only in the default language is a 404 under another language (#2286).
  • Search indexes the default coordinate only, so a fallback page is never a second hit for the same text, and every hit links to a default-coordinate page.
  • The sitemap and llms.txt list the default coordinate’s pages. Raw markdown serves every coordinate.
  • Prev and next stay inside the page’s coordinate.
  • related links, the “keep reading” cards and bare prose links don’t. They resolve in the default coordinate, or the first coordinate whose outline holds the collection, so on a fallback page or with a collection shared across coordinates they can take the reader to another version or language (#2286).

Sources

resolve returns a collection, a list of outline items, an outline() value, or a promise of any of them. It’s called once per coordinate, the first time that coordinate is read, and the answer is kept. A resolve that throws isn’t kept, so the next read of that coordinate tries again.

Where a version’s content comes from is up to you. A folder per version works, and so does a tag of a repository whose docs are .md files: the git loader reads the tag at build time, with no copy in your repo. git() reads only .md files for now, so it can’t read a +doc.svx corpus, such as this site’s own older tags (#2286). Here v1 is the docs folder of such a repository at its v1.4.0 tag, with page and meta set for plain .md files as the loaders page shows:

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

const v2 = content({
  loader: import.meta.og.loader.folder('../content/docs')
});
const v1 = content({
  loader: import.meta.og.loader.git(
    'example/docs@v1.4.0:docs',
    {
      page: /\.md$/,
      meta: /(^|\/)index\.md$/
    }
  )
});

export const docs = site({
  outline: dimensions({
    axes: { version: { values: ['v2', 'v1'] } },
    resolve: ({ version }) => [
      { label: 'Guides', items: version === 'v1' ? v1 : v2 }
    ]
  })
});

Do and don’t

  • Do model versions and languages as axes of one site, so there’s one structure to maintain.
  • Do turn on fallback for languages, so a missing translation shows the original instead of breaking the URL.
  • Do pass the current slug to meta, or every page gets the default coordinate’s sidebar.
  • Don’t start a page’s address with one of an axis’s values; it’s read as a coordinate.
  • Don’t expect search to find text that only exists in a non-default version. It indexes the default coordinate.