function amp_preprocess_html in Accelerated Mobile Pages (AMP) 8.3
Implements hook_preprocess_html().
File
- ./
amp.module, line 35 - Provides functionality for handling AMP.
Code
function amp_preprocess_html(&$variables) {
$amp_context = \Drupal::service('router.amp_context');
if ($amp_context
->isAmpRoute()) {
foreach ($variables['page']['#attached']['html_head'] as $key => $value) {
if ($value[1] === 'viewport') {
$value[0]['#attributes']['content'] = 'width=device-width,minimum-scale=1,initial-scale=1';
$variables['page']['#attached']['html_head'][$key] = $value;
}
// Remove Big Pipe's meta tag, which is invalid AMP markup.
// We are generating placeholders on the server so should not be needed.
if ($key == 'big_pipe_detect_nojs') {
unset($variables['page']['#attached']['html_head'][$key]);
}
}
// Remove RDF and Metatag properties incompatible with AMP specification.
$attribute_list = [
'prefix',
'xmlns:dc',
'xmlns:og',
'xmlns:article',
'xmlns:book',
'xmlns:product',
'xmlns:profile',
'xmlns:video',
'itemtype',
'itemscope',
];
if (isset($variables['html_attributes'])) {
foreach ($attribute_list as $attribute_item) {
if (isset($variables['html_attributes'][$attribute_item])) {
unset($variables['html_attributes'][$attribute_item]);
}
}
}
}
}