/** * Implements hook_library_info_alter(). */functionbartik_amp_library_info_alter(&$libraries,$extension){// This library persists even if listed in libraries-override.// This code will pull it out for good.if($extension=='core'&&isset($libraries['html5shiv'])){unset($libraries['html5shiv']);}}
/** * Implements hook_preprocess_html(). * * Reset toolbar classes and add sidebar toggle button to the header. */functionbartik_amp_preprocess_html(&$variables){// AMP Toolbar wrapped the toolbar in amp-sidebar, which is always// vertical. Change the page classes to reflect that.// @see toolbar.html.twig.if(!empty($variables['page_top']['toolbar'])){if(!empty($variables['attributes'])&&$variables['attributes']instanceofAttribute){$variables['attributes']->removeClass('toolbar-horizontal');$variables['attributes']->addClass('toolbar-vertical');}else{$variables['attributes']=newAttribute($variables['attributes']);$variables['attributes']->addClass(['toolbar-tray-open','toolbar-vertical','toolbar-fixed','toolbar-loading']);}}}
您还可以启用AMP CSS Tree Shaking模块。该模块不需要配置,只需启用它即可。它将自动“摇动”每个AMP页面上的css并删除页面上未使用的任何CSS。它还会缩小页面上的所有标记。使用此模块,您不必将包含的css严格降低到50KB,您可以依靠该模块来执行此操作。如果你有很多css,即使在摇晃之后你也可能超过50KB,所以你必须密切关注它,因为你可能仍然需要手动排除某些样式或库。
评论