public function AmpCssCollectionRenderer::doRewrite in Accelerated Mobile Pages (AMP) 8.3
Rewrite relative urls in css.
Rewrite relative css asset paths in css since they won't work correctly when css is rendered inline instead of as attachments. 1) Identify the path to where this CSS file originated from. This, when passed through rewriteFileURI() will iteratively remove ../ values within the css to rewrite the url relative to the web root. 2) Prefix all relative paths within this CSS file with the file path.
This mimics what the CSSOptimizer does when css is aggregated.
1 call to AmpCssCollectionRenderer::doRewrite()
- AmpCssCollectionRenderer::render in src/
Asset/ AmpCssCollectionRenderer.php - Renders an asset collection.
File
- src/
Asset/ AmpCssCollectionRenderer.php, line 311
Class
- AmpCssCollectionRenderer
- Renders CSS assets.
Namespace
Drupal\amp\AssetCode
public function doRewrite($url, $css) {
$this->rewriteFileURIBasePath = dirname($url) . '/';
$css = preg_replace_callback('/url\\([\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\)/i', [
$this,
'rewriteFileURI',
], $css);
$css = $this
->minify($css);
return $css;
}