mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
minify: rebase relative urls in imported files.
4177b3f943
moved the font-face declarations from src/static/css/pad.css to two
imported files (src/static/css/pad/fonts.css, src/static/css/pad/toolbar.css)
in a different directory.
This results in the font files being invoked from CSSes residing in different
directories in the minified and un-minified case. URLs in the src attribute are
relative to the stylesheet path [0], and so we have to start requiring clean-css
to rebase them.
Before this change, the non minified casse worked by chance, because there were
a lot of "..", which ended up resolving to the root of the site anyways.
Fixes #3956
[0] https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src
This commit is contained in:
parent
6dd9e9adc8
commit
37abb21a55
1 changed files with 17 additions and 11 deletions
|
@ -426,17 +426,17 @@ function compressCSS(filename, content, callback)
|
||||||
/*
|
/*
|
||||||
* Changes done to migrate CleanCSS 3.x -> 4.x:
|
* Changes done to migrate CleanCSS 3.x -> 4.x:
|
||||||
*
|
*
|
||||||
* 1. Disabling rebase is necessary because otherwise the URLs for the web
|
* 1. Rework the rebase logic, because the API was simplified (but we have
|
||||||
* fonts become wrong.
|
* less control now). See:
|
||||||
|
* https://github.com/jakubpawlowicz/clean-css/blob/08f3a74925524d30bbe7ac450979de0a8a9e54b2/README.md#important-40-breaking-changes
|
||||||
*
|
*
|
||||||
* EXAMPLE 1:
|
* EXAMPLE:
|
||||||
* /static/css/src/static/font/fontawesome-etherpad.woff
|
* The URLs contained in a CSS file (including all the stylesheets
|
||||||
* instead of
|
* imported by it) residing on disk at:
|
||||||
* /static/font/fontawesome-etherpad.woff
|
* /home/muxator/etherpad/src/static/css/pad.css
|
||||||
* EXAMPLE 2 (this is more surprising):
|
*
|
||||||
* /p/src/static/font/opendyslexic.otf
|
* Will be rewritten rebasing them to:
|
||||||
* instead of
|
* /home/muxator/etherpad/src/static/css
|
||||||
* /static/font/opendyslexic.otf
|
|
||||||
*
|
*
|
||||||
* 2. CleanCSS.minify() can either receive a string containing the CSS, or
|
* 2. CleanCSS.minify() can either receive a string containing the CSS, or
|
||||||
* an array of strings. In that case each array element is interpreted as
|
* an array of strings. In that case each array element is interpreted as
|
||||||
|
@ -447,7 +447,13 @@ function compressCSS(filename, content, callback)
|
||||||
* "content" argument, but we have to wrap the absolute path to the CSS
|
* "content" argument, but we have to wrap the absolute path to the CSS
|
||||||
* in an array and ask the library to read it by itself.
|
* in an array and ask the library to read it by itself.
|
||||||
*/
|
*/
|
||||||
new CleanCSS({rebase: false}).minify([absPath], function (errors, minified) {
|
|
||||||
|
const basePath = path.dirname(absPath);
|
||||||
|
|
||||||
|
new CleanCSS({
|
||||||
|
rebase: true,
|
||||||
|
rebaseTo: basePath,
|
||||||
|
}).minify([absPath], function (errors, minified) {
|
||||||
if (errors) {
|
if (errors) {
|
||||||
// on error, just yield the un-minified original, but write a log message
|
// on error, just yield the un-minified original, but write a log message
|
||||||
console.error(`CleanCSS.minify() returned an error on ${filename} (${absPath}): ${errors}`);
|
console.error(`CleanCSS.minify() returned an error on ${filename} (${absPath}): ${errors}`);
|
||||||
|
|
Loading…
Reference in a new issue