From 6e6de5d0cc4e3d5f2e83359ef5880725a5b2f268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Thu, 29 Oct 2026 14:13:37 +0100 Subject: [PATCH] Block library: noSnippet option for sections repeated on every page Co-Authored-By: Claude Opus 5.5 --- docs/agent/skills/ipal-reference/resources/api.md | 2 +- docs/block-library.md | 1 + src/modules/block-library/registry.tsx | 14 ++++++++++++-- test/blockLibraryRender.test.ts | 6 ++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index e49a3c4..2ee92af 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -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`. | diff --git a/docs/block-library.md b/docs/block-library.md index dee6c5a..07f3816 100644 --- a/docs/block-library.md +++ b/docs/block-library.md @@ -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 (``), 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, diff --git a/src/modules/block-library/registry.tsx b/src/modules/block-library/registry.tsx index 6e1ae4c..9b95ed6 100644 --- a/src/modules/block-library/registry.tsx +++ b/src/modules/block-library/registry.tsx @@ -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>> /** 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> - const bound = (props: Record) => + const hidden = noSnippet.includes(slug) + const bound = (props: Record) => { + const block = + return hidden ? {block} : block + } bound.displayName = `Library(${slug})` map[slugs[slug] ?? slug] = bound } diff --git a/test/blockLibraryRender.test.ts b/test/blockLibraryRender.test.ts index 86ba800..ed1a267 100644 --- a/test/blockLibraryRender.test.ts +++ b/test/blockLibraryRender.test.ts @@ -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(/^
/) + 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 }))