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 sanitizer to fixup issues with core themes #1074

Merged
merged 33 commits into from
Jun 4, 2018
Merged

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Apr 14, 2018

  • Add base sanitizer framework for fixing up core themes.
  • Force SVG support in Twenty Seventeen
  • Force fixed background attachment in Twenty Seventeen
  • Ensure custom backgrounds work.
  • Ensure color schemes work.
  • Ensure header video works in AMP across core themes; see Add support for header videos #1078
  • Remove enqueued JS and replace with AMP equivalents where possible
  • Ensure header image works in AMP across core themes; see Transform CSS selectors according to sanitizer HTML element to AMP component conversions #1094
  • Twenty Seventeen: Implement setQuotesIcon().
  • Twenty Seventeen: Add support for sticky nav, that is adjustScrollClass().
  • Improve accept_validation_errors to do partial checks.
  • Twenty Seventeen+Sixteen: Try to implement belowEntryMetaClass().
  • Try to figure out a way to implement onResizeARIA() (may be impossible due to lack of trusted actions in AMP).

Initial Themes to Check

  • Twenty Seventeen
  • Twenty Sixteen
  • Twenty Fifteen

Previous core themes would be good to test as well, but they could be looked at in a separate PR.

👉 Commits pushed up to this PR (in the core-themes branch) will be automatically deployed to https://core-themes-ampconfdemo.pantheonsite.io/

AMP can be disabled on this environment for a given URL to see what it looks like normally by adding a ?amp_disabled query param, for example: https://core-themes-ampconfdemo.pantheonsite.io/?amp_disabled

Fixes #1060
Fixes #1036
Fixes #1078

@westonruter westonruter added this to the v1.0 milestone Apr 14, 2018
'twentyseventeen' => array(
'force_svg_support' => array(),
'force_fixed_background_support' => array(),
// @todo Header video probably needs special support in the plugin generally.
Copy link
Member Author

Choose a reason for hiding this comment

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

See #1078

'force_svg_support' => array(),
'force_fixed_background_support' => array(),
// @todo Header video probably needs special support in the plugin generally.
// @todo Header image is not styled properly. Needs layout=responsive and other things?
Copy link
Member Author

Choose a reason for hiding this comment

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

@westonruter
Copy link
Member Author

westonruter commented May 2, 2018

This PR adds amp theme support to _s, which could have some useful pieces, especially in regards to the nav menus: Automattic/_s#1286

@postphotos
Copy link
Contributor

Related #1094.

@postphotos
Copy link
Contributor

We still would like testing (configure AMP in Customizer) and document what's clearly a problem.

kienstra and others added 8 commits May 23, 2018 09:08
This is still WIP, free for someone to work on.
@todo: as Weston mentioned, this needs to support Vimeo.
Also, simplify the conditionals at the
top of conditionally_output_header_video().
@todo: test the case where the header video
is an <amp-video>, not an <amp-youtube>.
@DavidCramer
Copy link
Contributor

@kienstra The image and video is almost working. It's a little blocked by #1175 as it requires those styles to correctly make the images and video looks the same. Still a little more to do and still need to update the unit tests to reflect all the changes.

$atts['layout'] = 'fill';
unset( $atts['width'] );

$place_holder = AMP_HTML_Utils::build_tag( 'img', $atts );
Copy link
Member Author

Choose a reason for hiding this comment

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

img or amp-img? I think this should be creating an amp-img here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, sorry, it was, I removed it for testing something, but forgot to revert 601c005

@westonruter
Copy link
Member Author

@DavidCramer in regards to the header image then, it's going to need to be part of the sanitizer here to add a rule with selector such as amp-img img { object-fit:contain } to ensure that the header is displayed properly.

@DavidCramer
Copy link
Contributor

@westonruter yes, I expected as much. however, not all headers for all core themes work that way, so I have made it part of the twentyseventeen core sanitiser here dc9e628#diff-5d05e505f93786061c2078486784c46dR97

@DavidCramer
Copy link
Contributor

@westonruter Feel free to review the header video and image for this, I think it works well now.

@westonruter westonruter requested a review from kienstra June 4, 2018 20:39
@westonruter westonruter changed the title [WIP] Add sanitizer to fixup issues with core themes Add sanitizer to fixup issues with core themes Jun 4, 2018
@westonruter
Copy link
Member Author

I believe we've done all that can be done here. I'm really happy with the result. Let's get this to testing.

@kienstra kienstra self-assigned this Jun 4, 2018
@kienstra
Copy link
Contributor

kienstra commented Jun 4, 2018

Thanks, Reviewing Now

Hi @westonruter,
Thanks, this looks great on the multidev sites. I'm reviewing this now.

Copy link
Contributor

@kienstra kienstra left a comment

Choose a reason for hiding this comment

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

Approved

Hi @westonruter,
This looks really good. There are some comments below about approach, but I think it's ready to merge if you're happy with them.

};

if ( ! has_header_video() ) {
return self::output_header_image( $atts );
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of these helper functions to simplify conditionally_output_header()

*
* This is JS-driven in Core themes like Twenty Sixteen and Twenty Seventeen.
* So in order for the header video to display,
* this replaces the markup of the header image.
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a blocker, but maybe this 3-line DocBlock description could be removed. It looks to be the same as in conditionally_output_header().

*
* This is JS-driven in Core themes like Twenty Sixteen and Twenty Seventeen.
* So in order for the header video to display,
* this replaces the markup of the header image.
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the suggestion above, maybe these 3 lines could be removed.

* @return string $html Filtered markup.
*/
public static function output_header_image( $atts ) {

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a blocker, but this might be cleaner as:

public static function output_header_image( $atts ) {
        return AMP_HTML_Utils::build_tag( 'amp-img', $atts );
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm going to just remove the method entirely. There's no need for it.

'twentyseventeen-global', // There are somethings not yet implemented in AMP. See todos below.
'jquery-scrollto', // Implemented via add_smooth_scrolling().
'twentyseventeen-navigation', // Handled by add_nav_menu_styles, add_nav_menu_toggle, add_nav_sub_menu_buttons.
'twentyseventeen-skip-link-focus-fix', // Only needed by IE11 and when admin bar is present.
Copy link
Contributor

@kienstra kienstra Jun 4, 2018

Choose a reason for hiding this comment

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

It's great how these comments describe the scripts.

@@ -0,0 +1,943 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be great to eventually go back and add tests for this class, and other new methods.

*/
protected static $theme_features = array(
// Twenty Seventeen.
'twentyseventeen' => array(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great idea to pass an array of arguments to each of the methods, depending on the theme.

* @link https://github.com/WordPress/wordpress-develop/blob/f4580c122b7d0d2d66d22f806c6fe6e11023c6f0/src/wp-content/themes/twentyseventeen/assets/js/global.js#L105-L108
*/
public static function set_twentyseventeen_quotes_icon() {
add_filter( 'the_content', function ( $content ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't relevant now, but maybe a method would be better than an anonymous function here, to enable unit testing.

* and the CSS parser will then convert the selectors to amp-img and amp-video respectively.
* Nevertheless, object-fit does not apply on amp-img and it needs to apply on an actual img.
*/
add_action( 'wp_enqueue_scripts', function() use ( $args ) {
Copy link
Contributor

@kienstra kienstra Jun 4, 2018

Choose a reason for hiding this comment

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

Similar to the comment above, how about passing a method, instead of an anonymous function? This might help with unit testing, but this isn't a blocker now.

</style>
<?php
$styles = str_replace( array( '<style>', '</style>' ), '', ob_get_clean() );
wp_add_inline_style( get_template() . '-style', $styles );
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nice how this passes the contents of the buffer to wp_add_inline_style()

Comment on lines +783 to +789
/* Attempt to emulate https://github.com/WordPress/wordpress-develop/blob/5e9a39baa7d4368f7d3c36dcbcd53db6317677c9/src/wp-content/themes/twentyfifteen/js/functions.js#L108-L149 */
#sidebar {
position: sticky;
top: -9vh;
max-height: 109vh;
overflow-y: auto;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Per @schlessera in #4744, this can be improved to better emulate the non-AMP version.

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