feat(www): add Product JSON-LD builder
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
buildWebSiteJsonLd,
|
||||
buildBreadcrumbJsonLd,
|
||||
buildTitle,
|
||||
buildProductJsonLd,
|
||||
} from "./seo";
|
||||
|
||||
describe("seo builders", () => {
|
||||
@@ -70,4 +71,18 @@ describe("seo builders", () => {
|
||||
it("buildTitle appends the brand", () => {
|
||||
expect(buildTitle("PostgreSQL GUI")).toBe("PostgreSQL GUI | Gridline");
|
||||
});
|
||||
|
||||
it("buildProductJsonLd returns valid Product schema", () => {
|
||||
const ld = buildProductJsonLd({
|
||||
name: "Gridline",
|
||||
url: "https://getgridline.app/",
|
||||
description: "Open-source database GUI",
|
||||
image: "https://getgridline.app/og.png",
|
||||
offersPrice: 0,
|
||||
offersCurrency: "USD",
|
||||
});
|
||||
expect(ld["@type"]).toBe("Product");
|
||||
expect(ld.name).toBe("Gridline");
|
||||
expect((ld.offers as { price: number }).price).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,3 +108,26 @@ export function buildBreadcrumbJsonLd(
|
||||
export function buildTitle(primary: string, brand = "Gridline"): string {
|
||||
return `${primary} | ${brand}`;
|
||||
}
|
||||
|
||||
export function buildProductJsonLd(opts: {
|
||||
name: string;
|
||||
url: string;
|
||||
description: string;
|
||||
image: string;
|
||||
offersPrice: number;
|
||||
offersCurrency: string;
|
||||
}): JsonLd {
|
||||
return {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Product",
|
||||
name: opts.name,
|
||||
url: opts.url,
|
||||
description: opts.description,
|
||||
image: opts.image,
|
||||
offers: {
|
||||
"@type": "Offer",
|
||||
price: opts.offersPrice,
|
||||
priceCurrency: opts.offersCurrency,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user