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

Fix/fonts behind reverse proxy when minify = true #4002

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/node/handler/PadMessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ async function handleClientReady(client, message)
var clientVars = {
"skinName": settings.skinName,
"skinVariants": settings.skinVariants,
"randomVersionString": settings.randomVersionString,
"accountPrivs": {
"maxRevisions": 100
},
Expand Down
28 changes: 17 additions & 11 deletions src/node/utils/Minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,17 @@ function compressCSS(filename, content, callback)
/*
* Changes done to migrate CleanCSS 3.x -> 4.x:
*
* 1. Disabling rebase is necessary because otherwise the URLs for the web
* fonts become wrong.
* 1. Rework the rebase logic, because the API was simplified (but we have
* less control now). See:
* https://github.com/jakubpawlowicz/clean-css/blob/08f3a74925524d30bbe7ac450979de0a8a9e54b2/README.md#important-40-breaking-changes
*
* EXAMPLE 1:
* /static/css/src/static/font/fontawesome-etherpad.woff
* instead of
* /static/font/fontawesome-etherpad.woff
* EXAMPLE 2 (this is more surprising):
* /p/src/static/font/opendyslexic.otf
* instead of
* /static/font/opendyslexic.otf
* EXAMPLE:
* The URLs contained in a CSS file (including all the stylesheets
* imported by it) residing on disk at:
* /home/muxator/etherpad/src/static/css/pad.css
*
* Will be rewritten rebasing them to:
* /home/muxator/etherpad/src/static/css
*
* 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
Expand All @@ -447,7 +447,13 @@ function compressCSS(filename, content, callback)
* "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.
*/
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) {
// on error, just yield the un-minified original, but write a log message
console.error(`CleanCSS.minify() returned an error on ${filename} (${absPath}): ${errors}`);
Expand Down
8 changes: 4 additions & 4 deletions src/static/js/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function Ace2Editor()

// disableCustomScriptsAndStyles can be used to disable loading of custom scripts
if(!clientVars.disableCustomScriptsAndStyles){
$$INCLUDE_CSS("../static/css/pad.css");
$$INCLUDE_CSS("../static/css/pad.css?v=" + clientVars.randomVersionString);
}

var additionalCSS = _(hooks.callAll("aceEditorCSS")).map(function(path){
Expand All @@ -247,7 +247,7 @@ function Ace2Editor()
return '../static/plugins/' + path;
});
includedCSS = includedCSS.concat(additionalCSS);
$$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css");
$$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css?v=" + clientVars.randomVersionString);

pushStyleTagsFor(iframeHTML, includedCSS);

Expand Down Expand Up @@ -321,7 +321,7 @@ window.onload = function () {\n\
var includedCSS = [];
var $$INCLUDE_CSS = function(filename) {includedCSS.push(filename)};
$$INCLUDE_CSS("../static/css/iframe_editor.css");
$$INCLUDE_CSS("../static/css/pad.css");
$$INCLUDE_CSS("../static/css/pad.css?v=" + clientVars.randomVersionString);


var additionalCSS = _(hooks.callAll("aceEditorCSS")).map(function(path){
Expand All @@ -331,7 +331,7 @@ window.onload = function () {\n\
return '../static/plugins/' + path }
);
includedCSS = includedCSS.concat(additionalCSS);
$$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css");
$$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css?v=" + clientVars.randomVersionString);

pushStyleTagsFor(outerHTML, includedCSS);

Expand Down