-
Notifications
You must be signed in to change notification settings - Fork 382
Add PreloadHeroImage Optimizer transformer #5350
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
Changes from 35 commits
9706741
53dc56a
437fa8d
b268cd6
72a01b5
99eec9b
4d462af
3a98ad0
d8b2015
0b78bd7
4c4bc56
9703ebd
4f1426b
96f88ab
fcbcc4a
16dbf2a
8795fde
d46c44e
d97d49c
e850726
8cfadb1
51da2cd
111e497
a0dc9cc
1acb66f
7c32636
7af1c5b
cbb01a1
ae4b1bd
86f34ef
a4f2ec4
361efde
71d5170
e98e684
56804ea
d890f2e
034e724
0a07090
b05b035
0ab477e
3850c25
b71afe8
122a5a0
392709c
025d54b
e68f7ff
9b58169
b0ed9ba
b6033c2
c251909
d35b8a8
d1ba9c7
fba400f
7afa02b
a6c1a89
1169981
8eb3250
ea637d5
6ae3e3e
a981eeb
7309ee3
dda3065
6caab91
17380a7
607fa5d
6343103
d4465a4
ec6daca
a56f7c1
29daf74
1555c72
07689ad
27d3be6
30973c6
e47cb8f
2bd673f
a92b8c1
9addb67
60abe7a
c249d69
a146319
7ba627e
01b33e0
cdb8818
a856eb1
1eed7f1
332ad51
d41fab7
ce95088
a7ac118
3320b6f
6ee3b0a
910342c
b2f67a6
94f4259
5270af3
ec5584f
981e960
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,11 +16,14 @@ interface Extension | |||||
const DYNAMIC_CSS_CLASSES = 'amp-dynamic-css-classes'; | ||||||
const EXPERIMENT = 'amp-experiment'; | ||||||
const GEO = 'amp-geo'; | ||||||
const IFRAME = 'amp-iframe'; | ||||||
const IMAGE = 'amp-img'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stick with the extension name being the same as the constant name (other areas where this is being used would also need to be updated).
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do this in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
const MUSTACHE = 'amp-mustache'; | ||||||
const PIXEL = 'amp-pixel'; | ||||||
const SOCIAL_SHARE = 'amp-social-share'; | ||||||
const STORY = 'amp-story'; | ||||||
const VIDEO = 'amp-video'; | ||||||
const VIDEO_IFRAME = 'amp-video-iframe'; | ||||||
const YOUTUBE = 'amp-youtube'; | ||||||
|
||||||
/** | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace AmpProject; | ||
|
||
/** | ||
* Helper class to work with URLs. | ||
* | ||
* @package ampproject/common | ||
*/ | ||
final class Url | ||
{ | ||
|
||
/** | ||
* Default URL parts to use when constructing an absolute URL out of a relative one. | ||
* | ||
* @var string[] | ||
*/ | ||
const URL_DEFAULT_PARTS = [ | ||
'scheme' => 'https', | ||
'host' => 'example.com', | ||
westonruter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'port' => '', | ||
'user' => '', | ||
'pass' => '', | ||
'path' => '', | ||
'query' => '', | ||
'fragment' => '', | ||
]; | ||
|
||
/** | ||
* Check whether a given src string is a valid image source URL. | ||
* | ||
* @param string $src Src string to validate. | ||
* @return bool Whether the src string is a valid image source URL. | ||
*/ | ||
public static function isValidImageSrc($src) | ||
schlessera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
list($scheme, $host, $port, $user, $pass, $path, $query, $fragment) = array_values( | ||
array_merge( | ||
self::URL_DEFAULT_PARTS, | ||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels a bit risky as it relies on the array keys being defined in the exact same order as the items in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we control both, so why wouldn't they? |
||
(array)parse_url($src) | ||
) | ||
); | ||
|
||
if ($scheme === 'data') { | ||
pierlon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} | ||
|
||
$userpass = $user; | ||
|
||
if (! empty($pass)) { | ||
$userpass = "{$user}:{$pass}"; | ||
schlessera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (! empty($userpass)) { | ||
$userpass .= '@'; | ||
} | ||
|
||
$url = sprintf( | ||
'%s://%s%s%s/%s%s%s', | ||
$scheme, | ||
$host, | ||
$userpass, | ||
schlessera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
empty($port) ? '' : ":{$port}", | ||
ltrim($path, '/'), | ||
empty($query) ? '' : "?{$query}", | ||
empty($fragment) ? '' : "#{$fragment}" | ||
); | ||
|
||
return (bool)filter_var($url, FILTER_VALIDATE_URL); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.