Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cms/faststore/sections.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,21 @@
}
}
}
},
{
"name": "CustomProductSEOSection",
"schema": {
"title": "Custom Product SEO",
"description": "Add SEO metadata to product pages",
"type": "object",
"required": ["skipLazyLoadingSection"],
"properties": {
"skipLazyLoadingSection": {
"title": "Skip lazy loading",
"type": "boolean",
"default": true
}
}
}
}
]
8 changes: 5 additions & 3 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import CustomIconsAlert from "./sections/CustomIconsAlert/CustomIconsAlert";
import ContactForm from "./ContactForm/ContactForm";
import AlertWithImage from "./sections/AlertWithImage/AlertWithImage";
import CustomProductDetails from "./sections/CustomProductDetails/CustomProductDetails";
import CustomIconsAlert from "./sections/CustomIconsAlert/CustomIconsAlert";
import CustomNewsletter from "./sections/CustomNewsletter/CustomNewsletter";
import ContactForm from "./ContactForm/ContactForm";
import CustomProductDetails from "./sections/CustomProductDetails/CustomProductDetails";
import CustomProductSEOSection from "./sections/CustomProductSEO/CustomProductSEO";

const sections = {
CustomIconsAlert,
AlertWithImage,
ProductDetails: CustomProductDetails,
ContactForm,
CustomNewsletter,
CustomProductSEOSection,
};

export default sections;
25 changes: 25 additions & 0 deletions src/components/sections/CustomProductSEO/CustomProductSEO.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { usePDP } from "@faststore/core";
import { ProductJsonLd } from "next-seo";

export function CustomProductSEOSection() {
// FastStore exposes the data that comes from FastStore API along with FastStore API Extensions inside a provider. Use the usePDP hook to access data from a Product Detail Page (PDP). Refer to: https://developers.vtex.com/docs/guides/faststore/api-extensions-consuming-api-extensions
const context = usePDP();
const product = context?.data?.product;
const meta = product?.seo;

return (
<ProductJsonLd
productName={meta.title}
description={meta.description}
brand={product.brand.name}
sku="TESTSKU"
gtin={product.gtin}
images={product.image.map(
(img: { url: string; alternateName: string }) => img.url
)}
releaseDate={product.releaseDate}
/>
);
}

export default CustomProductSEOSection;