49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
type ServiceJsonLdArgs = {
|
|
/** Area served, e.g. 'Wrocław' or ['Wrocław', 'Oława']. */
|
|
areaServed?: string | string[]
|
|
description?: string
|
|
/** Service name, e.g. 'Sprzątanie biur'. */
|
|
name: string
|
|
/** Provider (business) name. */
|
|
providerName: string
|
|
/** Service type / category. */
|
|
serviceType?: string
|
|
url: string
|
|
}
|
|
|
|
/**
|
|
* Builds Service JSON-LD (schema.org) for a service offering. Helps Google
|
|
* understand "what this page sells" — useful for service landing pages
|
|
* ("usługa + miasto"). Pairs well with LocalBusiness (the provider).
|
|
*
|
|
* Per-page (each service page emits its own), data from the panel:
|
|
*
|
|
* import { buildServiceJsonLd } from '@intecion/ipal-kit'
|
|
* const jsonLd = buildServiceJsonLd({
|
|
* name: page.serviceName, providerName: company.name,
|
|
* url: pageUrl, areaServed: 'Wrocław',
|
|
* })
|
|
*/
|
|
export function buildServiceJsonLd({
|
|
name,
|
|
areaServed,
|
|
description,
|
|
providerName,
|
|
serviceType,
|
|
url,
|
|
}: ServiceJsonLdArgs) {
|
|
return {
|
|
name,
|
|
'@context': 'https://schema.org',
|
|
'@type': 'Service',
|
|
provider: {
|
|
name: providerName,
|
|
'@type': 'LocalBusiness',
|
|
url,
|
|
},
|
|
...(description ? { description } : {}),
|
|
...(areaServed ? { areaServed } : {}),
|
|
...(serviceType ? { serviceType } : {}),
|
|
}
|
|
}
|