Files
imen_pishghaman/src/lib/seo/schema.ts
T

54 lines
1.3 KiB
TypeScript
Raw Normal View History

import { siteConfig as s } from "@/config/site";
const abs = (p: string) => new URL(p, s.url).toString();
const clean = <T extends object>(o: T) =>
JSON.parse(
JSON.stringify(o, (_, v) =>
v === "" || (Array.isArray(v) && !v.length) ? undefined : v,
),
);
export const organizationSchema = () =>
clean({
"@context": "https://schema.org",
"@type": "LocalBusiness",
"@id": `${s.url}/#organization`,
name: s.name,
url: s.url,
logo: abs(s.logo),
image: abs(s.logo),
email: s.contact.email,
telephone: s.contact.phone,
address: {
"@type": "PostalAddress",
streetAddress: s.contact.address.streetAddress,
addressLocality: s.contact.address.addressLocality,
addressCountry: s.contact.address.addressCountry,
},
sameAs: s.socials,
});
export const websiteSchema = () => ({
"@context": "https://schema.org",
"@type": "WebSite",
"@id": `${s.url}/#website`,
url: s.url,
name: s.name,
inLanguage: s.lang,
publisher: { "@id": `${s.url}/#organization` },
});
export const serviceSchema = (opts: {
name: string;
description: string;
areaServed?: string;
}) =>
clean({
"@context": "https://schema.org",
"@type": "Service",
name: opts.name,
description: opts.description,
areaServed: opts.areaServed,
provider: { "@id": `${s.url}/#organization` },
});