Skip to content

@ogygia/content · Macros

Block registry

import.meta.og.regions('./blocks/*.svelte') imports every component a glob matches as a static held region and returns them keyed by file name. One line replaces a hand-written import per block, and it can't fall out of step with the folder.

On this page

A block registry maps each type name your CMS sends to a component, and written by hand it’s one import per block. Add a file to the folder, forget its line, and the CMS’s new block silently doesn’t render:

import.meta.og.regions(glob) writes those lines for you. At build time it finds every file the glob matches, relative to the module, writes one with { region: 'raw' } import for each, and replaces the call with an object of them, keyed by file name. A file added to the folder is in the registry on the next build.

regions comes with @ogygia/content: list its content() plugin beside ogygia() and add /// <reference types="@ogygia/content/types" /> to src/ogygia.d.ts (Install). Without the plugin, a call fails the build with macro_needs_plugin.

import Hero from './blocks/Hero.svelte' with { region: 'raw' };
import Prose from './blocks/Prose.svelte' with {
  region: 'raw'
};
import Callout from './blocks/Callout.svelte' with {
  region: 'raw'
};

export const registry = { Hero, Prose, Callout };
export const registry = import.meta.og.regions(
  './blocks/*.svelte'
);
// at build: { Callout: …, Hero: …, Prose: … }

Keys

Hero.svelte becomes Hero, and hero-banner.svelte becomes hero-banner. Nothing is recased, because the key has to equal the type string in your content exactly, and you control both. Files in sub-folders ('./blocks/**/*.svelte') are keyed by their name alone, so two files with one name in different folders fail the build with content_regions_key_collision, naming both.

Held regions

Every match is imported with { region: 'raw' }: it renders as server HTML, ships no JavaScript, and its stylesheet loads only on pages that use it. Islands nested inside a block still wake. Held regions explains the mark.

A block that should hydrate needs a wake schedule, which the macro doesn’t give. Import it yourself and spread the registry under it; a key you write after the spread replaces the one the glob made.

import Counter from './blocks/Counter.svelte' with {
  wake: 'visible'
};

export const registry = {
  ...import.meta.og.regions('./blocks/*.svelte'),
  Counter
};

Rules

  • The glob is a string in the source. A variable fails with call_arg_not_literal, a template literal with ${…} with call_arg_interpolated, and an expression around the string ('./blocks/' + x) with call_arg_in_expression.
  • A glob that matches nothing gives {}. That’s no error, so a typo in the path drops every block. The only sign is a dev-only content_block_unregistered warning for each block the page can’t find.
  • It’s rewritten in .ts and .js modules only. A held region’s mark is read in a script module, so keep the registry in one and import it where you need it. In a .svelte file the call is left as it is, with no build error or warning, and it fails when it runs. (The loaders warn in that case; regions doesn’t yet.)
  • It runs on the server. A region: 'raw' block is signed with your server’s key, so the registry is turned into regions in a load, a remote function or a csr = false server render; blocks() and blocks.resolve do that for you.
  • It reads the folder when the module is compiled. In dev, a block file you add or delete shows up once the registry module is compiled again: save it, or restart the dev server.
  • Node 22 or later. The macro finds files with Node’s fs.globSync.