Skip to content

Use embedded Font Awesome SVG icons #2484

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

Closed
wants to merge 5 commits into from

Conversation

uncenter
Copy link

Incorporates the changes from #1330, brings up to date with repository and adds various fixes & improvements.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Nov 15, 2024
Copy link
Contributor

@notriddle notriddle left a comment

Choose a reason for hiding this comment

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

Not sure if it's a good idea to try to work around this, but existing books are going to be written to the old fontawesome version.

@uncenter
Copy link
Author

Would it be possible to get a review on this PR? I don't want it to lose momentum and have to deal with conflicts again down the road.

@ehuss ehuss added this to the 0.5 milestone Jan 23, 2025
fa::svg(type_, &icon).or_else(|_| fa::svg(fa::Type::Brands, &icon))
{
format!(
r#"<span{before}class="fa-svg{other_classes}"{after}>{svg}</span>"#,
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better instead of generating the SVG in the DOM directly to rely on CSS instead? It brings multiple advantages:

  1. Smaller DOM
  2. If the same SVG is used more than once, it's not duplicated

Copy link
Contributor

@notriddle notriddle Feb 14, 2025

Choose a reason for hiding this comment

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

I don't want to build a giant stylesheet with every icon in it unless we have to. That file would be immense, and most of it wouldn't get used. But mdBook exposes an API that lets the user include any icon they want, so we'd have to?

Besides, fontawesome SVGs almost all have a single <path> in them. The DOM is tiny.

Copy link
Member

Choose a reason for hiding this comment

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

FontAwesome is a font. Meaning that as long as we have the font, we have easily use their icons without needing to declare them ourselves.

Copy link
Author

Choose a reason for hiding this comment

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

FontAwesome is a font. Meaning that as long as we have the font, we have easily use their icons without needing to declare them ourselves.

But then you must include the entirety of the font (which is quite large iirc), unless you want to deal with subsetting? And then that is a whole other ordeal.

@GuillaumeGomez
Copy link
Member

Overall I think it's a very good idea, but unless I'm wrong, you're inlining the SVGs directly into the HTML, and I don't think this is the right approach. If you use the CSS and font provided by font awesome, then no need for this.

@uncenter
Copy link
Author

uncenter commented Apr 9, 2025

Overall I think it's a very good idea, but unless I'm wrong, you're inlining the SVGs directly into the HTML, and I don't think this is the right approach. If you use the CSS and font provided by font awesome, then no need for this.

CSS is a valid way to go about the inclusion of icons, and could be done in the future, but it should not be a blocker for this pull request to land. Much of the point of this pull request is to avoid the 77kb of fonts that must be loaded from FontAwesome, and to avoid the other downsides as mentioned in #1330 (comment).

@GuillaumeGomez
Copy link
Member

Then please inline the SVG into the CSS to prevent duplication in HTML.

@uncenter uncenter closed this Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: waiting on a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants