-
Notifications
You must be signed in to change notification settings - Fork 6
Should u-* parsing special case img srcset? #7
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
Comments
yes! use case: snarfed/bridgy#592 (comment) . a few people want bridgy publish to support cc @jonnybarnes and @petermolnar for example posts. |
Here’s an initial post that uses |
It appears php-mf2 leaves the |
#2 proposes already to expand images into an object with Looking at the examples linked, from my understanding the based on example HTML from the wiki: <img
class="u-photo"
src="http://example.com/img-360x540.jpg"
alt="img"
srcset="img-240x360.jpg 360w, img-360x540.jpg 540w, img-653x980.jpg 980w, img-853x1280.jpg 1280w"
sizes="(min-width: 960px) 50vw, 100vw"
/> The parser could just pass on the content of …
"photo": {
"value": "http://example.com/img-360x540.jpg",
"alt": "img",
"srcset": "img-240x360.jpg 360w, img-360x540.jpg 540w, img-653x980.jpg 980w, img-853x1280.jpg 1280w"
} , or transform it into some kind of more detailed structure (suggestions at what that'd ideally look like for a consumer? Seems like @snarfed would only want something where the full list of images is easy to get from, since the parameters don't actually matter for bridgy?) |
@grantcodes I believe you were interested in this too, any feedback? |
@sknebel yeah, I didn't comment as my use case is very different, and probably not a microformats issue. I am trying to generate html from mf2 json and very rarely want to show a full resolution image. Your proposal may work for that but honestly I have not thought about it enough to be sure. |
friendly nudge! this came up in chat just now: https://chat.indieweb.org/dev/2020-04-03#t1585936229416600 |
Would suggest sourceset might be best parsed out.
turning into
|
Building on @dshanske's comment with some uses cases pulled from MDN's Responsive Images tutorial. URLs are resolved based on a hypothetical source page/base URL at Simple
|
Don't look now, but there's also the Same values permitted: a comma-separated list of image candidate strings. |
The conclusion at the end of today's Microformats online session was that someone should try implementing this behind an experimental flag to move forward with this idea. |
This commit adds a new ImageElementParser class that encompasses existing custom `img[alt]` handling with the addition of `srcset` parsing based on the rules I proposed in microformats/microformats2-parsing#7. See my comment here: microformats/microformats2-parsing#7 (comment)
I've just published MicroMicro v3.1.0 (RubyGems, GitHub release notes) which implements The implementation matches the examples in my comment above along with feedback in the |
Following up on @tantek's request for implementation details, here's where we collectively landed on parsing an For reference, relevant classes and methods from MicroMicro's implementation: Based on the existing specification, feedback in IRC/Slack, Mozilla's HTMLImageElement.srcset documentation, and the WHATWG HTML specification's
☝🏻 Feedback and refinement would be welcome. That's a long-winded spec-y way of saying… Take a
…and return a hash like: {
"480w": "https://jgarber.example/image-480.jpg",
"1x": "https://jgarber.example/image.jpg",
"640w": "https://jgarber.example/image-640.jpg",
"2x": "https://jgarber.example/image-2x.jpg"
} For a real-world example, see this photo on my website and the results parsed by micromicro.cc (which uses v3.1.0 of MicroMicro). The relevant snippet from the microformats2 JSON: "photo": [
{
"value": "https://assets.sixtwothree.org/uploads/photos/256/5394F7C7-97B5-465D-AF6D-B9CC85F98212_medium.jpg",
"srcset": {
"500w": "https://assets.sixtwothree.org/uploads/photos/256/5394F7C7-97B5-465D-AF6D-B9CC85F98212_small.jpg",
"750w": "https://assets.sixtwothree.org/uploads/photos/256/5394F7C7-97B5-465D-AF6D-B9CC85F98212_medium.jpg",
"1000w": "https://assets.sixtwothree.org/uploads/photos/256/5394F7C7-97B5-465D-AF6D-B9CC85F98212_large.jpg"
},
"alt": ""
}
] |
Also, the MicroMicro test suite includes several test files (HTML and JSON) consistent with the microformats/tests repo. Those files are available here: https://github.com/jgarber623/micromicro/tree/main/spec/support/fixtures/micromicro_test_suite |
I'm curious how/if incorrect usages of An example of how many of the images on my site are displayed. <img srcset="logo.webp, logo.jpeg" src="logo.jpeg" alt="The logo for my site" class="u-photo"> If I understand the specification documented above by @jgarber623 correctly, then I presume that the following structure would be attempted, "photo": [
{
"value": "https://my-website.com/logo.jpg",
"srcset": {
"1x": "https://my-website.com/logo.webp",
"1x": "https://my-website.com/logo.jpg"
},
"alt": "The logo for my site"
}
] I imagine the actual result would be that only the last entry in the While I understand that this is explicitly against the WHATWG specs, it is accepted behavior in both Chrome 120.0.6099.201, and Firefox 121.0. Similarly, if I got this info somewhere, surely other people did too. Is it worth it to try and consider this possibility in these specs? |
Responsive images add the 'srcset' attribute to the 'img' tag which can then provide a variety of image resolutions, both in density and pixel size.
Should u-* on an img tag pay attention to the srcset attribute, and if so, how?
Summary of srcset here https://indieweb.org/srcset
The text was updated successfully, but these errors were encountered: