From 04016f3be67aa61a463ce7ad39b5260626fbae76 Mon Sep 17 00:00:00 2001 From: Tetsuya Morimoto Date: Fri, 28 Apr 2023 12:46:49 +0900 Subject: [PATCH 1/3] Refactor the warning message related to copy_fonts so that a user simply configures it --- src/renderer/html_handlebars/hbs_renderer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index e170e2fc..479f5a78 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -294,7 +294,7 @@ impl HtmlHandlebars { if html_config.copy_fonts { warn!( "output.html.copy_fonts is deprecated.\n\ - Set copy_fonts=false and ensure the fonts you want are in \ + Set copy-fonts=false in book.toml and ensure the fonts you want are in \ the `theme/fonts/` directory." ); } @@ -304,7 +304,7 @@ impl HtmlHandlebars { if !html_config.copy_fonts && theme.fonts_css.is_none() { warn!( "output.html.copy_fonts is deprecated.\n\ - This book appears to have copy_fonts=false without a fonts.css file.\n\ + This book appears to have copy-fonts=false in book.toml without a fonts.css file.\n\ Add an empty `theme/fonts/fonts.css` file to squelch this warning." ); } From 75a6d65e5a25c4394f5fd2404d559d2309057df9 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 13 May 2023 08:49:17 -0700 Subject: [PATCH 2/3] Don't warn on copy-fonts=true (the default) when fonts.css is overridden. --- src/renderer/html_handlebars/hbs_renderer.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 479f5a78..986b81c2 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -291,19 +291,12 @@ impl HtmlHandlebars { } if let Some(fonts_css) = &theme.fonts_css { if !fonts_css.is_empty() { - if html_config.copy_fonts { - warn!( - "output.html.copy_fonts is deprecated.\n\ - Set copy-fonts=false in book.toml and ensure the fonts you want are in \ - the `theme/fonts/` directory." - ); - } write_file(destination, "fonts/fonts.css", &fonts_css)?; } } if !html_config.copy_fonts && theme.fonts_css.is_none() { warn!( - "output.html.copy_fonts is deprecated.\n\ + "output.html.copy-fonts is deprecated.\n\ This book appears to have copy-fonts=false in book.toml without a fonts.css file.\n\ Add an empty `theme/fonts/fonts.css` file to squelch this warning." ); From 01047846a9df2c517c4c76276b2425bca11312c5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 13 May 2023 08:59:28 -0700 Subject: [PATCH 3/3] Don't copy the stock fonts if the user has overridden fonts.css. This wasn't behaving as I was really intending. --- src/renderer/html_handlebars/hbs_renderer.rs | 3 ++- tests/rendered_output.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 986b81c2..a7c99225 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -275,7 +275,8 @@ impl HtmlHandlebars { "FontAwesome/fonts/FontAwesome.ttf", theme::FONT_AWESOME_TTF, )?; - if html_config.copy_fonts { + // Don't copy the stock fonts if the user has specified their own fonts to use. + if html_config.copy_fonts && theme.fonts_css.is_none() { write_file(destination, "fonts/fonts.css", theme::fonts::CSS)?; for (file_name, contents) in theme::fonts::LICENSES.iter() { write_file(destination, file_name, contents)?; diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index a279c4f8..12999b44 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -891,8 +891,8 @@ fn custom_fonts() { assert_eq!(actual_files(&p.join("book/fonts")), &builtin_fonts); assert!(has_fonts_css(p)); - // Mixed with copy_fonts=true - // This should generate a deprecation warning. + // Mixed with copy-fonts=true + // Should ignore the copy-fonts setting since the user has provided their own fonts.css. let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap(); let p = temp.path(); MDBook::init(p).build().unwrap(); @@ -900,10 +900,10 @@ fn custom_fonts() { write_file(&p.join("theme/fonts"), "myfont.woff", b"").unwrap(); MDBook::load(p).unwrap().build().unwrap(); assert!(has_fonts_css(p)); - let mut expected = Vec::from(builtin_fonts); - expected.push("myfont.woff"); - expected.sort(); - assert_eq!(actual_files(&p.join("book/fonts")), expected.as_slice()); + assert_eq!( + actual_files(&p.join("book/fonts")), + ["fonts.css", "myfont.woff"] + ); // copy-fonts=false, no theme // This should generate a deprecation warning.