Skip to content

Macros

regions

A block registry built from a folder glob. One line replaces the N hand-written `with { region: 'raw' }` imports a CMS block map needs, and it can never drift out of sync with the folder.

On this page

import.meta.og.regions(glob) builds a block registry from a folder. Without it, a CMS block map is N hand-written import lines that quietly fall out of sync with the folder:

// the manual way — every block a line, easy to forget one
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 };

The macro reduces that to one line that cannot drift:

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

At build time it globs the pattern (relative to the module), emits one with { region: 'raw' } import for each match, and assembles a registry keyed by each file’s basename, which is the name your CMS type field refers to. Each block is a raw held region, so islands nested inside a block still wake.

Keys are the basename, verbatim

A file named Hero.svelte becomes the key "Hero", and hero-banner.svelte becomes "hero-banner", with no PascalCasing or other guessing. The key is exactly the basename because it has to match the type string in your content, and you control both the filename and the type. If two files in the glob normalize to the same key, the build fails with an error that names both.

Blocks that need a schedule

regions() makes each match a raw region, rendered inline during SSR with no client JS unless something inside it wakes. A block that needs its own wake schedule (such as a Counter that hydrates when visible) stays a manual import, spread on top:

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

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

The rules

  • The glob is a literal string, resolved relative to the module at build time. A non-literal argument is a build error.
  • Server-only. A block registry drives SSR, so it belongs in server code next to your blocks collection.

Blocks shows how a registry feeds blocks() and blocks.resolve() to turn a CMS tree into rendered regions.