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

Regex is not compatible when absolute_urls: true is set. #12

Open
mdonadio opened this issue Jan 2, 2018 · 4 comments
Open

Regex is not compatible when absolute_urls: true is set. #12

mdonadio opened this issue Jan 2, 2018 · 4 comments

Comments

@mdonadio
Copy link
Contributor

mdonadio commented Jan 2, 2018

Grav version: 1.3.10
CDN version: 1.4.0

If a Twig template uses the url() function to reference an asset, eg

<link rel="icon" type="image/png" sizes="32x32" href="{{ url('theme://images/favicon/favicon-32x32.png') }}">

then the final URL doesn't get updated to point to the CDN.

@mdonadio
Copy link
Contributor Author

mdonadio commented Jan 2, 2018

The problem is that if system.yaml has absolute_urls: true, then the the regex will skip them.

@mdonadio mdonadio changed the title Asset URLs using Twig url() function don't get replaced Regex is not compatible when absolute_urls: true is set. Jan 2, 2018
@beejay41
Copy link

something like
<div style="background: url({{page.media[feature.background].url}});">.... }}
also doesn't get updated, despite 'absolute_urls:false'.
Is this the same issue or something else? It fits the original problem description.

Grav: 1.5.8
CDN: 1.5.0

@beejay41
Copy link

OK, I see what the problem is with 'url()', the value does not need to be quoted and the Grav url() method doesn't include quotes. Unfortunately, your regex: https://regex101.com/r/8zAnec/2 requires quotes.
"/(url\([\'\"]?)... making the quotes optional solves mine and the original problem.
Hope this helps.

@beejay41
Copy link

Can I suggest the following for line 83:
$regex = "/(url\([\'\"]??)(?:" . $base . ")(.*?\.(?:" . $extensions . "))(.*?\).*?;)/i";
Semicolon doesn't necessarily follow closing ) when used with background:
style="background:transparent url({{page.media[feature.background].url}}) center center/ 100% no-repeat;"
I hope that covers everything, but my regex knowledge is not great.

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

2 participants