test inlining
This commit is contained in:
parent
b59414f836
commit
68d77a2138
@ -9,21 +9,28 @@ function inlineLocalStylesFromHref($inputString) {
|
||||
// Extract the href attribute value
|
||||
$href = $match[1];
|
||||
|
||||
$fname = $_SERVER['DOCUMENT_ROOT'] . '/' . $href;
|
||||
echo "from $fname";
|
||||
// Get the content of the local CSS file
|
||||
$cssContent = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . $href);
|
||||
$cssFilePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $href;
|
||||
echo "from $cssFilePath";
|
||||
|
||||
// Replace url() declarations in the CSS content with updated paths
|
||||
$cssContent = preg_replace_callback('/url\(["\']?\/(.*?)(?:[?#].*?)?["\']?\)/i', function($urlMatch) {
|
||||
// Get the content of the local CSS file
|
||||
$cssContent = file_get_contents($cssFilePath);
|
||||
|
||||
// Get the directory where the CSS file is located
|
||||
$cssDir = dirname($cssFilePath);
|
||||
|
||||
// Replace relative paths in the CSS content to be relative to the CSS file's directory
|
||||
$cssContent = preg_replace_callback('/url\(["\']?(\/.*?|.*?)["\']?\)/i', function($urlMatch) use ($cssDir) {
|
||||
// Extract the URL value
|
||||
$url = $urlMatch[1];
|
||||
|
||||
// Modify the path as needed
|
||||
$modifiedPath = '/new/path/' . $url;
|
||||
// Combine with the CSS file's directory to create an absolute path
|
||||
$absolutePath = $cssDir . '/' . $url;
|
||||
|
||||
// Make the path relative to the CSS file's directory
|
||||
$relativePath = ltrim(substr($absolutePath, strlen($_SERVER['DOCUMENT_ROOT'])), '/');
|
||||
|
||||
// Create the updated url() declaration
|
||||
$updatedUrlDeclaration = 'url("' . $modifiedPath . '")';
|
||||
$updatedUrlDeclaration = 'url("' . $relativePath . '")';
|
||||
|
||||
return $updatedUrlDeclaration;
|
||||
}, $cssContent);
|
||||
|
Loading…
Reference in New Issue
Block a user