-
Notifications
You must be signed in to change notification settings - Fork 196
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
Put SVG images into CSS #2623
base: master
Are you sure you want to change the base?
Put SVG images into CSS #2623
Conversation
a156283
to
bb9d795
Compare
@syphar: Any idea why there are sqlx errors? |
bb9d795
to
ecf053b
Compare
fc7a51f
to
416d7bc
Compare
build.rs
Outdated
@@ -80,11 +84,194 @@ fn main() -> Result<()> { | |||
write_known_targets(out_dir)?; | |||
compile_syntax(out_dir).context("could not compile syntax files")?; | |||
|
|||
println!("cargo::rustc-check-cfg=cfg(icons_out_dir)"); |
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.
I'm likely missing something, but where is this cfg ever set?
Or is this just for debugging this build script?
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's used in src/lib.rs
to import the generated Rust file.
build.rs
Outdated
let css_class = format!("f-a_{icon_name}_{icon_kind}"); | ||
css_output.push_str(&format!( | ||
"\ | ||
.{css_class} {{ |
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.
what I wonder:
isn't a CSS distribution with the icons something that font-awesome already provides? That we can just use?
not finished yet with all review, but one bigger question |
175247b
to
607615a
Compare
607615a
to
c9498fb
Compare
Since CSS files are often cached, we can take advantage of this to reduce network usage.
Now how it works: we inline the SVG images into a CSS file we generate at compile-time to ensure this file only contains what we need to limit its use but also to generate equivalent Rust types so we know at compile-time that the SVG exists.
I checked on caniuse for
mask
here: https://caniuse.com/css-masks. It says that more than 89% of current web browsers supports it unprefixed (without-webkit-
). With the prefix, it goes up to more than 96%. Just in case, I used both (thanks to HTML variables, we don't need to duplicate the SVG for bothmask
) so we should be on the safe side with more than 96% of our potential users being able to see the icons.I compared the HTML size on https://docs.rs/sysinfo/0.30.12/sysinfo/index.html. On current docs.rs, the transferred HTML is 52KB, with this PR is goes down to 40KB.