Skip to content

Commit

Permalink
Merge pull request #7615 from ampproject/update/amphtml-spec-23090118…
Browse files Browse the repository at this point in the history
…27000

Update amphtml spec to 2309011827000
  • Loading branch information
westonruter authored Oct 17, 2023
2 parents 4132152 + 93ade31 commit 339b8e3
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 1,364 deletions.
69 changes: 61 additions & 8 deletions bin/amphtml-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ def ParseRules(repo_directory, out_dir):
'!DOCTYPE',
]

manual_versioning = {
'amp-stream-gallery': ['0.1'],
'amp-wordpress-embed': ['1.0'],
}

bento_spec_names = {}

for (field_desc, field_val) in rules.ListFields():
if 'tags' == field_desc.name:
for tag_spec in field_val:
Expand All @@ -380,6 +387,32 @@ def ParseRules(repo_directory, out_dir):
else:
tag_list = allowed_tags[tag_name]

if 'SCRIPT' == tag_spec.tag_name:
gotten_tag_spec = GetTagSpec(tag_spec, attr_lists)
if gotten_tag_spec is not None:
if 'extension_spec' in gotten_tag_spec['tag_spec'] and 'bento_supported_version' in gotten_tag_spec['tag_spec']['extension_spec']:
if '' != tag_spec.spec_name:
# In case some other extension requires bento extension, we need to know the spec name of the bento extension.
bento_spec_names[ gotten_tag_spec['tag_spec']['extension_spec']['name'] ] = tag_spec.spec_name

# Remove bento spec version from the list of versions.
version = gotten_tag_spec['tag_spec']['extension_spec']['version']
bento_version = gotten_tag_spec['tag_spec']['extension_spec']['bento_supported_version']

for _version in bento_version:
if _version in version:
version.remove( _version )

gotten_tag_spec['tag_spec']['extension_spec'].pop('bento_supported_version', None)
gotten_tag_spec['tag_spec']['extension_spec']['version'] = version

if len( version ) == 0 and gotten_tag_spec['tag_spec']['extension_spec']['name'] in manual_versioning.keys():
gotten_tag_spec['tag_spec']['extension_spec']['version'] = manual_versioning[ gotten_tag_spec['tag_spec']['extension_spec']['name'] ]

tag_list.append(gotten_tag_spec)
allowed_tags[tag_name] = tag_list
continue

gotten_tag_spec = GetTagSpec(tag_spec, attr_lists)
if gotten_tag_spec is not None:
tag_list.append(gotten_tag_spec)
Expand All @@ -399,6 +432,18 @@ def ParseRules(repo_directory, out_dir):

descendant_lists[_list.name].append( val.lower() )

# Remove any tags that requires bento_spec_names.keys()
for tag_name, tag_list in allowed_tags.items():
for tag in tag_list:
if 'requires_extension' not in tag['tag_spec'] or 'requires_condition' not in tag['tag_spec']:
continue
requires_condition = tag['tag_spec']['requires_condition'][0]
requires_extension = tag['tag_spec']['requires_extension'][0]
if requires_extension not in bento_spec_names:
continue
if bento_spec_names[requires_extension] == requires_condition:
tag_list.remove( tag )

# Separate extension scripts from non-extension scripts and gather the versions
extension_scripts = collections.defaultdict(list)
extension_specs_by_satisfies = dict()
Expand All @@ -407,8 +452,8 @@ def ParseRules(repo_directory, out_dir):
if 'extension_spec' in script_tag['tag_spec']:
extension = script_tag['tag_spec']['extension_spec']['name']
extension_scripts[extension].append(script_tag)
if 'satisfies' in script_tag['tag_spec']:
satisfies = script_tag['tag_spec']['satisfies']
if 'satisfies_condition' in script_tag['tag_spec']:
satisfies = script_tag['tag_spec']['satisfies_condition']
else:
satisfies = extension
if satisfies in extension_specs_by_satisfies:
Expand Down Expand Up @@ -440,7 +485,8 @@ def ParseRules(repo_directory, out_dir):
# Amend the allowed_tags to supply the required versions for each component.
for tag_name, tags in allowed_tags.items():
for tag in tags:
tag['tag_spec'].pop('satisfies', None) # We don't need it anymore.
tag['tag_spec'].pop('satisfies_condition', None) # We don't need it anymore.
tag['tag_spec'].pop('requires_condition', None) # We don't need it anymore.
requires = tag['tag_spec'].pop('requires', [])

if 'requires_extension' not in tag['tag_spec']:
Expand Down Expand Up @@ -468,11 +514,10 @@ def ParseRules(repo_directory, out_dir):
tag['tag_spec']['requires_extension'] = requires_extension_versions

extensions = json.load( open( os.path.join( repo_directory, 'build-system/compile/bundles.config.extensions.json' ) ) )
bento_extensions = json.load( open( os.path.join( repo_directory, 'build-system/compile/bundles.config.bento.json' ) ) )

latest_versions = json.load( open( latest_extensions_file_path ) )
extensions_versions = dict()
for extension in extensions + bento_extensions:
for extension in extensions:
if '-impl' in extension['name'] or '-polyfill' in extension['name']:
continue

Expand Down Expand Up @@ -686,6 +731,11 @@ def GetTagRules(tag_spec):
for requires_extension in tag_spec.requires_extension:
requires_extension_list.add(requires_extension)

requires_condition_list = set()
if hasattr(tag_spec, 'requires_condition') and len( tag_spec.requires_condition ) != 0:
for requires_condition in tag_spec.requires_condition:
requires_condition_list.add(requires_condition)

if hasattr(tag_spec, 'requires') and len( tag_spec.requires ) != 0:
tag_rules['requires'] = [ requires for requires in tag_spec.requires ]

Expand All @@ -699,6 +749,9 @@ def GetTagRules(tag_spec):
if len( requires_extension_list ) > 0:
tag_rules['requires_extension'] = list( requires_extension_list )

if len( requires_condition_list ) > 0:
tag_rules['requires_condition'] = list( requires_condition_list )

if hasattr(tag_spec, 'reference_points') and len( tag_spec.reference_points ) != 0:
tag_reference_points = {}
for reference_point_spec in tag_spec.reference_points:
Expand Down Expand Up @@ -785,10 +838,10 @@ def GetTagRules(tag_spec):
if tag_spec.HasField('spec_name'):
tag_rules['spec_name'] = UnicodeEscape(tag_spec.spec_name)

if hasattr(tag_spec, 'satisfies') and len( tag_spec.satisfies ) > 0:
if len( tag_spec.satisfies ) > 1:
if hasattr(tag_spec, 'satisfies_condition') and len( tag_spec.satisfies_condition ) > 0:
if len( tag_spec.satisfies_condition ) > 1:
raise Exception('More than expected was satisfied')
tag_rules['satisfies'] = tag_spec.satisfies[0]
tag_rules['satisfies_condition'] = tag_spec.satisfies_condition[0]

if tag_spec.HasField('spec_url'):
tag_rules['spec_url'] = UnicodeEscape(tag_spec.spec_url)
Expand Down
2 changes: 1 addition & 1 deletion bin/latest-extension-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"amp-powr-player" : "0.1",
"amp-reach-player" : "0.1",
"amp-recaptcha-input" : "0.1",
"amp-redbull-player" : "0.1",
"amp-reddit" : "0.1",
"amp-render" : "1.0",
"amp-riddle-quiz" : "0.1",
Expand All @@ -107,6 +106,7 @@
"amp-sidebar" : "0.1",
"amp-skimlinks" : "0.1",
"amp-slides" : "0.1",
"amp-slikeplayer" : "0.1",
"amp-smartlinks" : "0.1",
"amp-social-share" : "0.1",
"amp-soundcloud" : "0.1",
Expand Down
63 changes: 3 additions & 60 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,32 +913,6 @@ function amp_add_generator_metadata() {
printf( '<meta name="generator" content="%s">', esc_attr( $content ) );
}

/**
* Determine whether the use of Bento components is enabled.
*
* When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation
* of the component framework.
*
* @since 2.2
* @link https://blog.amp.dev/2021/01/28/bento/
*
* @return bool Whether Bento components are enabled.
*/
function amp_is_bento_enabled() {
/**
* Filters whether the use of Bento components is enabled.
*
* When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation
* of the component framework.
*
* @since 2.2
* @link https://blog.amp.dev/2021/01/28/bento/
*
* @param bool $enabled Enabled.
*/
return apply_filters( 'amp_bento_enabled', false );
}

/**
* Register default scripts for AMP components.
*
Expand Down Expand Up @@ -990,15 +964,10 @@ function amp_register_default_scripts( $wp_scripts ) {
$extension_specs['amp-carousel']['latest'] = '0.2';
}

$bento_enabled = amp_is_bento_enabled();
foreach ( $extension_specs as $extension_name => $extension_spec ) {
if ( $bento_enabled && ! empty( $extension_spec['bento'] ) ) {
$version = $extension_spec['bento']['version'];
} else {
$version = $extension_spec['latest'];
}
$version = $extension_spec['latest'];

// Skip registering the amp-gfycat extension.
// Skip registering the amp-gfycat extension, as gfycat have been sunset.
// @TODO: Remove this once the amp-gfycat extension is removed from spec.
if ( 'amp-gfycat' === $extension_name ) {
continue;
Expand All @@ -1013,7 +982,7 @@ function amp_register_default_scripts( $wp_scripts ) {
$wp_scripts->add(
$extension_name,
$src,
[ 'amp-runtime' ], // @todo Eventually this will not be present for Bento.
[ 'amp-runtime' ],
null
);
}
Expand Down Expand Up @@ -1043,28 +1012,6 @@ function amp_register_default_styles( WP_Styles $styles ) {
AMP__VERSION
);
$styles->add_data( 'amp-icons', 'rtl', 'replace' );

// These are registered exclusively for non-AMP pages that manually enqueue them. They aren't needed on
// AMP pages due to the runtime style being present and because the styles are inlined in the scripts already.
if ( amp_is_bento_enabled() ) {
foreach ( AMP_Allowed_Tags_Generated::get_extension_specs() as $extension_name => $extension_spec ) {
if ( empty( $extension_spec['bento']['has_css'] ) ) {
continue;
}

$src = sprintf(
'https://cdn.ampproject.org/v0/%s-%s.css',
$extension_name,
$extension_spec['bento']['version']
);
$styles->add(
$extension_name,
$src,
[],
null
);
}
}
}

/**
Expand Down Expand Up @@ -1560,8 +1507,6 @@ function amp_get_content_sanitizers( $post = null ) {
'comments_live_list' => ! empty( $theme_support_args['comments_live_list'] ),
],

AMP_Bento_Sanitizer::class => [],

// The AMP_PWA_Script_Sanitizer run before AMP_Script_Sanitizer, to prevent the script tags
// from getting removed in PWA plugin offline/500 templates.
AMP_PWA_Script_Sanitizer::class => [],
Expand Down Expand Up @@ -1606,7 +1551,6 @@ function amp_get_content_sanitizers( $post = null ) {
AMP_Accessibility_Sanitizer::class => [],
// Note: This validating sanitizer must come at the end to clean up any remaining issues the other sanitizers didn't catch.
AMP_Tag_And_Attribute_Sanitizer::class => [
'prefer_bento' => amp_is_bento_enabled(),
'allow_localhost_http_protocol' => $is_dev_mode,
],
];
Expand Down Expand Up @@ -1743,7 +1687,6 @@ function amp_get_content_sanitizers( $post = null ) {
$expected_final_sanitizer_order = [
AMP_Auto_Lightbox_Disable_Sanitizer::class,
AMP_Core_Theme_Sanitizer::class, // Must come before script sanitizer since onclick attributes are removed.
AMP_Bento_Sanitizer::class, // Bento scripts may be preserved here.
AMP_PWA_Script_Sanitizer::class, // Must come before script sanitizer since PWA offline page scripts are removed.
AMP_GTag_Script_Sanitizer::class, // Must come before script sanitizer since gtag.js is removed.
AMP_Script_Sanitizer::class, // Must come before sanitizers for images, videos, audios, comments, forms, and styles.
Expand Down
41 changes: 0 additions & 41 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1559,47 +1559,6 @@ public static function ensure_required_markup( Document $dom, $script_handles =
}
}

// Make sure that Bento versions are used when required, either by explicitly requesting Bento or when the document is non-valid AMP.
$is_using_bento = (
array_key_exists( AMP_Tag_And_Attribute_Sanitizer::class, $sanitizers )
&&
$sanitizers[ AMP_Tag_And_Attribute_Sanitizer::class ]->get_arg( 'prefer_bento' )
);
if ( $is_using_bento ) {
$bento_extension_count = 0;

// Override all required scripts with the available Bento versions.
foreach ( $amp_scripts as $extension_name => $script_element ) {
if ( ! empty( $extension_specs[ $extension_name ]['bento']['version'] ) ) {
$script_element->setAttribute(
Attribute::SRC,
sprintf(
'https://cdn.ampproject.org/v0/%s-%s.js',
$extension_name,
$extension_specs[ $extension_name ]['bento']['version']
)
);
$bento_extension_count++;
}
}

// Enable Bento experiment per <https://amp.dev/documentation/guides-and-tutorials/start/bento_guide/?format=websites#enable-bento-experiment>.
// @todo Remove this once Bento no longer requires an experiment to opt-in.
if ( $bento_extension_count > 0 ) {
$bento_experiment_script = $dom->createElement( Tag::SCRIPT );
$bento_experiment_script->appendChild(
$dom->createTextNode( '(self.AMP = self.AMP || []).push(function (AMP) { AMP.toggleExperiment("bento", true); });' )
);

ValidationExemption::mark_node_as_px_verified( $bento_experiment_script );
if ( DevMode::isActiveForDocument( $dom ) ) {
$bento_experiment_script->setAttributeNode( $dom->createAttribute( Attribute::DATA_AMPDEVMODE ) );
}

$dom->head->appendChild( $bento_experiment_script );
}
}

/*
* "3. If your page includes render-delaying extensions (e.g., amp-experiment, amp-dynamic-css-classes, amp-story),
* preload those extensions as they're required by the AMP runtime for rendering the page."
Expand Down
32 changes: 32 additions & 0 deletions includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,35 @@ function amp_post_template_add_analytics_script( $data ) {
}
return $data;
}

/**
* Determine whether the use of Bento components is enabled.
*
* When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation
* of the component framework.
*
* @since 2.2
* @link https://blog.amp.dev/2021/01/28/bento/
*
* @deprecated 2.4.3 Bento support has been removed.
* @codeCoverageIgnore
* @return bool Whether Bento components are enabled.
*/
function amp_is_bento_enabled() {
_deprecated_function( __FUNCTION__, 'AMP 2.4.3' );

/**
* Filters whether the use of Bento components is enabled.
*
* When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation
* of the component framework.
*
* @since 2.2
* @link https://blog.amp.dev/2021/01/28/bento/
*
* @deprecated 2.4.3 Bento support has been removed.
*
* @param bool $enabled Enabled.
*/
return apply_filters_deprecated( 'amp_bento_enabled', [ false ], 'AMP 2.4.3', 'Remove beno support', 'Bento support has been removed.' );
}
Loading

0 comments on commit 339b8e3

Please sign in to comment.