Skip to content

Conversation

@HyperDanisH
Copy link
Contributor

Introduces #276

ATM only extracts micordata from schema.org and no JSON-LD or RDFa.

Did I write the tests as of now?
No

@HyperDanisH HyperDanisH changed the title Feat/extract microdata Nov 6, 2025
@HyperDanisH HyperDanisH changed the title Feat: extract microdata Nov 6, 2025
Copy link
Member

@barjin barjin left a 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!

Comment on lines +16 to +18
const extractValue = (elem: any) => {
return $(elem).attr('content') || $(elem).text()?.trim() || $(elem).attr('src') || $(elem).attr('href') || null;
};
Copy link
Member

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') };
Copy link
Member

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');
Copy link
Member

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):

Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants