Skip to content

Commit 4c948b4

Browse files
authored
Merge pull request #2790 from ehuss/remove-copy-fonts
Remove copy-fonts
2 parents 7e09491 + 3e5ec74 commit 4c948b4

File tree

18 files changed

+14
-89
lines changed

18 files changed

+14
-89
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub enum RustEdition {
411411
}
412412

413413
/// Configuration for the HTML renderer.
414-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
414+
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
415415
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
416416
#[non_exhaustive]
417417
pub struct HtmlConfig {
@@ -426,8 +426,6 @@ pub struct HtmlConfig {
426426
pub smart_punctuation: bool,
427427
/// Should mathjax be enabled?
428428
pub mathjax_support: bool,
429-
/// Whether to fonts.css and respective font files to the output directory.
430-
pub copy_fonts: bool,
431429
/// Additional CSS stylesheets to include in the rendered page's `<head>`.
432430
pub additional_css: Vec<PathBuf>,
433431
/// Additional JS scripts to include at the bottom of the rendered page's
@@ -481,36 +479,6 @@ pub struct HtmlConfig {
481479
pub hash_files: bool,
482480
}
483481

484-
impl Default for HtmlConfig {
485-
fn default() -> HtmlConfig {
486-
HtmlConfig {
487-
theme: None,
488-
default_theme: None,
489-
preferred_dark_theme: None,
490-
smart_punctuation: false,
491-
mathjax_support: false,
492-
copy_fonts: true,
493-
additional_css: Vec::new(),
494-
additional_js: Vec::new(),
495-
fold: Fold::default(),
496-
playground: Playground::default(),
497-
code: Code::default(),
498-
print: Print::default(),
499-
no_section_label: false,
500-
search: None,
501-
git_repository_url: None,
502-
git_repository_icon: None,
503-
edit_url_template: None,
504-
input_404: None,
505-
site_url: None,
506-
cname: None,
507-
live_reload_endpoint: None,
508-
redirect: HashMap::new(),
509-
hash_files: false,
510-
}
511-
}
512-
}
513-
514482
impl HtmlConfig {
515483
/// Returns the directory of theme from the provided root directory. If the
516484
/// directory is not present it will append the default directory of "theme"

crates/mdbook-html/front-end/templates/index.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434

3535
<!-- Fonts -->
3636
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
37-
{{#if copy_fonts}}
3837
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
39-
{{/if}}
4038

4139
<!-- Highlight.js Stylesheets -->
4240
<link rel="stylesheet" id="highlight-css" href="{{ resource "highlight.css" }}">

crates/mdbook-html/front-end/templates/toc.html.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
{{/if}}
3030
<!-- Fonts -->
3131
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
32-
{{#if copy_fonts}}
3332
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
34-
{{/if}}
3533
<!-- Custom theme stylesheets -->
3634
{{#each additional_css}}
3735
<link rel="stylesheet" href="{{ resource this }}">

crates/mdbook-html/src/html_handlebars/hbs_renderer.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,6 @@ fn make_data(
557557
data.insert("mathjax_support".to_owned(), json!(true));
558558
}
559559

560-
// This `matches!` checks for a non-empty file.
561-
if html_config.copy_fonts || matches!(theme.fonts_css.as_deref(), Some([_, ..])) {
562-
data.insert("copy_fonts".to_owned(), json!(true));
563-
}
564-
565560
// Add check to see if there is an additional style
566561
if !html_config.additional_css.is_empty() {
567562
let mut css = Vec::new();

crates/mdbook-html/src/html_handlebars/static_files.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::helpers::resources::ResourceHelper;
44
use crate::theme::{self, Theme, playground_editor};
55
use anyhow::{Context, Result};
6-
use log::{debug, warn};
6+
use log::debug;
77
use mdbook_core::config::HtmlConfig;
88
use mdbook_core::utils;
99
use std::borrow::Cow;
@@ -84,7 +84,7 @@ impl StaticFiles {
8484
theme::FONT_AWESOME_WOFF2,
8585
);
8686
this.add_builtin("FontAwesome/fonts/FontAwesome.ttf", theme::FONT_AWESOME_TTF);
87-
if html_config.copy_fonts && theme.fonts_css.is_none() {
87+
if theme.fonts_css.is_none() {
8888
this.add_builtin("fonts/fonts.css", theme::fonts::CSS);
8989
for (file_name, contents) in theme::fonts::LICENSES.iter() {
9090
this.add_builtin(file_name, contents);
@@ -101,13 +101,6 @@ impl StaticFiles {
101101
this.add_builtin("fonts/fonts.css", fonts_css);
102102
}
103103
}
104-
if !html_config.copy_fonts && theme.fonts_css.is_none() {
105-
warn!(
106-
"output.html.copy-fonts is deprecated.\n\
107-
This book appears to have copy-fonts=false in book.toml without a fonts.css file.\n\
108-
Add an empty `theme/fonts/fonts.css` file to squelch this warning."
109-
);
110-
}
111104

112105
let playground_config = &html_config.playground;
113106

guide/src/format/configuration/renderers.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ default-theme = "light"
9999
preferred-dark-theme = "navy"
100100
smart-punctuation = true
101101
mathjax-support = false
102-
copy-fonts = true
103102
additional-css = ["custom.css", "custom2.css"]
104103
additional-js = ["custom.js"]
105104
no-section-label = false
@@ -127,10 +126,6 @@ The following configuration options are available:
127126
Defaults to `false`.
128127
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
129128
`false`.
130-
- **copy-fonts:** (**Deprecated**) If `true` (the default), mdBook uses its built-in fonts which are copied to the output directory.
131-
If `false`, the built-in fonts will not be used.
132-
This option is deprecated. If you want to define your own custom fonts,
133-
create a `theme/fonts/fonts.css` file and store the fonts in the `theme/fonts/` directory.
134129
- **additional-css:** If you need to slightly change the appearance of your book
135130
without overwriting the whole style, you can specify a set of stylesheets that
136131
will be loaded after the default ones where you can surgically change the

tests/testsuite/theme.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,45 +139,26 @@ book/fonts/myfont.woff
139139
);
140140
}
141141

142-
// copy-fonts=false, no theme, deprecated
142+
// Empty fonts.css should not copy the default fonts.
143143
#[test]
144-
fn copy_fonts_false_no_theme() {
145-
BookTest::from_dir("theme/copy_fonts_false_no_theme")
144+
fn empty_fonts_css() {
145+
BookTest::from_dir("theme/empty_fonts_css")
146146
.run("build", |cmd| {
147147
cmd.expect_stderr(str![[r#"
148148
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
149149
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend
150-
[TIMESTAMP] [WARN] (mdbook_html::html_handlebars::static_files): output.html.copy-fonts is deprecated.
151-
This book appears to have copy-fonts=false in book.toml without a fonts.css file.
152-
Add an empty `theme/fonts/fonts.css` file to squelch this warning.
153150
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
154151
155152
"#]]);
156153
})
157-
.check_file_doesnt_contain("book/index.html", "fonts.css")
158-
.check_file_list("book/fonts", str![[""]]);
159-
}
160-
161-
// copy-fonts=false, empty fonts.css
162-
#[test]
163-
fn copy_fonts_false_with_empty_fonts_css() {
164-
BookTest::from_dir("theme/copy_fonts_false_with_empty_fonts_css")
165-
.run("build", |cmd| {
166-
cmd.expect_stderr(str![[r#"
167-
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
168-
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend
169-
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
170-
171-
"#]]);
172-
})
173-
.check_file_doesnt_contain("book/index.html", "fonts.css")
154+
.check_file_contains("book/index.html", "fonts.css")
174155
.check_file_list("book/fonts", str![[""]]);
175156
}
176157

177-
// copy-fonts=false, fonts.css has contents
158+
// Custom fonts.css file shouldn't copy default fonts.
178159
#[test]
179-
fn copy_fonts_false_with_fonts_css() {
180-
BookTest::from_dir("theme/copy_fonts_false_with_fonts_css")
160+
fn custom_fonts_css() {
161+
BookTest::from_dir("theme/custom_fonts_css")
181162
.run("build", |cmd| {
182163
cmd.expect_stderr(str![[r#"
183164
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started

tests/testsuite/theme/copy_fonts_false_no_theme/book.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/testsuite/theme/copy_fonts_false_with_empty_fonts_css/book.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/testsuite/theme/copy_fonts_false_with_fonts_css/book.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)