-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: extract microdata #3233
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: master
Are you sure you want to change the base?
feat: extract microdata #3233
Conversation
barjin
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.
Hello and thank you for your contribution!
See my comments regarding the implementation - feel free to get inspired by other projects, e.g. extruct.
Also, please add tests for this feature.
Cheers!
| const extractValue = (elem: any) => { | ||
| return $(elem).attr('content') || $(elem).text()?.trim() || $(elem).attr('src') || $(elem).attr('href') || null; | ||
| }; |
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 is not entirely correct as per the microdata specification. See point 5.2.4 Values - the type of the value extracted is based on the element type.
| }; | ||
|
|
||
| const extractItem = (elem: any): any => { | ||
| const item: any = { _type: $(elem).attr('itemtype') }; |
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.
As per the spec, itemtype is a unordered set of unique space-separated tokens, we should split this by ASCII whitespace.
| return $(this).parentsUntil(elem, '[itemscope]').length === 0; | ||
| }) | ||
| .each(function () { | ||
| const propName = $(this).attr('itemprop'); |
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.
itemprop is also an unordered set of unique space-separated tokens, this needs to be split too - see example (link):
Introduces #276
ATM only extracts micordata from schema.org and no JSON-LD or RDFa.
Did I write the tests as of now?
No