Stylesheet: Don't parse library CSS as LESS

This commit is contained in:
Johannes Meyer 2022-06-13 09:45:47 +02:00
parent 3203cd8fea
commit c65ba3c2fc
1 changed files with 28 additions and 4 deletions

View File

@ -90,6 +90,9 @@ class StyleSheet
*/
protected $app;
/** @var string[] Pre-compiled CSS files */
protected $cssFiles = [];
/**
* Less compiler
*
@ -123,7 +126,11 @@ class StyleSheet
{
foreach ($this->app->getLibraries() as $library) {
foreach ($library->getCssAssets() as $lessFile) {
$this->lessCompiler->addLessFile($lessFile);
if (substr($lessFile, -4) === '.css') {
$this->cssFiles[] = $lessFile;
} else {
$this->lessCompiler->addLessFile($lessFile);
}
}
}
@ -186,6 +193,16 @@ class StyleSheet
$this->lessCompiler->setThemeMode($this->pubPath . '/css/modes/'. $mode . '.less');
}
/**
* Get all collected files
*
* @return string[]
*/
protected function getFiles(): array
{
return array_merge($this->cssFiles, $this->lessCompiler->getLessFiles());
}
/**
* Get the stylesheet for PDF export
*
@ -213,7 +230,13 @@ class StyleSheet
if ($minified) {
$this->lessCompiler->compress();
}
return $this->lessCompiler->render();
$css = '';
foreach ($this->cssFiles as $cssFile) {
$css .= file_get_contents($cssFile);
}
return $css . $this->lessCompiler->render();
}
/**
@ -233,14 +256,15 @@ class StyleSheet
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
if (! $noCache && FileCache::etagMatchesFiles($styleSheet->lessCompiler->getLessFiles())) {
$collectedFiles = $styleSheet->getFiles();
if (! $noCache && FileCache::etagMatchesFiles($collectedFiles)) {
$response
->setHttpResponseCode(304)
->sendHeaders();
return;
}
$etag = FileCache::etagForFiles($styleSheet->lessCompiler->getLessFiles());
$etag = FileCache::etagForFiles($collectedFiles);
$response->setHeader('ETag', $etag, true)
->setHeader('Content-Type', 'text/css', true);