Skip to content

Commit

Permalink
feat: links
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyreilly committed Jan 1, 2024
1 parent e3fa69d commit 96d3833
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
13 changes: 10 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34979,23 +34979,30 @@ ${responseText}`);
}
}
function processValidationResult(validationResult) {
const seeMore = `For more details see https://validator.schema.org/#url=${encodeURIComponent(validationResult.url)}`;
if (validationResult.numObjects === 0) {
return {
success: false,
resultText: `Validated ${validationResult.url} and found no structured data`,
resultText: `Validated ${validationResult.url} and found no structured data
${seeMore}
`,
};
}
if (validationResult.totalNumErrors > 0 ||
validationResult.totalNumWarnings > 0) {
return {
success: false,
resultText: `Validated ${validationResult.url} and failed with ${validationResult.totalNumErrors} errors and ${validationResult.totalNumWarnings} warnings`,
resultText: `Validated ${validationResult.url} and failed with ${validationResult.totalNumErrors} errors and ${validationResult.totalNumWarnings} warnings
${seeMore}
`,
};
}
return {
success: true,
resultText: `${validationResult.url} has structured data of these types:
${validationResult.tripleGroups.map((group) => ` - ${group.type}`).join("\n")}`,
${validationResult.tripleGroups.map((group) => ` - ${group.type}`).join("\n")}
${seeMore}
`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion dist/validate.d.ts.map

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

16 changes: 13 additions & 3 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ ${responseText}`,
export function processValidationResult(
validationResult: ValidationResult,
): ProcessedValidationResult {
const seeMore = `For more details see https://validator.schema.org/#url=${encodeURIComponent(
validationResult.url,
)}`;

if (validationResult.numObjects === 0) {
return {
success: false,
resultText: `Validated ${validationResult.url} and found no structured data`,
resultText: `Validated ${validationResult.url} and found no structured data
${seeMore}
`,
};
}

Expand All @@ -88,13 +94,17 @@ export function processValidationResult(
) {
return {
success: false,
resultText: `Validated ${validationResult.url} and failed with ${validationResult.totalNumErrors} errors and ${validationResult.totalNumWarnings} warnings`,
resultText: `Validated ${validationResult.url} and failed with ${validationResult.totalNumErrors} errors and ${validationResult.totalNumWarnings} warnings
${seeMore}
`,
};
}

return {
success: true,
resultText: `${validationResult.url} has structured data of these types:
${validationResult.tripleGroups.map((group) => ` - ${group.type}`).join("\n")}`,
${validationResult.tripleGroups.map((group) => ` - ${group.type}`).join("\n")}
${seeMore}
`,
};
}
16 changes: 12 additions & 4 deletions test/__snapshots__/validate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@

exports[`processValidationResult > given errors returns unsuccessfully 1`] = `
{
"resultText": "Validated https://deploy-preview-9669--docusaurus-2.netlify.app/blog/releases/2.4/ and failed with 1 errors and 0 warnings",
"resultText": "Validated https://deploy-preview-9669--docusaurus-2.netlify.app/blog/releases/2.4/ and failed with 1 errors and 0 warnings
For more details see https://validator.schema.org/#url=https%3A%2F%2Fdeploy-preview-9669--docusaurus-2.netlify.app%2Fblog%2Freleases%2F2.4%2F
",
"success": false,
}
`;

exports[`processValidationResult > given no structured data returns unsuccessfully 1`] = `
{
"resultText": "Validated https://news.ycombinator.com/ and found no structured data",
"resultText": "Validated https://news.ycombinator.com/ and found no structured data
For more details see https://validator.schema.org/#url=https%3A%2F%2Fnews.ycombinator.com%2F
",
"success": false,
}
`;

exports[`processValidationResult > given valid schema without errors / warnings returns successfully 1`] = `
{
"resultText": "https://deploy-preview-9669--docusaurus-2.netlify.app/blog/releases/2.4/ has structured data of these types:
- BlogPosting",
- BlogPosting
For more details see https://validator.schema.org/#url=https%3A%2F%2Fdeploy-preview-9669--docusaurus-2.netlify.app%2Fblog%2Freleases%2F2.4%2F
",
"success": true,
}
`;

exports[`processValidationResult > given warnings returns unsuccessfully 1`] = `
{
"resultText": "Validated https://deploy-preview-9669--docusaurus-2.netlify.app/blog/releases/2.4/ and failed with 0 errors and 1 warnings",
"resultText": "Validated https://deploy-preview-9669--docusaurus-2.netlify.app/blog/releases/2.4/ and failed with 0 errors and 1 warnings
For more details see https://validator.schema.org/#url=https%3A%2F%2Fdeploy-preview-9669--docusaurus-2.netlify.app%2Fblog%2Freleases%2F2.4%2F
",
"success": false,
}
`;

0 comments on commit 96d3833

Please sign in to comment.