-
Notifications
You must be signed in to change notification settings - Fork 33
Resolve CSS URLs fix for #12 #28
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
Conversation
src/run.js
Outdated
| const root = /^\// | ||
| if (absolute.test(path)) { | ||
| // do nothing | ||
| } else if (root.test(path) /* && css path is the same domain as html document */) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to complete that before I do a full code review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how to handle this. WDYT?
|
We really need a unit test framework! Anyway, consider making an example that uses |
|
Jest? or you prefer something else? |
Yes, if you want to get a crack start I'd love to take a look. |
2a5b508 to
0a987cd
Compare
|
I made it work except this bug in csstree: There is an array in one place, while code always expects Lists for (var name in types) {
if (hasOwnProperty.call(types, name)) {
var config = types[name];
walkers[name] = Function('node', 'context', 'walk',
(config.context ? 'var old = context.' + config.context + ';\ncontext.' + config.context + ' = node;\n' : '') +
config.fields.map(function(field) {
var line = field.type === 'list'
- ? 'node.' + field.name + '.each(walk);'
+ ? 'node.' + field.name + '.forEach ? node.' + field.name + '.forEach(walk) : node.' + field.name + '.each(walk);'
: 'walk(node.' + field.name + ');';
if (field.nullable) {
line = 'if (node.' + field.name + ') {\n ' + line + '}';
}
return line;
}).join('\n') +
(config.context ? '\ncontext.' + config.context + ' = old;' : '')
);
}
} |
|
fixed |
|
Great work! But one thing we can maybe fix is to drop the domain name. background-image:url(http://localhost:8000/images/small.jpg)What it really ought to be is: background-image:url(/images/small.jpg)because there's no need to repeat the host (and protocol). |
|
yes you are right. missed it somehow |
src/run.js
Outdated
| path = value.value.substr(1, value.value.length - 2); | ||
| } | ||
| const absolute = /^https?:\/\/|^\/\//i | ||
| const root = /^\// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two variables don't need to be variables. They're only used once (each) and they're also a bit "poorly named". Like absolute doesn't carry any descriptive value. Unlike "absoluteUrl", "nodeTree" or "tree". Perhaps they should be called "absoluteUrlRegex"?
Can you consider putting the regexes inline?
For example:
if (/^https?:\/\/|^\/\//i.test(path)) {
...
src/run.js
Outdated
| const absolute = /^https?:\/\/|^\/\//i | ||
| const root = /^\// | ||
| const responseHost = url.parse(responseUrl).host | ||
| const pageHost = url.parse(pageUrl).host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be simplified to just:
const sameHost = url.parse(responseUrl).host === url.parse(pageUrl).host
peterbe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works!
I tried it and it did work for the "images" directory thing.
I still couldn't get the fontawesome example to work but we can iterate on that later.
Fonts are weird. Perhaps we should not worry about that first and first just make sure things work with thins like <link rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css>
Can you address the nits and then we'll land this.
|
ok, a bit later will do |
d333db6 to
603caa2
Compare
|
I tested bootstrap example and it works. What is not working for you? |
Earlier when I tested with fontawesome.min.css from a CDN, the fonts wouldn't load. But I suspect it's because fonts are weird and I kinda rushed my testing. Let's make this PR be about images for the moment and we can tackle the fonts problem in a separate PR. |
peterbe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
No description provided.