Skip to content

Commit

Permalink
Include last-modified in metadata (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
herzog31 authored Nov 26, 2024
1 parent d516736 commit 6cc6c93
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions blocks/product-details/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ function setMetaTags(product) {
createMetaTag('description', product.metaDescription, 'name');
createMetaTag('keywords', product.metaKeyword, 'name');

createMetaTag('og:type', 'og:product', 'property');
createMetaTag('og:type', 'product', 'property');
createMetaTag('og:description', product.shortDescription, 'property');
createMetaTag('og:title', product.metaTitle || product.name, 'property');
createMetaTag('og:url', window.location.href, 'property');
const mainImage = product?.images?.filter((image) => image.roles.includes('thumbnail'))[0];
const metaImage = mainImage?.url || product?.images[0]?.url;
createMetaTag('og:image', metaImage, 'property');
createMetaTag('og:image:secure_url', metaImage, 'property');
createMetaTag('og:product:price:amount', price.value, 'property');
createMetaTag('og:product:price:currency', price.currency, 'property');
createMetaTag('product:price:amount', price.value, 'property');
createMetaTag('product:price:currency', price.currency, 'property');
}

export default async function decorate(block) {
Expand Down
6 changes: 5 additions & 1 deletion tools/pdp-metadata/pdp-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const getProducts = async (config, pageNumber) => {
metaTitle,
description,
shortDescription,
lastModifiedAt,
} = item.productView;
const { url: imageUrl } = item.productView.images?.[0] ?? { url: '' };

Expand Down Expand Up @@ -144,6 +145,7 @@ const getProducts = async (config, pageNumber) => {
meta_description: finalDescription,
'og:image': baseImageUrl,
'og:image:secure_url': baseImageUrl,
'last-modified': lastModifiedAt,
},
};
}));
Expand Down Expand Up @@ -210,6 +212,7 @@ async function addVariantsToProducts(products, config) {
'og:url',
'og:image',
'og:image:secure_url',
'last-modified',
'json-ld',
],
];
Expand All @@ -220,12 +223,13 @@ async function addVariantsToProducts(products, config) {
metaData.meta_title, // title
metaData.meta_description, // description
metaData.meta_keyword, // keywords
'og:product', // og:type
'product', // og:type
metaData.meta_title, // og:title
metaData.meta_description, // og:description
`${basePath}${metaData.path}`, // og:url
metaData['og:image'], // og:image
metaData['og:image:secure_url'], // og:image:secure_url
metaData['last-modified'], // last-modified header
getJsonLd(metaData, variants), // json-ld
],
);
Expand Down
1 change: 1 addition & 0 deletions tools/pdp-metadata/queries/products.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default `query productSearch($currentPage: Int = 1) {
metaDescription
metaKeyword
metaTitle
lastModifiedAt
inStock
images(roles: ["image"]) {
url
Expand Down

0 comments on commit 6cc6c93

Please sign in to comment.