Skip to content

Switch fontawesome from font files to embedded SVG #1033

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

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

notriddle
Copy link
Contributor

Fixes #790

@jyn514
Copy link
Member

jyn514 commented Sep 3, 2020

Can you post some screenshots of what this looks like after the change? I'm a little worried about changing so much of the CSS without any frontend tests ...

@jyn514 jyn514 added A-frontend Area: Web frontend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Sep 3, 2020
@notriddle
Copy link
Contributor Author

notriddle commented Sep 3, 2020

If anybody notices a change, other than people who disable web fonts, then I messed up

image

image

image

@pietroalbini
Copy link
Member

cc @Kixiron

This is great! I'm wondering, could we inline the SVG directly without having to download the .svg file? That would cut a network request completly, and since we don't use icons that much (except for maybe the source listing page?) it should also reduce the amount of data sent to viewers.

@pietroalbini
Copy link
Member

To be clear, landing this is also fine, if you don't have the time to make the other change or you prefer to do it in a followup :)

@notriddle
Copy link
Contributor Author

Yeah, we probably should switch to inlined SVG. I didn't originally do it, because there's no FontAwesome HOWTO for it, but I've done it before and know how. Also, IE11 shows blank spots where the icons ought to be, and inlining them would fix that.

@notriddle notriddle force-pushed the fontawesome-sprites branch 2 times, most recently from 29ae43f to 47f2484 Compare September 4, 2020 20:52
@notriddle
Copy link
Contributor Author

Okay, it embeds the SVG directly now. It looks identical.

@notriddle notriddle changed the title Switch fontawesome from font files to svg sprites Switch fontawesome from font files to embedded SVG Sep 4, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 5, 2020

It looks like you moved all the vendor files into a new repo, which you just published as a crate? https://github.com/notriddle/font-awesome-as-a-crate

What's the rationale for doing that? What's the long-term maintenance plan if we need to update? I want to avoid adding and deleting 8k lines of code every 2 weeks.

@notriddle
Copy link
Contributor Author

notriddle commented Sep 5, 2020

It looks like you moved all the vendor files into a new repo, which you just published as a crate? https://github.com/notriddle/font-awesome-as-a-crate

Yes.

What's the rationale for doing that?

font-awesome-as-a-crate doesn't just vendor the SVG files. It concatenates them into a massive rust source file.

The rationale for embedding the SVG files directly in your binary:

  • avoid file I/O occurring in your Tera Filter, which would likely have complex knock-on effects when combined with async
  • avoid complex error handling in your Tera Filter, which is the inevitable outcome of file I/O
  • avoid having to carefully construct filesystem paths, with all the terrible possible outcomes and failure modes that come with that (using the infrastructure that the existing static file server uses is not an option, because it's not an HTTP request)
  • I'm guessing it's faster to pull a string out of the binary's text section than it is to open a file for every request, though I have done no benchmarking to justify this wild speculation

The rationale for doing it in its own crate:

  • we're not using any of docs.rs's file handling infrastructure anyway, so all the other stuff in its build.rs was just getting in the way while I coded up its codegen script
  • it should be useful in other Rust web projects, regardless of the web framework they're using
  • let's not force rustc to parse a 1.3MiB source file every time you change docs.rs; this seems like prime "separate translation unit" material

What's the long-term maintenance plan if we need to update?

I give everyone on the docs.rs team write access to the font-awesome-as-a-crate repository.

But, more generally, I don't actually expect the vendored fontawesome to be updated very often. I know it's happened a couple of times in the last few weeks, but that probably isn't normal. docs.rs used the same fontawesome version for years without upgrading and it was fine. The way it's now being tweaked twice in the same month is an unusual circumstance.

@jyn514
Copy link
Member

jyn514 commented Sep 5, 2020

All your points make sense, except that I'm a little unsure about having font_awesome_as_a_crate in a separate repository, since we're the only ones currently using it. Do you mind making it part of the docs.rs workspace and adding I and @pietroalbini as owners on crates.io? See #1000 for an example of what that would look like.

@notriddle
Copy link
Contributor Author

Sure, let's do that.

@notriddle notriddle force-pushed the fontawesome-sprites branch 5 times, most recently from ba01450 to b70cec5 Compare September 5, 2020 20:01
@notriddle
Copy link
Contributor Author

Did you get my invite on crates.io?

@jyn514
Copy link
Member

jyn514 commented Sep 5, 2020

Got it, thanks.

Don't have time to do a full review of this right now but the general idea looks right. Thanks for working on this!

@jyn514 jyn514 added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. S-waiting-on-author Status: This PR is incomplete or needs to address review comments and removed S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Sep 10, 2020
jyn514 added a commit to jyn514/docs.rs that referenced this pull request Sep 10, 2020
@jyn514 jyn514 removed the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Sep 10, 2020
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once #1041 unblocks switching vendor/fontawesome to crates/fontawesome

jyn514 added a commit to jyn514/docs.rs that referenced this pull request Sep 10, 2020
jyn514 added a commit that referenced this pull request Sep 14, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 14, 2020

Can you rebase this over master and change the new crate to be in crates/font-awesome-as-a-crate? Looks good to me after that.

@jyn514 jyn514 added S-waiting-on-author Status: This PR is incomplete or needs to address review comments and removed S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. labels Sep 14, 2020
Fixes rust-lang#790

The rationale for embedding the SVG files directly in the binary:

* avoid file I/O occurring in your Tera Filter, which would likely
  have complex knock-on effects when combined with `async`
* avoid complex error handling in your Tera Filter, which is the
  inevitable outcome of file I/O
* avoid having to carefully construct filesystem paths, with all
  the terrible possible outcomes and failure modes that come with
  that (using the infrastructure that the existing static file
  server uses is not an option, because it's not an HTTP request)
* I'm guessing it's faster to pull a string out of the binary's
  text section than it is to open a file for every request, though
  I have done no benchmarking to justify this wild speculation

The rationale for doing it in its own crate:

* we're not using any of docs.rs's file handling infrastructure
  anyway, so all the other stuff in its build.rs was just getting
  in the way while I coded up its codegen script
* it should be useful in other Rust web projects, regardless of
  the web framework they're using
* let's not force rustc to parse a 1.3MiB source file every time
  you change docs.rs; this seems like prime "separate translation
  unit" material
@notriddle
Copy link
Contributor Author

@rustbot modify labels to -S-waiting-on-author, +S-waiting-on-review

@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2020

Error: This repository is not enabled to use triagebot.
Add a triagebot.toml in the root of the master branch to enable it.

Please let @rust-lang/release know if you're having trouble with this bot.

@notriddle
Copy link
Contributor Author

shucks

@jyn514
Copy link
Member

jyn514 commented Sep 14, 2020

I'd take a PR adding triagebot ;)

@jyn514 jyn514 added S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed and removed S-waiting-on-author Status: This PR is incomplete or needs to address review comments labels Sep 14, 2020
@jyn514 jyn514 merged commit f2c5f66 into rust-lang:master Sep 14, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 14, 2020

Thanks for the PR!

@notriddle notriddle deleted the fontawesome-sprites branch September 14, 2020 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Web frontend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Font Awesome
5 participants