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

root relative urls in css are being meesed up #87

Open
diegodorado opened this issue Sep 22, 2016 · 7 comments
Open

root relative urls in css are being meesed up #87

diegodorado opened this issue Sep 22, 2016 · 7 comments
Labels

Comments

@diegodorado
Copy link

diegodorado commented Sep 22, 2016

I have to change minit-css.php on line 88, because root relative urls were being messed up.

this is what i changed:

// Make all local asset URLs absolute
        $content = preg_replace(
            '/url\(["\' ]?+(?!data:|https?:|\/\/|\/)(.*?)["\' ]?\)/i',
            sprintf( "url('%s/$1')", $this->handler->base_url . dirname( $src ) ),
            $content
        );

Note the |\/ addition to the regex, to avoid replacing root relative urls.

I understand that having root relative urls in css isnt a very good practice, at least for wordpress, but it happened that i already have them.

Beside that, the plugin is absolutly great as simple! Just what i needed

@kasparsd kasparsd added the bug label Sep 22, 2016
@kasparsd
Copy link
Owner

@diegodorado Thanks you for reporting the issue. Could you please post the "messed up" URL that it generated?

@diegodorado
Copy link
Author

Sure:

say I have a style.css file inside wp-content/themes/mytheme/ with the following rule

some.selector{ background: url(/wp-content/uploads/some-img.jpg); }

(I know, I know.... bad practices)

then, after minit run, it concat
site_url + css_path + content, so and I end up with

some.selector{ background: url(http://mysite.url/wp-content/themes/mytheme//wp-content/uploads/some-img.jpg); }

Anyway, good or bad practice, I think that following urls shouldnt be touched:

  • absolute urls (done)
  • protocol relative urls (done)
  • root relative urls (this was missing)

@kasparsd
Copy link
Owner

Great, thank you @diegodorado! That will help during testing.

@szepeviktor
Copy link
Contributor

szepeviktor commented Sep 22, 2016

@diegodorado I was in your shoe. That is why I developed a ultra-simplified but proper theme options page.

@diegodorado
Copy link
Author

And again: great work... i ve been trying out several popular plugins but this is the only only that gave me a single js and a single css output, without breaking the site...I was going to do it by myslef, but you saved me a lot of work.

@diegodorado
Copy link
Author

@szepeviktor , sorry, i dont get it, what does proper theme options page do with this respect?

@szepeviktor
Copy link
Contributor

If you have an options page you don't have to hardcode /wp-content/uploads/.

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

No branches or pull requests

3 participants