Skip to content

Use embedded SVG instead of fonts for icons, font-awesome 6.2 #1330

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
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ clap = { version = "4.5.41", features = ["cargo", "wrap_help"] }
clap_complete = "4.5.55"
elasticlunr-rs = "3.0.2"
env_logger = "0.11.8"
font-awesome-as-a-crate = "0.3.0"
futures-util = "0.3.31"
handlebars = "6.3.2"
hex = "0.4.3"
Expand Down
1 change: 1 addition & 0 deletions crates/mdbook-html/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rust-version.workspace = true
ammonia = { workspace = true, optional = true }
anyhow.workspace = true
elasticlunr-rs = { workspace = true, optional = true }
font-awesome-as-a-crate.workspace = true
handlebars.workspace = true
hex.workspace = true
log.workspace = true
Expand Down
31 changes: 21 additions & 10 deletions crates/mdbook-html/front-end/css/chrome.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ html.sidebar-visible #menu-bar {
#menu-bar.bordered {
border-block-end-color: var(--table-border-color);
}
#menu-bar i, #menu-bar .icon-button {
#menu-bar .fa-svg, #menu-bar .icon-button {
position: relative;
padding: 0 8px;
z-index: 10;
Expand All @@ -65,7 +65,7 @@ html.sidebar-visible #menu-bar {
transition: color 0.5s;
}
@media only screen and (max-width: 420px) {
#menu-bar i, #menu-bar .icon-button {
#menu-bar .fa-svg, #menu-bar .icon-button {
padding: 0 5px;
}
}
Expand All @@ -76,7 +76,7 @@ html.sidebar-visible #menu-bar {
padding: 0;
color: inherit;
}
.icon-button i {
.icon-button .fa-svg {
margin: 0;
}

Expand Down Expand Up @@ -118,14 +118,14 @@ html:not(.js) .left-buttons button {
.mobile-nav-chapters,
.mobile-nav-chapters:visited,
.menu-bar .icon-button,
.menu-bar a i {
.menu-bar a .fa-svg {
color: var(--icons);
}

.menu-bar i:hover,
.menu-bar .fa-svg:hover,
.menu-bar .icon-button:hover,
.nav-chapters:hover,
.mobile-nav-chapters i:hover {
.mobile-nav-chapters .fa-svg:hover {
color: var(--icons-hover);
}

Expand Down Expand Up @@ -240,13 +240,10 @@ pre > .buttons :hover {
border-color: var(--icons-hover);
background-color: var(--theme-hover);
}
pre > .buttons i {
margin-inline-start: 8px;
}
pre > .buttons button {
cursor: inherit;
margin: 0px 5px;
padding: 4px 4px 3px 5px;
padding: 2px 3px 0px 4px;
font-size: 23px;

border-style: solid;
Expand Down Expand Up @@ -365,6 +362,20 @@ mark.fade-out {
background-color: var(--bg);
}

#fa-spin {
animation: rotating 2s linear infinite;
display: inline-block;
}

@keyframes rotating {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

#searchbar {
width: 100%;
margin-block-start: var(--searchbar-margin-block-start);
Expand Down
4 changes: 0 additions & 4 deletions crates/mdbook-html/front-end/css/font-awesome.min.css

This file was deleted.

7 changes: 7 additions & 0 deletions crates/mdbook-html/front-end/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,10 @@ sup {
.result-no-output {
font-style: italic;
}

.fa-svg svg {
width: 1em;
height: 1em;
fill: currentColor;
margin-bottom: -0.1em;
}
Binary file removed crates/mdbook-html/front-end/fonts/FontAwesome.otf
Binary file not shown.
Binary file not shown.
2,671 changes: 0 additions & 2,671 deletions crates/mdbook-html/front-end/fonts/fontawesome-webfont.svg

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 17 additions & 14 deletions crates/mdbook-html/front-end/js/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function playground_text(playground, hidden = true) {

if (all_available) {
play_button.classList.remove('hidden');
play_button.hidden = false;
} else {
play_button.classList.add('hidden');
}
Expand Down Expand Up @@ -207,26 +208,25 @@ function playground_text(playground, hidden = true) {

const buttons = document.createElement('div');
buttons.className = 'buttons';
buttons.innerHTML = '<button class="fa fa-eye" title="Show hidden lines" \
buttons.innerHTML = '<button title="Show hidden lines" \
aria-label="Show hidden lines"></button>';
buttons.firstChild.innerHTML = document.getElementById('fa-eye').innerHTML;

// add expand button
const pre_block = block.parentNode;
pre_block.insertBefore(buttons, pre_block.firstChild);

pre_block.querySelector('.buttons').addEventListener('click', function(e) {
if (e.target.classList.contains('fa-eye')) {
e.target.classList.remove('fa-eye');
e.target.classList.add('fa-eye-slash');
e.target.title = 'Hide lines';
e.target.setAttribute('aria-label', e.target.title);
buttons.firstChild.addEventListener('click', function(e) {
if (this.title === 'Show hidden lines') {
this.innerHTML = document.getElementById('fa-eye-slash').innerHTML;
this.title = 'Hide lines';
this.setAttribute('aria-label', e.target.title);

block.classList.remove('hide-boring');
} else if (e.target.classList.contains('fa-eye-slash')) {
e.target.classList.remove('fa-eye-slash');
e.target.classList.add('fa-eye');
e.target.title = 'Show hidden lines';
e.target.setAttribute('aria-label', e.target.title);
} else if (this.title === 'Hide lines') {
this.innerHTML = document.getElementById('fa-eye').innerHTML;
this.title = 'Show hidden lines';
this.setAttribute('aria-label', e.target.title);

block.classList.add('hide-boring');
}
Expand Down Expand Up @@ -266,10 +266,11 @@ aria-label="Show hidden lines"></button>';
}

const runCodeButton = document.createElement('button');
runCodeButton.className = 'fa fa-play play-button';
runCodeButton.className = 'play-button';
runCodeButton.hidden = true;
runCodeButton.title = 'Run this code';
runCodeButton.setAttribute('aria-label', runCodeButton.title);
runCodeButton.innerHTML = document.getElementById('fa-play').innerHTML;

buttons.insertBefore(runCodeButton, buttons.firstChild);
runCodeButton.addEventListener('click', () => {
Expand All @@ -289,9 +290,11 @@ aria-label="Show hidden lines"></button>';
const code_block = pre_block.querySelector('code');
if (window.ace && code_block.classList.contains('editable')) {
const undoChangesButton = document.createElement('button');
undoChangesButton.className = 'fa fa-history reset-button';
undoChangesButton.className = 'reset-button';
undoChangesButton.title = 'Undo changes';
undoChangesButton.setAttribute('aria-label', undoChangesButton.title);
undoChangesButton.innerHTML +=
document.getElementById('fa-clock-rotate-left').innerHTML;

buttons.insertBefore(undoChangesButton, buttons.firstChild);

Expand Down
38 changes: 21 additions & 17 deletions crates/mdbook-html/front-end/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
{{/if}}

<!-- Fonts -->
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">

<!-- Highlight.js Stylesheets -->
Expand Down Expand Up @@ -145,10 +144,10 @@
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
{{fa "solid" "bars"}}
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
{{fa "solid" "paintbrush"}}
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
Expand All @@ -160,7 +159,7 @@
</ul>
{{#if search_enabled}}
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
{{fa "solid" "magnifying-glass"}}
</button>
{{/if}}
</div>
Expand All @@ -170,17 +169,17 @@
<div class="right-buttons">
{{#if print_enable}}
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
{{fa "solid" "print" "print-button"}}
</a>
{{/if}}
{{#if git_repository_url}}
<a href="{{git_repository_url}}" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
{{fa git_repository_icon_class git_repository_icon}}
</a>
{{/if}}
{{#if git_repository_edit_url}}
<a href="{{git_repository_edit_url}}" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
<i id="git-edit-button" class="fa fa-edit"></i>
{{fa "solid" "pencil" "git-edit-button"}}
</a>
{{/if}}

Expand All @@ -193,7 +192,7 @@
<div class="search-wrapper">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
<div class="spinner-wrapper">
<i class="fa fa-spinner fa-spin"></i>
{{fa "solid" "spinner" "fa-spin"}}
</div>
</div>
</form>
Expand Down Expand Up @@ -224,19 +223,18 @@
{{#if previous}}
<a rel="prev" href="{{ path_to_root }}{{previous.link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
{{#if (eq ../text_direction "rtl")}}
<i class="fa fa-angle-right"></i>
{{fa "solid" "angle-right"}}
{{else}}
<i class="fa fa-angle-left"></i>
{{fa "solid" "angle-left"}}
{{/if}}
</a>
{{/if}}

{{#if next}}
<a rel="next prefetch" href="{{ path_to_root }}{{next.link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
{{#if (eq ../text_direction "rtl")}}
<i class="fa fa-angle-left"></i>
{{fa "solid" "angle-left"}}
{{else}}
<i class="fa fa-angle-right"></i>
{{fa "solid" "angle-right"}}
{{/if}}
</a>
{{/if}}
Expand All @@ -250,26 +248,32 @@
{{#if previous}}
<a rel="prev" href="{{ path_to_root }}{{previous.link}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
{{#if (eq ../text_direction "rtl")}}
<i class="fa fa-angle-right"></i>
{{fa "solid" "angle-right"}}
{{else}}
<i class="fa fa-angle-left"></i>
{{fa "solid" "angle-left"}}
{{/if}}
</a>
{{/if}}

{{#if next}}
<a rel="next prefetch" href="{{ path_to_root }}{{next.link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
{{#if (eq text_direction "rtl")}}
<i class="fa fa-angle-left"></i>
{{fa "solid" "angle-left"}}
{{else}}
<i class="fa fa-angle-right"></i>
{{fa "solid" "angle-right"}}
{{/if}}
</a>
{{/if}}
</nav>

</div>

<template id=fa-eye>{{fa "solid" "eye"}}</template>
<template id=fa-eye-slash>{{fa "solid" "eye-slash"}}</template>
<template id=fa-copy>{{fa "regular" "copy"}}</template>
<template id=fa-play>{{fa "solid" "play"}}</template>
<template id=fa-clock-rotate-left>{{fa "solid" "clock-rotate-left"}}</template>

{{#if live_reload_endpoint}}
<!-- Livereload script (if served using the cli tool) -->
<script>
Expand Down
1 change: 0 additions & 1 deletion crates/mdbook-html/front-end/templates/toc.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<link rel="stylesheet" href="{{ resource "css/print.css" }}" media="print">
{{/if}}
<!-- Fonts -->
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
<!-- Custom theme stylesheets -->
{{#each additional_css}}
Expand Down
Loading
Loading