Skip to content
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

feat(Experimental): add support for metaformats #229

Merged
merged 4 commits into from
Sep 4, 2023

Conversation

aciccarello
Copy link
Contributor

Fixes #224
Based on PR #226

Checklist

  • Added validaton to any changes in the parser API.
  • Added tests covering the parsing behaviour changes.
  • Linked to any relevant issues this will close.
  • Tested the output using the demo.

Changes to parsing behaviour

Adds an optional experimental option to fallback to parsing meta tags. This was inspired by the metaformats spec but with some significant changes.

  • Only parse metaformats if no microformats found (per #microformats chat discussion
  • Imply h-entry on all pages if not using a more specific og:type
  • Return featured rather than photo on og:image to avoid implying a photo post (matches opengraph-mf2 implementation)
  • More complex parsing of media tags to avoid duplicates, handle some variation in property name, and include alt text
  • Handle more fallback options like page title

The parsing approach needed to change significantly from the metaformats spec due to a few challenges with tag order. By parsing all the meta tags before creating the microformats item, we can prefer some tags over others and also handle complex tags like og:image + og:image:alt.

Example input covered by new behaviour

Source HTML of #224

Example output from new behaviour

{
  "rels": "abbreviated",
  "rel-urls": "abbreviated",
  "items": [
    {
      "properties": {
        "name": [
          "Support metaformats fallback option · Issue #224 · microformats/microformats-parser"
        ],
        "summary": [
          "Describe the feature An experimental option should be available to use meta tags as a fallback for sites that don't natively implement microformats. The Metaformats spec defines changes to the micr..."
        ],
        "featured": [
          {
            "value": "https://opengraph.githubassets.com/ca089fa87f65c6c7175965401c8881676db8e741dd58f52428850467c8578962/microformats/microformats-parser/issues/224",
            "alt": "Describe the feature An experimental option should be available to use meta tags as a fallback for sites that don't natively implement microformats. The Metaformats spec defines changes to the micr..."
          }
        ],
        "url": [
          "https://github.com/microformats/microformats-parser/issues/224"
        ],
        "publication": [
          "GitHub"
        ]
      },
      "lang": "en",
      "type": [
        "h-entry"
      ]
    }
  ]
}

Other changes

  • Added an isTag('tagName') helper for finding child nodes.

Other considerations

  • Should there be a property identifying the mf as being parsed from metaformats in case someone wants to cleanup messy meta tag content
  • Should metaformats use og:locale for the lang?
@aimee-gm
Copy link
Member

@aciccarello wow thanks for putting the time in to getting this working. Sorry I didn't see this earlier, I will get round to reviewing this shortly.

Once again, really appreciate this contribution 💯

@aimee-gm aimee-gm self-assigned this Aug 17, 2023
@aimee-gm aimee-gm self-requested a review August 17, 2023 16:13
@aimee-gm aimee-gm removed their assignment Aug 17, 2023
@aciccarello
Copy link
Contributor Author

Welcome! I'm happy to discuss any changes you think should be made.

@aimee-gm
Copy link
Member

Welcome! I'm happy to discuss any changes you think should be made.

It might be a short discussion 😄 I've had a read and can't in all honesty find anything I would insist on changing 👍

should fix test ordering issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants