representative-h-card-parsing: Difference between revisions

From Microformats Wiki
Jump to navigation Jump to search
(initial updated microformats2 version of representative h-card algorithm)
 
(→‎Implementations: added rockorager/representative-h-card)
 
(3 intermediate revisions by 2 users not shown)
Line 9: Line 9:
* If the page contains an h-card with '''uid''' and '''url''' properties both matching the page URL, the first such h-card is the representative h-card
* If the page contains an h-card with '''uid''' and '''url''' properties both matching the page URL, the first such h-card is the representative h-card
* If no representative h-card was found, if the page contains an h-card with a '''url''' property value which also has a <code>rel=me</code> relation (i.e. matches a URL in parse_results.rels.me), the first such h-card is the representative h-card
* If no representative h-card was found, if the page contains an h-card with a '''url''' property value which also has a <code>rel=me</code> relation (i.e. matches a URL in parse_results.rels.me), the first such h-card is the representative h-card
* If no representative h-card was found, if the page contains '''one single''' h-card with a '''url''' property matching the page URL, that h-card is the representative h-card
* If no representative h-card was found, if the page contains '''one single''' h-card, and the h-card has a '''url''' property matching the page URL, that h-card is the representative h-card
* If no representative h-card was found, the page has no representative h-card
* If no representative h-card was found, the page has no representative h-card


Line 21: Line 21:
Open source implementations of the representative h-card algorithm.
Open source implementations of the representative h-card algorithm.


* '''PHP''' [https://github.com/barnabywalters/php-mf-cleaner barnabywalters/mf-cleaner] package implements representative h-card parsing in [https://github.com/barnabywalters/php-mf-cleaner/blob/master/src/BarnabyWalters/Mf2/Functions.php#L211 getRepresentativeHCard()] function
** Example usage: <code>$hcard = BarnabyWalters\Mf2\getRepresentativeHCard($mfs, $url);</code>
* '''PHP''' [https://github.com/indieweb/representative-h-card-php indieweb/representative-h-card-php]
* '''node.js''' [https://github.com/rockorager/representative-h-card rockorager/representative-h-card]
* Add yours here!
* Add yours here!
* …
* …

Latest revision as of 12:45, 22 June 2021

Assuming you already have access to a microformats2 parser, the algorithm defined here allows you to determine the representative h-card for a given page.

This algorithm is the microformats2 update to representative-hcard-parsing.

Algorithm

After parsing the page:

  • If the page contains an h-card with uid and url properties both matching the page URL, the first such h-card is the representative h-card
  • If no representative h-card was found, if the page contains an h-card with a url property value which also has a rel=me relation (i.e. matches a URL in parse_results.rels.me), the first such h-card is the representative h-card
  • If no representative h-card was found, if the page contains one single h-card, and the h-card has a url property matching the page URL, that h-card is the representative h-card
  • If no representative h-card was found, the page has no representative h-card

Matching URLs

URLs are to be matched as per the parsing algorithm defined in https://url.spec.whatwg.org:

  • Parse the URLs
  • If every component matches, the URLs match

Implementations

Open source implementations of the representative h-card algorithm.

Back compat

All backcompat for representative h-card parsing should already be handled by the h-card backcompat rules, implemented by a conforming parser.

See Also