Skip to content

Commit

Permalink
GH-54 fix: remove references to "reviews" field in blogPost documents,
Browse files Browse the repository at this point in the history
Also disable server-side recipe structured data
  • Loading branch information
“Marco committed Jul 31, 2020
1 parent 93084b7 commit bd031f7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pages-tests/blogpost.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const blogPostData = testRecipeData as SanityBlogPostFull;

jest.mock('../components/blog-post/sanity-browser-client', () => {
return {
getPostReviews: (): { reviews: number[] } => {
return { reviews: [1, 5, 3] };
getPostReviews: (): { rating: number }[] => {
return [{ rating: 1 }, { rating: 5 }, { rating: 3 }];
},
};
});
Expand Down
6 changes: 2 additions & 4 deletions pages-tests/data/test-category.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
"categoryId": "test-category",
"postId": "blog-post-slug"
}
},
"reviews": []
}
}
],
"featuredBlogPosts": [
Expand Down Expand Up @@ -214,8 +213,7 @@
"categoryId": "test-category",
"postId": "blog-post-slug"
}
},
"reviews": []
}
}
],
"name": "Test category",
Expand Down
1 change: 0 additions & 1 deletion sanity/blogPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const allBlogPostsQuery = /* groq */ `*[_type == "${blogPostType}"] {
"seoTitle": ${pageBlogPostQuery}[0].seoTitle,
"seoDescription": ${pageBlogPostQuery}[0].seoDescription,
"seoImage": seoImage.asset->url,
"reviews": coalesce(reviews[], []),
}`;

function replaceBlogPostContent(blogPostItem, content) {
Expand Down
1 change: 0 additions & 1 deletion sanity/projections.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const blogPostPreviewProjection = /* groq */ `{
"tags":tags[]->${tagPreviewProjection},
datePublished,
previewImage->${accessibleImageProjection},
"reviews": coalesce(reviews[], []),
}`;

module.exports = {
Expand Down
22 changes: 11 additions & 11 deletions scripts/structured-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,17 @@ export function generateRecipeStructuredData({
// Missing: video
};

if (blogPostData.reviews.length) {
toReturn.aggregateRating = {
'@type': 'AggregateRating',
reviewCount: blogPostData.reviews.length,
ratingValue:
Math.round(
(100 * blogPostData.reviews.reduce((acc, curr) => acc + curr, 0)) /
blogPostData.reviews.length
) / 100,
};
}
// if (blogPostData.reviews.length) {
// toReturn.aggregateRating = {
// '@type': 'AggregateRating',
// reviewCount: blogPostData.reviews.length,
// ratingValue:
// Math.round(
// (100 * blogPostData.reviews.reduce((acc, curr) => acc + curr, 0)) /
// blogPostData.reviews.length
// ) / 100,
// };
// }

return toReturn;
}
Expand Down
1 change: 0 additions & 1 deletion typings/sanity-blog-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type SanityBlogPostBase = {
category: SanityCategoryPreview;
tags: SanityTag[];
datePublished: string;
reviews: number[];
};

export type SanityBlogPostPreview = SanityBlogPostBase & {
Expand Down

0 comments on commit bd031f7

Please sign in to comment.