From 0f3ca132314678b7bc3ac93cf2d65373cf476a3d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 3 Feb 2021 14:42:32 +0100 Subject: [PATCH] Use a `/*!` comment for the CSS header This change stops the `Compressed` formatter from removing the comment, allowing us to remove the `insertHeader()` logic which looked somewhat fragile. --- .../lib/system/style/StyleCompiler.class.php | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index dcfdca70bf..4dcf531d2b 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -162,7 +162,8 @@ final class StyleCompiler extends SingletonFactory $files[] = $customCustomSCSSFile; } - $scss = $this->bootstrap(); + $scss = "/*!\n\nstylesheet for '" . $styleName . "', generated on " . \gmdate('r') . " -- DO NOT EDIT\n\n*/\n"; + $scss .= $this->bootstrap(); foreach ($files as $file) { $scss .= $this->prepareFile($file); } @@ -177,10 +178,6 @@ final class StyleCompiler extends SingletonFactory $variables ); - $header = "/* stylesheet for '" . $styleName . "', generated on " . \gmdate('r') . " -- DO NOT EDIT */"; - - $css = $this->injectHeader($header, $css); - $this->writeCss(FileUtil::addTrailingSlash($testFileDir) . 'style', $css); } catch (\Exception $e) { return $e; @@ -269,7 +266,8 @@ final class StyleCompiler extends SingletonFactory $parameters = ['scss' => '']; EventHandler::getInstance()->fireAction($this, 'compile', $parameters); - $scss = $this->bootstrap(); + $scss = "/*!\n\nstylesheet for '" . $style->styleName . "', generated on " . \gmdate('r') . " -- DO NOT EDIT\n\n*/\n"; + $scss .= $this->bootstrap(); foreach ($this->getFiles() as $file) { $scss .= $this->prepareFile($file); } @@ -283,10 +281,6 @@ final class StyleCompiler extends SingletonFactory $variables ); - $header = "/* stylesheet for '" . $style->styleName . "', generated on " . \gmdate('r') . " -- DO NOT EDIT */"; - - $css = $this->injectHeader($header, $css); - $this->writeCss($this->getFilenameForStyle($style), $css); } @@ -330,7 +324,8 @@ final class StyleCompiler extends SingletonFactory $variables['style_image_path'] = "'../images/'"; - $scss = $this->bootstrap(); + $scss = "/*!\n\nstylesheet for the admin panel, generated on " . \gmdate('r') . " -- DO NOT EDIT\n\n*/\n"; + $scss .= $this->bootstrap(); foreach ($files as $file) { $scss .= $this->prepareFile($file); } @@ -345,25 +340,9 @@ final class StyleCompiler extends SingletonFactory $css = \str_replace('../icon/', '../../icon/', $css); $css = \preg_replace('~\.\./images/~', '../../images/', $css); - $header = "/* stylesheet for the admin panel, generated on " . \gmdate('r') . " -- DO NOT EDIT */"; - - $css = $this->injectHeader($header, $css); - $this->writeCss(WCF_DIR . 'acp/style/style', $css); } - /** - * Injects the given header string into the given css while ensuring - * that the charset at-rule remains at the beginning. - */ - private function injectHeader(string $header, string $css): string - { - // Strip charset at-rule. - $css = \preg_replace('~^@charset "UTF-8";\r?\n~', '', $css); - - return '@charset "UTF-8";' . "\n\n{$header}\n\n{$css}"; - } - /** * Returns a list of common stylesheets provided by the core. * -- 2.20.1