Block library: noSnippet option for sections repeated on every page

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 14:13:37 +01:00
co-authored by Claude Opus 5.5
parent 2a07fb8844
commit 6e6de5d0cc
4 changed files with 20 additions and 3 deletions
@@ -125,7 +125,7 @@ Fifteen ready blocks and ten page templates. **Use a library block (or a variant
| `blockThumbnail(slug)` | `@intecion/ipal-kit/blocks` | Inline SVG sketch (data URL) for the block picker — what `thumbnail: true` uses. |
| `faqItemsFromLayout(doc, { field?, slugs? })` | `@intecion/ipal-kit/blocks` | FAQ questions of the page's FAQ blocks → `getPageJsonLd(locale, slug, { faq: faqItemsFromLayout })` (FAQPage). |
| `blockLibraryManifest`, `buildBlockLibraryManifest()`, `fieldPaths(fields)` | `@intecion/ipal-kit/blocks` | Plain data: every block's slug, interface name, variants, stored field paths; primitives, field builders, templates — for `ipal-doctor` and tests. |
| `createBlockRegistry(content, options?)` | `@intecion/ipal-kit/blocks/rsc` | `blockType → component` map for `createPageRoute` / `RenderBlocks`, bound to lib/content. Options: `Image`, `Link` (next/image, next/link), `sendForm`, `formClassNames`, `contactDetails`, `classNames` (per block part), `ui` (swap primitives), `components` (swap a block), `backgrounds`, `slugs`, `only`, `extra` (own blocks), `icons`, `texts`, `lightbox`, `richText`, `entryCard`, `mapTestimonial`. |
| `createBlockRegistry(content, options?)` | `@intecion/ipal-kit/blocks/rsc` | `blockType → component` map for `createPageRoute` / `RenderBlocks`, bound to lib/content. Options: `Image`, `Link` (next/image, next/link), `sendForm`, `formClassNames`, `contactDetails`, `classNames` (per block part), `ui` (swap primitives), `components` (swap a block), `backgrounds`, `slugs`, `only`, `extra` (own blocks), `noSnippet` (e.g. `['cta']`), `icons`, `texts`, `lightbox`, `richText`, `entryCard`, `mapTestimonial`. |
| `LIBRARY_BLOCK_COMPONENTS` | `@intecion/ipal-kit/blocks/rsc` | The plugin's component per slug. |
| `HeroBlock`, `TextMediaBlock`, `FeatureGridBlock`, `GalleryBlock`, `FaqBlock`, `CtaBlock`, `ContactBlock`, `TeamBlock`, `PricingBlock`, `LogosBlock`, `TestimonialsBlock`, `StatsBlock`, `RichTextBlock`, `StepsBlock`, `EntryListBlock` | `@intecion/ipal-kit/blocks/rsc` | The block components (server; props `LibraryBlockProps`: data + `locale`, `isFirst`, `ui`, `ctx`, `classNames`). |
| `HERO_PARTS`, `TEXT_MEDIA_PARTS`, `FEATURE_GRID_PARTS`, `GALLERY_PARTS`, `FAQ_PARTS`, `CTA_PARTS`, `CONTACT_PARTS`, `TEAM_PARTS`, `PRICING_PARTS`, `LOGOS_PARTS`, `TESTIMONIALS_PARTS`, `STATS_PARTS`, `RICH_TEXT_PARTS`, `STEPS_PARTS`, `ENTRY_LIST_PARTS` | `@intecion/ipal-kit/blocks/rsc` | Default token classes per block part — the keys of `classNames`. |
+1
View File
@@ -158,6 +158,7 @@ plugin's components. `content` needs `resolveLink`; `getEntries` (entry list), `
| `Image`, `Link` | next/image and next/link |
| `sendForm`, `formClassNames`, `contactDetails` | the contact block: form action, form classes, details beside the form |
| `entryCard`, `mapTestimonial` | how a collection document becomes an entry card / a testimonial (defaults `defaultEntryCard`, `defaultTestimonial`) |
| `noSnippet` | blocks kept out of Google's snippets (`<NoSnippet>`), e.g. `['cta']` when the same call to action is on every page (docs/seo.md) |
| `icons`, `texts`, `lightbox`, `richText` | feature icons by name; visitor texts; `lightbox: false` = plain gallery images; `richText.className` for every rich text |
**UI primitives** (`/blocks/rsc`), each styled once with token utilities: `Section` (anchor, background,
+12 -2
View File
@@ -8,6 +8,7 @@ import type { PartClasses } from './ui/cx.js'
import type { MediaProps } from './ui/Media.js'
import type { SectionProps } from './ui/Section.js'
import { NoSnippet } from '../seo/NoSnippet.js'
import { ContactBlock } from './blocks/contact/Component.js'
import { CtaBlock } from './blocks/cta/Component.js'
import { EntryListBlock } from './blocks/entryList/Component.js'
@@ -59,6 +60,11 @@ export type BlockRegistryOptions = {
components?: Partial<Record<LibraryBlockSlug, ComponentType<never>>>
/** The project's own blocks, in the same registry. */
extra?: BlockComponentMap
/**
* Blocks kept out of Google's snippets (`data-nosnippet`) — for sections repeated on every page,
* e.g. `['cta']`, so the same call to action is not quoted under every result. Default none.
*/
noSnippet?: readonly LibraryBlockSlug[]
/** Turn on only these library blocks. Default: all 15 (an unused entry costs nothing). */
only?: readonly LibraryBlockSlug[]
/** Renamed slugs (BlockOptions `slug`), so the registry key matches the stored blockType. */
@@ -77,13 +83,17 @@ export type BlockRegistryOptions = {
* Everything is bound on the server, so no function crosses to the client.
*/
export function createBlockRegistry(content: BlockContent, options: BlockRegistryOptions = {}): BlockComponentMap {
const { backgrounds, classNames = {}, components = {}, extra = {}, only, slugs = {}, ui: own = {}, ...rest } = options
const { backgrounds, classNames = {}, components = {}, extra = {}, noSnippet = [], only, slugs = {}, ui: own = {}, ...rest } = options
const ctx: BlockContext = { ...rest, content, lightbox: rest.lightbox ?? true }
const ui = buildUi(ctx, own, backgrounds)
const map: BlockComponentMap = {}
for (const slug of only ?? (Object.keys(LIBRARY_BLOCK_COMPONENTS) as LibraryBlockSlug[])) {
const Block = (components[slug] ?? LIBRARY_BLOCK_COMPONENTS[slug]) as ComponentType<Record<string, unknown>>
const bound = (props: Record<string, unknown>) => <Block {...props} classNames={classNames[slug]} ctx={ctx} ui={ui} />
const hidden = noSnippet.includes(slug)
const bound = (props: Record<string, unknown>) => {
const block = <Block {...props} classNames={classNames[slug]} ctx={ctx} ui={ui} />
return hidden ? <NoSnippet>{block}</NoSnippet> : block
}
bound.displayName = `Library(${slug})`
map[slugs[slug] ?? slug] = bound
}
+6
View File
@@ -237,6 +237,12 @@ describe('block details', () => {
warn.mockRestore()
})
test('noSnippet keeps a repeated section out of search snippets', async () => {
const map = createBlockRegistry(content, { noSnippet: ['cta'] })
expect(await render(h(map.cta, { blockType: 'cta', header, locale: 'en', ...SAMPLES.cta }))).toMatch(/^<div><div data-nosnippet="">/)
expect(await render(block('cta'))).not.toContain('data-nosnippet')
})
test('classNames replace one part’s classes', async () => {
const map = createBlockRegistry(content, { classNames: { faq: { item: 'my-item' } } })
const html = await render(h(map.faq, { blockType: 'faq', locale: 'en', ...SAMPLES.faq }))