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

metaformats: should we distinguish the parsed output item more explicitly? #2

Open
snarfed opened this issue Nov 29, 2023 · 5 comments

Comments

@snarfed
Copy link
Member

snarfed commented Nov 29, 2023

Right now, if https://microformats.org/wiki/metaformats finds eligible metaformats, it generates an h-entry and appends it to the returned items. There's no way to distinguish this item from real mf2 items, though, which is unfortunate. As an implementor, I could use one! Especially for interpreting home page metaformats as an h-card, eg #3, but also for non-homepage pages. Should we include a new property? New type? (I assume not.) Something else? cc @tantek

@sknebel
Copy link
Member

sknebel commented Nov 30, 2023

given that they as far as I see don't really participate in the nesting of objects (i.e. a metaformats-parsed object is not going to be a child or property-value of an mf2-parsed object, nor vice-versa) they could be sorted in a separate list, e.g. metaformats-items. Alternatively, they could have an extra flag on the same level as type

@aciccarello
Copy link

aciccarello commented Dec 2, 2023

I wondered about this too in microformats/microformats-parser#229.

Should there be a property identifying the mf as being parsed from metaformats in case someone wants to cleanup messy meta tag content

I'd prefer to not put them in a separate list so a consumer of the parsed output doesn't need to do anything extra. So far I haven't personally needed to know if if an output if from metaformats, but I could see a property identifying it being useful.

@tantek tantek transferred this issue from microformats/microformats2-parsing Dec 2, 2023
@angelogladding
Copy link

angelogladding commented Dec 4, 2023

I think adding a new property meta-item keeps things clean and explicit. In Python:

if parsed["meta-item"]:

vs. eg.

if parsed["items"] and parsed["items"][-1].get("source") == "metaformats":

I believe mf2py can toggle metaformats parsing on by default immediately if we can keep items as is and use meta-item experimentally -- see microformats/mf2py#213 (comment)

@snarfed
Copy link
Member Author

snarfed commented Dec 4, 2023

As @aciccarello mentioned, the problem is that a separate list forces all consumers to have to be explicit. One of the benefits of the current metaformats spec is that it lets current mf2 consuming code (choose to) benefit from metaformats automatically, without any changes. New top-level field preserves that, separate list doesn't.

@angelogladding
Copy link

I do like automatic fallback for entries. Now I better see what you guys are talking about.

mf2util will need to be updated to look for the new top-level field and ignore it when interpreting a feed but everything else in that library should just work (again by simply operating on the first item).

>>> mf2json = mf2py.parse(url="https://zeldman.com", metaformats=True)
>>> homepage_feed = mf2util.interpret_feed(mf2json, "https://zeldman.com")
>>> homepage_feed["entries"][-1]["name"]
'Zeldman on Web and Interaction Design'

The fix will look something like this which is perfectly fine:

if feed["entries"][-1].get("source") == "metaformats":
    feed["entries"].pop()

And you'll never actually need to look up the meta item so I was optimizing for a non-existent case with:

if parsed["meta-item"]:

So keeping it in items and adding a top-level field does make good sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants