Skip to content
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

Relative CSS paths are wrong #11

Closed
wazum opened this issue Jul 18, 2022 · 7 comments
Closed

Relative CSS paths are wrong #11

wazum opened this issue Jul 18, 2022 · 7 comments

Comments

@wazum
Copy link

wazum commented Jul 18, 2022

This issue did already exist in the forge and bitbucket tracker, but was never fixed.
Now I changed to the recent version and had to adapt my patch.

Example:
in the CSS file generated by TYPO3 there's path like ../../../typo3conf/ext/my_ext/Resources/Public/fonts/myfont.xxx and the problem is that your extension passes the content of the file to the $minifier->add method, which results in appending another ../../.. in front of the already correct relative paths (because the source is missing).
The solution is to write the output of compressCss to a file and pass the file name to $minifier->add, then the source path is correctly determined by minifier and not changed.

Here's my local patch:

+++ Classes/Minifier.php
@@ -121,7 +121,8 @@
             $minifier = new $minifierClassName();
             if ($type === self::TYPE_STYLESHEET) {
                 $minifier->setImportExtensions([]);
-                $minifier->add($this->compressCss(file_get_contents($config['file'])));
+                file_put_contents($pathSite . 'tmp' . $targetFilename, $this->compressCss(file_get_contents($config['file'])));
+                $minifier->add($targetFilename);
             } else {
                 $minifier->add($config['file']);
             }
@wazum
Copy link
Author

wazum commented Jul 18, 2022

See vendor/matthiasmullie/minify/src/Minify.php:89 for details on how the key is generated and then used in the execute method vendor/matthiasmullie/minify/src/CSS.php:301 as $source variable to determine the correct path.

@a-r-m-i-n
Copy link
Owner

a-r-m-i-n commented Jul 18, 2022

Hi, thanks for you issue. I've recently used EXT:min in a project including fonts and there I had no issues.

When your CSS is located in Resources/Public/Css/ and your font in Resources/Public/fonts you can simply address the font in CSS like this:

src: url("../fonts/my-font-regular.eot");

Also I'm suspisious that your approach really works, because when you create the $pathSite . $targetFilename file on your own, minifier will not minify it anymore (see condition in line 129) https://github.com/a-r-m-i-n/min/blob/master/Classes/Minifier.php#L129). Only the additional CSS compression will be applied to your CSS, then.

@wazum
Copy link
Author

wazum commented Jul 19, 2022

@a-r-m-i-n thanks, the same file name is a mistake, point taken, the rest is still valid, but maybe you have an idea how to solve it:

  • I already have the ../fonts/… path in my source CSS files
  • but when TYPO3 concatenates the CSS files
    page.config {
        compressCss = 1
        concatenateCss = 1
  • it uses a method \TYPO3\CMS\Core\Resource\ResourceCompressor::cssFixRelativeUrlPaths which changes the paths to ../../../something/…
  • which leads to the problem described above
    I don't know how you circumvent this in your projects, but would be nice to learn

@a-r-m-i-n
Copy link
Owner

a-r-m-i-n commented Aug 9, 2022

Hey. I'm currently working on #2 and I think I know where the problem is. When you concatenate css files, TYPO3 is fixing the relative links, because the location of the actual called file moved to typo3temp/assets/compressed

When min is doing the same, the file paths are not getting adjusted. Need to investigate further, but it looks promising. Now, I'm on your page ;)

@a-r-m-i-n
Copy link
Owner

@wazum I think I got it :) Could you please test with the latest master? Thank you

@Patta
Copy link

Patta commented Aug 11, 2022

@a-r-m-i-n thanks for version 2.1.0. The relative css paths of fonts in a compressed file are working now, but not if you already use the composer-installer v4 package with TYPO3 11, which has a different folder structure of public assets. See also: https://b13.com/core-insights/typo3-and-composer-weve-come-a-long-way

@a-r-m-i-n
Copy link
Owner

Thanks for your response. I think this worth a dedicated issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants