Files
klz-cables.com/components/JsonLd.tsx
Marc Mintel 7cb3763125
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Successful in 2m5s
Build & Deploy / 🏗️ Build (push) Successful in 5m22s
Build & Deploy / 🚀 Deploy (push) Successful in 19s
Build & Deploy / 🧪 Post-Deploy Verification (push) Failing after 4m42s
Build & Deploy / 🔔 Notify (push) Successful in 2s
fix: resolve typescript error and lint warnings
- Fix TS2698 in JsonLd.tsx (spread types)
- Clean up unused variable in analytics route
2026-04-12 22:42:04 +02:00

67 lines
2.0 KiB
TypeScript

import { Thing, WithContext } from 'schema-dts';
interface JsonLdProps {
id?: string;
data?: WithContext<Thing> | WithContext<Thing>[];
}
export default function JsonLd({ id, data }: JsonLdProps) {
// If data is provided, use it. Otherwise, use the default Organization + WebSite schema.
const rawData = data || [
{
'@context': 'https://schema.org',
'@type': 'Organization',
name: 'KLZ Cables',
url: 'https://klz-cables.com',
logo: 'https://klz-cables.com/logo-blue.svg',
sameAs: ['https://www.linkedin.com/company/klz-cables'],
description: 'Premium Cable Solutions for Renewable Energy and Infrastructure.',
address: {
'@type': 'PostalAddress',
addressCountry: 'DE',
},
},
{
'@context': 'https://schema.org',
'@type': 'WebSite',
name: 'KLZ Cables',
url: 'https://klz-cables.com',
potentialAction: {
'@type': 'SearchAction',
target: {
'@type': 'EntryPoint',
urlTemplate: 'https://klz-cables.com/search?q={search_term_string}',
},
'query-input': 'required name=search_term_string',
},
},
];
// Harden schema items: Ensure each item is an object and has @context
const schemaData = (Array.isArray(rawData) ? rawData : [rawData])
.filter((item): item is WithContext<Thing> => {
// Basic sanity check: must be an object and not null
return typeof item === 'object' && item !== null;
})
.map((item) => {
// Ensure @context is present and correctly typed for consumer libraries
if (!item['@context']) {
return {
...(item as Record<string, any>),
'@context': 'https://schema.org',
} as WithContext<Thing>;
}
return item;
});
return (
<script
id={id}
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(schemaData.length === 1 ? schemaData[0] : schemaData),
}}
/>
);
}