Skip to content

Improve AMP plugin compatibility#3621

Merged
swissspidy merged 25 commits intomainfrom
add/amp-plugin-compatibility
Aug 7, 2020
Merged

Improve AMP plugin compatibility#3621
swissspidy merged 25 commits intomainfrom
add/amp-plugin-compatibility

Conversation

@westonruter
Copy link
Copy Markdown
Contributor

@westonruter westonruter commented Aug 3, 2020

Summary

This PR improves compatibility with the AMP plugin:

  • Override the template mode to be Standard (AMP-First) when requesting a singular web-story or the Validated URL screen is being viewed for a web-story.
  • Inject web-stories into the list of supported post types when requesting a web story. When not requesting a web story, exclude the web-stories post type from the list of supportable post types. This prevents the post type from appearing among the list of post types which can be enabled/disabled on the AMP Settings screen (as of v2.0).
  • Adds workaround for standalone="standalone" being flagged as a validation error. This was resulting in the body element being emptied out when serving an amp-story. The AMP plugin needs to be updated to allow the attribute value to replicate the attribute name for such boolean attributes. See Boolean attributes erroneously flagged as validation errors when name copied as value ampproject/amp-wp#5156.
  • Prevents script handle collision for amp-story-player AMP component by renaming the handle used for the AMP Story block to be standalone-amp-story-player. This is only enqueued if not on an AMP page since otherwise it will be added automatically. This fixes a 404 error I saw in the editor: image

Relevant Technical Choices

The changes in this PR are in lieu of there being a more centralized way of conditionally switching the template mode given the request. When/if that happens, much of the code in this PR can be revised. The closest issue for that presently is ampproject/amp-wp#2817.

The logic in Story_Post_Type::get_request_post_type() is admittedly hacky!

User-facing changes

“Stories” will no longer appear in the list of post types that can be enabled for AMP.

Testing Instructions

  1. Activate the latest AMP plugin in the develop branch (2.0-beta2)
  2. Create a story.
  3. Upon saving the story, you should be able to see the story appear in the Validated URLs screen.
  4. No validation errors should be reported.
  5. Viewing the story on the frontend should show that the AMP Optimizer is running.

Fixes #3257
Fixes #1276

@github-actions

This comment has been minimized.

@spacedmonkey

This comment has been minimized.

@westonruter

This comment has been minimized.

<body>
<amp-story
standalone="standalone"
standalone=""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@swissspidy swissspidy added the AMP Output Issues related to AMP output and validation label Aug 5, 2020
@swissspidy swissspidy marked this pull request as ready for review August 6, 2020 13:32
@spacedmonkey
Copy link
Copy Markdown
Contributor

One nitpic, but otherwise, we are looking good.

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 6, 2020

Codecov Report

Merging #3621 into main will decrease coverage by 0.20%.
The diff coverage is 40.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3621      +/-   ##
==========================================
- Coverage   83.72%   83.51%   -0.21%     
==========================================
  Files         775      775              
  Lines       13380    13428      +48     
==========================================
+ Hits        11203    11215      +12     
- Misses       2177     2213      +36     
Flag Coverage Δ
#karmatests 67.39% <ø> (ø)
#unittests 66.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
assets/src/edit-story/output/story.js 100.00% <ø> (ø)
includes/Story_Post_Type.php 77.36% <28.00%> (-17.84%) ⬇️
includes/Embed_Block.php 98.24% <100.00%> (+0.03%) ⬆️
includes/Plugin.php 100.00% <100.00%> (ø)

@swissspidy swissspidy merged commit b1ad429 into main Aug 7, 2020
@swissspidy swissspidy deleted the add/amp-plugin-compatibility branch August 7, 2020 09:04
@swissspidy swissspidy added Group: Integration Integration with other platforms and plugins Group: WordPress Changes related to WordPress or Gutenberg integration Type: Enhancement New feature or improvement of an existing feature labels Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AMP Output Issues related to AMP output and validation Group: Integration Integration with other platforms and plugins Group: WordPress Changes related to WordPress or Gutenberg integration Type: Enhancement New feature or improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AMP: Mark story post type as not supported Leverage AMP Optimizer if possible

3 participants