-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add validators for LocalBusiness, Article, Event, FAQPage, HowT… #58
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
base: main
Are you sure you want to change the base?
Conversation
…o, and WebSite Add validators for commonly-used schema.org types that Google Rich Results supports: - LocalBusiness: requires name, address; recommends geo, image, telephone, etc. - Article (+ BlogPosting, NewsArticle): requires headline; recommends author, dates, etc. - Event: requires name, startDate, location/eventAttendanceMode - FAQPage: requires mainEntity (with Question/Answer validators) - HowTo: requires name, step; recommends tools, supplies, etc. - WebSite: requires name, url; recommends potentialAction Also includes: - Question and Answer validators for FAQPage support - Test fixtures in gallery/ and src/types/__tests__/ - Minor fix to Product.test.js to filter for errors only Closes adobe#56
…o, and WebSite Add validators for commonly-used schema.org types that Google Rich Results supports: - LocalBusiness: requires name, address; recommends geo, image, telephone, etc. - Article (+ BlogPosting, NewsArticle): requires headline; recommends author, dates, etc. - Event: requires name, startDate, location/eventAttendanceMode - FAQPage: requires mainEntity (with Question/Answer validators) - HowTo: requires name, step; recommends tools, supplies, etc. - WebSite: requires name, url; recommends potentialAction Also includes: - Question and Answer validators for FAQPage support - Test fixtures in gallery/ and src/types/__tests__/ - Minor fix to Product.test.js to filter for errors only Closes adobe#56
…/structured-data-validator into feature/new-validators
|
Hi, would any of the maintainers let me know if this would be considered or if there's anything I missed? |
|
|
||
| this.recommended('aggregateRating', 'object'), | ||
| this.recommended('geo', 'object'), | ||
| this.recommended('image', 'url'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
image can also be an object https://developers.google.com/search/docs/appearance/structured-data/local-business#carousel
| : [typeEntry['rdfs:subClassOf']]; | ||
|
|
||
| return parents.map((p) => { | ||
| const id = p['@id'] || p; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ever possible for p to be null?
| ].map((c) => c.bind(this)); | ||
| } | ||
|
|
||
| locationOrAttendanceMode(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably also check for location.name https://developers.google.com/search/docs/appearance/structured-data/event#structured-data-type-definitions
herzog31
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
I raised a few inconsistencies compared to the Google Rich Results documentation available at https://developers.google.com/search/docs/appearance/structured-data.
|
|
||
| return parents.map((p) => { | ||
| const id = p['@id'] || p; | ||
| return id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| */ | ||
| import BaseValidator from './base.js'; | ||
|
|
||
| export default class WebSiteValidator extends BaseValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library bases the implementation for attribute constraints on documentation provided by Google at https://developers.google.com/search/docs/appearance/structured-data/search-gallery as the schema.org specification does not mandate required fields.
As the WebSite type is not part of the Google Rich Results gallery, I recommend to not add this handler. A handler like this can be added to the validator as part of your project.
| */ | ||
| import BaseValidator from './base.js'; | ||
|
|
||
| export default class HowToValidator extends BaseValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment about the WebSite type applies here as well.
While HowTo is not supported, HowToStep is and already available in the project.
|
|
||
| export default class FAQPageValidator extends BaseValidator { | ||
| getConditions() { | ||
| return [this.required('mainEntity', 'arrayOrObject')].map((c) => c.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please additionally check that mainEntity contains at least one item.
https://developers.google.com/search/docs/appearance/structured-data/faqpage#faq-page
| this.recommended('eventAttendanceMode'), | ||
| this.recommended('eventStatus'), | ||
| this.recommended('image', 'arrayOrObject'), | ||
| this.recommended('offers', 'arrayOrObject'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adjust the Offer type to selectively add recommended attributes availability, price, priceCurrency, validFrom and url for when used within an Event type. The Offer type already contains this logic for use with Product as a reference.
| this.recommended('endDate', 'date'), | ||
| this.recommended('eventAttendanceMode'), | ||
| this.recommended('eventStatus'), | ||
| this.recommended('image', 'arrayOrObject'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be an URL as string.
| export default class ArticleValidator extends BaseValidator { | ||
| getConditions() { | ||
| return [ | ||
| this.required('headline'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the documentation, headline is only a recommended property.
https://developers.google.com/search/docs/appearance/structured-data/article
| this.recommended('author', 'arrayOrObject'), | ||
| this.recommended('dateModified', 'date'), | ||
| this.recommended('datePublished', 'date'), | ||
| this.recommended('image', 'arrayOrObject'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be an URL as string as well.
| this.recommended('dateModified', 'date'), | ||
| this.recommended('datePublished', 'date'), | ||
| this.recommended('image', 'arrayOrObject'), | ||
| this.recommended('publisher', 'object'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This attribute is optional according to the documentation. Basically recommending that the publisher of an article should not be listed as part of the author attribute, but using publisher.
https://developers.google.com/search/docs/appearance/structured-data/article
Summary
Add validators for commonly-used schema.org types that Google Rich Results supports:
name,address; recommendsgeo,image,telephone,url, etc.headline; recommendsauthor,datePublished,image, etc.name,startDate,location(or onlineeventAttendanceMode)mainEntity(with nested Question/Answer validators)mainEntity,mainEntity.answerCount(Google's Q&A Page requirement)name,acceptedAnswerORsuggestedAnswer; recommendstexttextname,step; recommendstools,supply,totalTime, etc.name,url; recommendspotentialActionAutomatic Subtype Inheritance
This PR also introduces automatic validator inheritance for schema.org subtypes. When validating a type that doesn't have its own registered validator, the library automatically falls back to parent type validators by traversing the
rdfs:subClassOfhierarchy.Examples:
Restaurant,Store,Hotel,DentistLocalBusinessNewsArticle,BlogPosting,TechArticleArticleMusicEvent,SportsEvent,FestivalEventThis enables validation of 100+ schema types without needing individual validator files for each.
How it works:
schemaOrgJsonChanges
LocalBusiness.js,Article.js,Event.js,FAQPage.js,HowTo.js,WebSite.js,Question.js,Answer.js)#getParentTypes()and#getHandlersForType()methods tovalidator.jsfor inheritancegallery/andsrc/types/__tests__/Product.test.jsto filter for errors onlyTesting
Closes #56