Skip to content

Macros

regions

A block registry 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 from the folder.

On this page

import.meta.og.regions(glob) builds a block registry from a folder. A CMS block map is otherwise 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 collapses that to one line that cannot drift:

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

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

Keys are the basename, verbatim

A file Hero.svelte becomes the key "Hero"; hero-banner.svelte becomes "hero-banner". No PascalCasing, no guessing. The key is the basename exactly, 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, that’s a build error naming both.

Blocks that need a schedule

regions() makes every match a raw region: SSR’d inline, no client JS unless something inside wakes. A block that needs its own wake schedule (a Counter that hydrates on visibility) stays a manual import, spread over the 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. A non-literal argument is a build error.
  • Server-only. A block registry drives SSR, so it belongs alongside your blocks collection in server code.

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