Skip to content

Commit 7c87a81

Browse files
committed
Warn on invalid fields in the [book] section of book.toml
A step for #1595. We might need to revise this if de decide to remove the `multilingual` field as described in #2636
1 parent 4f698f8 commit 7c87a81

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/config.rs

+24
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ impl<'de> serde::Deserialize<'de> for Config {
313313
}
314314

315315
warn_on_invalid_fields(&raw);
316+
warn_on_invalid_fields_in_book_section(&raw);
316317

317318
use serde::de::Error;
318319
let mut table = match raw {
@@ -389,6 +390,29 @@ fn warn_on_invalid_fields(table: &Value) {
389390
}
390391
}
391392

393+
fn warn_on_invalid_fields_in_book_section(table: &Value) {
394+
let valid_items = [
395+
"title",
396+
"authors",
397+
"description",
398+
"src",
399+
"language",
400+
"text-direction",
401+
"multilingual",
402+
];
403+
if let Some(book) = table.get("book") {
404+
let table = book.as_table().expect("root.book must be a table");
405+
for item in table.keys() {
406+
if !valid_items.contains(&item.as_str()) {
407+
warn!(
408+
"Invalid field {:?} in the [book] section of book.toml",
409+
&item
410+
);
411+
}
412+
}
413+
}
414+
}
415+
392416
fn is_legacy_format(table: &Value) -> bool {
393417
let legacy_items = [
394418
"title",

0 commit comments

Comments
 (0)