Added JsonLdGraph.tsx

This commit is contained in:
2026-10-09 17:25:22 +02:00
parent f5a4ceb5bf
commit eb6efa26f6
14 changed files with 434 additions and 44 deletions
+1
View File
@@ -14,4 +14,5 @@ export type {
} from '../modules/blocks/index.js'
export { RenderRichText } from '../modules/richtext/index.js'
export type { RenderRichTextProps } from '../modules/richtext/index.js'
export { JsonLdGraph } from '../modules/seo/index.js'
export { MediaPreconnect } from '../modules/storage/MediaPreconnect.js'
+41
View File
@@ -0,0 +1,41 @@
type JsonLdSchema = Record<string, unknown>
/**
* Renders one or more schema.org objects as a single JSON-LD @graph in a
* <script type="application/ld+json">. The plugin owns ONLY the wrapping and the
* safe serialization — NOT the schema contents. The project builds its own nodes
* (with the plugin's buildWebSiteJsonLd / buildOrganizationJsonLd /
* buildLocalBusinessJsonLd / buildSiteNavigationJsonLd helpers) and maps its own
* company data to the right @type.
*
* Why not a <GlobalJsonLd> that reads Company/Header: company data is a business
* domain that varies by country and industry (NIP/KRS in PL, ABN in AU, EIN in
* US; barAssociation for a law firm, licenceText for an HVAC business). A fixed
* model would be a leaky abstraction. So the project decides the @type and
* fields; the plugin just wraps and renders safely.
*
* // project — build nodes from YOUR data, choose the @type for YOUR market
* import { JsonLdGraph, buildWebSiteJsonLd, buildOrganizationJsonLd } from '@intecion/ipal-kit'
* const website = buildWebSiteJsonLd({ name, url })
* const org = buildOrganizationJsonLd({ name, url, logo })
* const localBusiness = { '@type': 'HVACBusiness', taxID: company.abn, areaServed: company.serviceArea, ... }
* <JsonLdGraph schemas={[website, org, localBusiness]} />
*
* Replaces the ~140-line JsonLd.tsx (only the @graph wrapper + <script> was
* actually duplicated; the schema mapping stays in the project where it belongs).
*/
export function JsonLdGraph({ schemas }: { schemas: Array<JsonLdSchema | null | undefined> }) {
const graph = schemas.filter((s): s is JsonLdSchema => Boolean(s))
if (graph.length === 0) {return null}
const json = JSON.stringify({ '@context': 'https://schema.org', '@graph': graph })
return (
<script
// Escape '<' to prevent the JSON from breaking out of the script tag
// (XSS hardening) — the only safety concern the plugin owns here.
dangerouslySetInnerHTML={{ __html: json.replace(/</g, '\\u003c') }}
type="application/ld+json"
/>
)
}
+1
View File
@@ -25,6 +25,7 @@ export { createPageMetadata } from './createPageMetadata.js'
export { buildHreflangAlternates } from './hreflang.js'
export { injectAutoFillMeta } from './injectAutoFillMeta.js'
export { injectSeoTabs } from './injectSeoTabs.js'
export { JsonLdGraph } from './JsonLdGraph.js'
export { readSiteMetaConfig } from './readSiteMetaConfig.js'
export type { SiteMetaConfig } from './readSiteMetaConfig.js'
export { createLlmsTxtRoute, createSitemapRouteHandler } from './routeHandlers.js'