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

Add AMP compatibility to Slideshow shortcode #15319

Merged
merged 11 commits into from
May 8, 2020

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Apr 6, 2020

Changes proposed in this Pull Request:

  • Adds AMP compatibility to the Slideshow shortcode
  • Reuses the Slideshow block render method
  • No change on non-AMP endpoints

Is this a new feature or does it add/remove features to an existing part of Jetpack?

  • Enhances an existing feature

Testing instructions:

  1. Activate the AMP plugin
  2. In AMP Settings, select Transitional mode
  3. Create a new post
  4. Add a Shortcode block
  5. Enter this, with ids from your environment:
[gallery ids="1691,766,760" type="slideshow"]

The attribute type="slideshow" is what triggers the code below.

  1. Preview the front-end of the AMP URL:

amp-button

  1. Expected: there's an <amp-carousel>, and it displays captions if the images have them:
    slideshow

This won't look exactly like the non-AMP endpoint, but it should have the same images.

  1. Preview the non-AMP URL:

amp-button

  1. Checkout the master branch
  2. Preview the non-AMP URL in another tab
  3. Expected: the non-AMP URL looks the same with this PR and without

Proposed changelog entry for your changes:

  • Add AMP compatibility to Slideshow shortcode

@kienstra kienstra requested a review from a team April 6, 2020 20:02
@jetpackbot
Copy link

jetpackbot commented Apr 6, 2020

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: June 2, 2020.
Scheduled code freeze: May 26, 2020

Generated by 🚫 dangerJS against 2f4df5a

@kienstra kienstra added the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Apr 6, 2020
@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it AMP [Feature] Shortcodes / Embeds labels Apr 14, 2020
@jeherve jeherve added this to the 8.5 milestone Apr 14, 2020
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello kienstra! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D42010-code before merging this PR. Thank you!
This revision will be updated with each commit to this PR

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well. Reusing the work from the Slideshow block is a smart take on this. I only have one remark about this.

tests/php/modules/shortcodes/test-class.slideshow.php Outdated Show resolved Hide resolved
@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Apr 16, 2020
…ideshow block

Also, add some test cases for the AMP output,
and enqueue the stylesheet for the Slideshow block.
This should help to ensure regressions,
to maybe prevent wp_list_pluck()
from throwing an error if there's no 'id' index.
Instead of hard-coding the image URL
in the expected markup,
dynamically replace it.
It looks like at least one failed Travis build
is from lazy-loaded images
@jeherve jeherve force-pushed the add/slideshow-shortcode-amp branch from 9f449fc to e77a7fb Compare April 20, 2020 19:24
@jeherve jeherve removed this from the 8.5 milestone Apr 24, 2020
- Apply a consistent size and make width/height variable
@MattGeri
Copy link
Contributor

@jeherve I've updated the tests here to use dynamic image sizes based on the size parameter passed through. I believe the parameter appended to the image URL should also be fixed now. Could you let me know if this fixes the failing tests?

The Travis Failure for e2e looks unrelated to this code.

@MattGeri MattGeri added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels May 7, 2020
Since the block is set to autoplay as soon as you pass an autoplay string parameter, regardless of its value, let's not pass that parameter unless necessary.
Let's not aim to validate the full slideshow markup. Instead, focus on pieces that indicate that the parameters are respected, and that the block is used.
jeherve
jeherve previously approved these changes May 7, 2020
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few changes to this PR as tests were still problematic on WordPress.com.

  • I cleaned up the array producing CSS classes for Gutenberg blocks, as it was previously outputting empty spaces for classes that were set as null
  • I reworked the autostart / autoplay conditions, as things work a bit differently between the block and the shortcode: the shortcode is set to autostart by default, while the block will not autoplay by default, but will autoplay as soon as you provide an autoplay parameter.
  • I simplified the tests. I don't think we need to check for the entirety of the slideshow markup; what's interesting in my opinion is whether the AMP markup is being used, and if the parameters are respected.

Let me know what you think about it!

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels May 7, 2020
@jeherve jeherve added this to the 8.6 milestone May 7, 2020
@jeherve
Copy link
Member

jeherve commented May 7, 2020

Hm, tests are failing on PHP 5.6 because of this:
sebastianbergmann/phpunit#2778

I'll need to work around this.

@MattGeri
Copy link
Contributor

MattGeri commented May 8, 2020

I've made a few changes to this PR as tests were still problematic on WordPress.com.

  • I cleaned up the array producing CSS classes for Gutenberg blocks, as it was previously outputting empty spaces for classes that were set as null
  • I reworked the autostart / autoplay conditions, as things work a bit differently between the block and the shortcode: the shortcode is set to autostart by default, while the block will not autoplay by default, but will autoplay as soon as you provide an autoplay parameter.
  • I simplified the tests. I don't think we need to check for the entirety of the slideshow markup; what's interesting in my opinion is whether the AMP markup is being used, and if the parameters are respected.

Let me know what you think about it!

LGTM! 👍

@MattGeri MattGeri removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label May 8, 2020
@jeherve jeherve merged commit 4aac769 into master May 8, 2020
@jeherve jeherve deleted the add/slideshow-shortcode-amp branch May 8, 2020 14:23
@jeherve
Copy link
Member

jeherve commented May 14, 2020

r207455-wpcom and r207427-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP [Feature] Shortcodes / Embeds Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants