type MediaLike = { url?: null | string } | null | undefined type OrganizationJsonLdArgs = { /** Logo media (from panel). Google uses this for brand knowledge panels. */ logo?: MediaLike /** Organization / site name. */ name: string /** Optional social / official profile URLs (sameAs). */ sameAs?: string[] /** Absolute site URL (https://…). */ url: string } /** * Builds Organization JSON-LD (schema.org) — helps Google associate the site * with a brand: name, logo, official links. Improves how the site appears in * search (brand recognition, logo in knowledge panels) and is a signal used * alongside favicon for identity. * * Returns a plain object; the project renders it with in the * root layout: * * import { buildOrganizationJsonLd } from '@intecion/ipal-kit' * const jsonLd = buildOrganizationJsonLd({ * name: settings.siteName, url: baseUrl, logo: settings.logo, * }) * // render through JsonLdGraph (@intecion/ipal-kit/rsc) — it escapes '<' and wraps @graph: * * * Data comes from the panel (siteName, logo) — nothing hardcoded. Emit once in * the root layout (Organization is site-wide, not per page). */ export function buildOrganizationJsonLd({ name, logo, sameAs, url }: OrganizationJsonLdArgs) { const logoUrl = logo?.url return { name, '@context': 'https://schema.org', '@type': 'Organization', url, ...(logoUrl ? { logo: logoUrl.startsWith('http') ? logoUrl : `${url}${logoUrl}` } : {}), ...(sameAs && sameAs.length > 0 ? { sameAs } : {}), } } /** * Profile URLs from Site Settings → sameAs (array of { url }), ready for * buildOrganizationJsonLd / buildLocalBusinessJsonLd. Empty when none. */ export function sameAsUrls(settings: null | Record | undefined): string[] { const rows = settings?.sameAs if (!Array.isArray(rows)) {return []} return rows .map((r) => (r && typeof r === 'object' ? (r as { url?: unknown }).url : undefined)) .filter((u): u is string => typeof u === 'string' && /^https?:\/\//.test(u)) }