-
Notifications
You must be signed in to change notification settings - Fork 845
Improve AMP support for Photon #12821
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
Conversation
|
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: August 6, 2019. |
|
That would be a nice improvement! Do you think you could add some tests in |
|
@jeherve Thanks for the review. I believe I've addressed your feedback in what I just pushed. |
…s param and AMP support
15771bb to
cf053c2
Compare
cf053c2 to
b7875e1
Compare
|
Caution: This PR has changes that must be merged to WordPress.com |
jeherve
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well for me. This should be good to merge once we fix the Unit Test breakage caused by https://core.trac.wordpress.org/changeset/45687/
* Add initial changelog / testing list changes for 7.6 * Update stable tag to 7.5.3 * changelog: add #12957 * Changelog: add #12932 * Changelog: add #12867 * Changelog: add #12823 * changelog: add #12969 * changelog: add #13012 * changelog: add #12974 * Changelog: add #13059 * Changelog: add #13079 * Changelog: add #12924 * changelog: add #12954 * Changelog: add #12959 * Changelog: add #12977 * Changelog: add #12830 * Changelog: add #12926 * Changelog: add #12958 * Changelog: add #12999 * Changelog: add #13077 * Changelog: add #13083 * Changelog: add #13087 * Changelog: add #13110 * Changelog: add #13116 * Changelog: add #13117 * Changelog: add #12821 * Changelog: add #13120 * changelog: add #13139 * Changelog: add #13143 * Changelog: add #13147 * Testing list: add section about sync
* Add initial changelog / testing list changes for 7.6 * Update stable tag to 7.5.3 * changelog: add #12957 * Changelog: add #12932 * Changelog: add #12867 * Changelog: add #12823 * changelog: add #12969 * changelog: add #13012 * changelog: add #12974 * Changelog: add #13059 * Changelog: add #13079 * Changelog: add #12924 * changelog: add #12954 * Changelog: add #12959 * Changelog: add #12977 * Changelog: add #12830 * Changelog: add #12926 * Changelog: add #12958 * Changelog: add #12999 * Changelog: add #13077 * Changelog: add #13083 * Changelog: add #13087 * Changelog: add #13110 * Changelog: add #13116 * Changelog: add #13117 * Changelog: add #12821 * Changelog: add #13120 * changelog: add #13139 * Changelog: add #13143 * Changelog: add #13147 * Testing list: add section about sync
In testing a site using the AMP plugin in Standard/Transitional mode and in AMP Stories, I noticed a couple issues where Photon could better support AMP.
Proposed Changes
Support photonification of
amp-imglikeimgI noticed that an
<amp-img>put directly intopost_contentdoes not get processed by Photon. This isn't particularly surprising since it would be looking for<img>not<amp-img>(or<amp-anim>). To fix this, the regex in\Jetpack_Photon::parse_images_from_html()just needs to be updated like so:Given
post_content(e.g. a Custom HTML block) containing:Before, with no change because Photon didn't see it:
After, with image being replaced with Photon CDN as expected:
Remove unnecessary
data-recalc-dims=1Additionally I noticed that Photon was adding the
data-recalc-dims=1attribute to images, but this is irrelevant in AMP since thedevicepxJS is not loaded. So I'm not omitting this in AMP.Prevent constraining to
content_widthin StoriesOriginally reported in ampproject/amp-wp#2595.
The AMP Stories experience (
amp_storyplugin) intends to constrain the height of images to be 1440px, given the vertical resolution of mobile devices. This turned out to fail to work as expected when Photon supplied, since it constrains based on the theme'scontent_width.For example, when setting the background image for a story page when a theme has a
640content width, the generated markup with Photon is:The
w=640is the problem here. What is actually desired ish=1440.In order to accomplish this, this PR adds a
jetpack_photon_post_image_argsfilter which runs when on a singularamp_storypost to override the args to be appropriate for the format.In order to achieve this, additional context params needed to be passed to
jetpack_photon_post_image_argsin order to basically re-factor the following logic using a fixed height of 1440px instead of thecontent_width:jetpack/class.photon.php
Lines 422 to 458 in 596bdd6
When this change is paired with support for photonizing
<amp-img>inpost_content(which theamp_storypost type does), the result is a user can successfully upload new large images and have them appear with the expected 1440px height as opposed to the full size or acontent_width-constrained size.Testing instructions:
h=1440.Proposed changelog entry for your changes:
<amp-img>and<amp-anim>inpost_contentand ensuring proper height-constrained images are used in AMP Stories. Adds additional context tojetpack_photon_post_image_argsfilter, and remove AMP-unnecessarydata-recalc-dimsattribute.