Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(recipe-schema): add support for recipe schema in structured data #561

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 10 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quintype/seo",
"version": "1.47.0",
"version": "1.48.0-recipe-schema.0",
"description": "SEO Modules for Quintype",
"main": "dist/index.cjs.js",
"repository": "https://github.com/quintype/quintype-node-seo",
Expand Down
27 changes: 27 additions & 0 deletions src/structured-data/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,30 @@ export function generateAuthorPageSchema(publisherConfig, data, url) {
},
};
}

export function generateRecipePageSchema(story) {
const { headline, url, "author-name": authorName, description, metadata } = story;
const servings = get(metadata, ["servings"], "");
const ingredients = get(metadata, ["ingredients"], "");
const recipeAttributes = get(metadata, ["story-attributes"], "");
const cuisine = get(recipeAttributes, ["cuisine", "0"], "");
const preperationtime = get(recipeAttributes, ["preparationtime", "0"], "");
const cookingtime = get(recipeAttributes, ["cookingtime", "0"], "");

return {
"@context": "https://schema.org/",
"@type": "Recipe",
name: headline,
url: url,
author: {
"@type": "Person",
name: authorName,
},
description: description,
recipeIngredient: ingredients,
prepTime: preperationtime,
cookTime: cookingtime,
recipeCuisine: cuisine,
recipeYield: servings,
};
}
36 changes: 35 additions & 1 deletion src/structured-data/structured-data-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getQueryParams, stripMillisecondsFromTime } from "../utils";
import { generateTagsForEntity } from "./entity";
import {
generateAuthorPageSchema,
generateRecipePageSchema,
getSchemaBlogPosting,
getSchemaBreadcrumbList,
getSchemaContext,
Expand Down Expand Up @@ -472,7 +473,6 @@ export function StructuredDataTags({ structuredData = {} }, config, pageType, re
const isStructuredDataEmpty = Object.keys(structuredData).length === 0;
const enableBreadcrumbList = get(structuredData, ["enableBreadcrumbList"], true);
const structuredDataTags = get(structuredData, ["structuredDataTags"], []);

let articleData = {};

if (!isStructuredDataEmpty) {
Expand Down Expand Up @@ -501,11 +501,45 @@ export function StructuredDataTags({ structuredData = {} }, config, pageType, re
if (!isStructuredDataEmpty && pageType === "story-page") {
const newsArticleTags = generateNewsArticleTags();
newsArticleTags ? tags.push(storyTags(), newsArticleTags) : tags.push(storyTags());
if (story["story-template"] === "recipe") {
const recipeTags = generateRecipePageSchema(story);
recipeTags.image = Object.assign(
{
"@type": "ImageObject",
},
generateArticleImageData(story["hero-image-s3-key"], publisherConfig)
);
recipeTags.video = Object.assign(
{
"@type": "VideoObject",
},
generateVideoArticleData(structuredData, story, publisherConfig, timezone)
);

tags.push(ldJson("Recipe", recipeTags));
}
}

if (!isStructuredDataEmpty && pageType === "story-page-amp") {
const newsArticleTags = generateNewsArticleTags();
newsArticleTags ? tags.push(storyTags(), newsArticleTags) : tags.push(storyTags());
if (story["story-template"] === "recipe") {
const recipeTags = generateRecipePageSchema(story);
recipeTags.image = Object.assign(
{
"@type": "ImageObject",
},
generateArticleImageData(story["hero-image-s3-key"], publisherConfig)
);
recipeTags.video = Object.assign(
{
"@type": "VideoObject",
},
generateVideoArticleData(structuredData, story, publisherConfig, timezone)
);

tags.push(ldJson("Recipe", recipeTags));
}
}

if (!isStructuredDataEmpty && structuredData.header) {
Expand Down