Skip to content

Commit eda77b8

Browse files
committed
Remove legacy config support
This removes the old legacy config that allowed certain things at the top level. The legacy switch was added in #457 Closes #2653
1 parent 8befcc7 commit eda77b8

File tree

2 files changed

+0
-146
lines changed

2 files changed

+0
-146
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -226,39 +226,6 @@ impl Config {
226226

227227
Ok(())
228228
}
229-
230-
fn from_legacy(mut table: Value) -> Config {
231-
let mut cfg = Config::default();
232-
233-
// we use a macro here instead of a normal loop because the $out
234-
// variable can be different types. This way we can make type inference
235-
// figure out what try_into() deserializes to.
236-
macro_rules! get_and_insert {
237-
($table:expr, $key:expr => $out:expr) => {
238-
let got = $table
239-
.as_table_mut()
240-
.and_then(|t| t.remove($key))
241-
.and_then(|v| v.try_into().ok());
242-
if let Some(value) = got {
243-
$out = value;
244-
}
245-
};
246-
}
247-
248-
get_and_insert!(table, "title" => cfg.book.title);
249-
get_and_insert!(table, "authors" => cfg.book.authors);
250-
get_and_insert!(table, "source" => cfg.book.src);
251-
get_and_insert!(table, "description" => cfg.book.description);
252-
253-
if let Some(dest) = table.delete("output.html.destination") {
254-
if let Ok(destination) = dest.try_into() {
255-
cfg.build.build_dir = destination;
256-
}
257-
}
258-
259-
cfg.rest = table;
260-
cfg
261-
}
262229
}
263230

264231
impl Default for Config {
@@ -276,18 +243,6 @@ impl<'de> serde::Deserialize<'de> for Config {
276243
fn deserialize<D: Deserializer<'de>>(de: D) -> std::result::Result<Self, D::Error> {
277244
let raw = Value::deserialize(de)?;
278245

279-
if is_legacy_format(&raw) {
280-
warn!("It looks like you are using the legacy book.toml format.");
281-
warn!("We'll parse it for now, but you should probably convert to the new format.");
282-
warn!("See the mdbook documentation for more details, although as a rule of thumb");
283-
warn!("just move all top level configuration entries like `title`, `author` and");
284-
warn!("`description` under a table called `[book]`, move the `destination` entry");
285-
warn!("from `[output.html]`, renamed to `build-dir`, under a table called");
286-
warn!("`[build]`, and it should all work.");
287-
warn!("Documentation: https://rust-lang.github.io/mdBook/format/config.html");
288-
return Ok(Config::from_legacy(raw));
289-
}
290-
291246
warn_on_invalid_fields(&raw);
292247

293248
use serde::de::Error;
@@ -365,24 +320,6 @@ fn warn_on_invalid_fields(table: &Value) {
365320
}
366321
}
367322

368-
fn is_legacy_format(table: &Value) -> bool {
369-
let legacy_items = [
370-
"title",
371-
"authors",
372-
"source",
373-
"description",
374-
"output.html.destination",
375-
];
376-
377-
for item in &legacy_items {
378-
if table.read(item).is_some() {
379-
return true;
380-
}
381-
}
382-
383-
false
384-
}
385-
386323
/// Configuration options which are specific to the book and required for
387324
/// loading it from disk.
388325
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -1006,57 +943,6 @@ mod tests {
1006943
assert_eq!(got_baz, baz_should_be);
1007944
}
1008945

1009-
/// The config file format has slightly changed (metadata stuff is now under
1010-
/// the `book` table instead of being at the top level) so we're adding a
1011-
/// **temporary** compatibility check. You should be able to still load the
1012-
/// old format, emitting a warning.
1013-
#[test]
1014-
fn can_still_load_the_previous_format() {
1015-
let src = r#"
1016-
title = "mdBook Documentation"
1017-
description = "Create book from markdown files. Like Gitbook but implemented in Rust"
1018-
authors = ["Mathieu David"]
1019-
source = "./source"
1020-
1021-
[output.html]
1022-
destination = "my-book" # the output files will be generated in `root/my-book` instead of `root/book`
1023-
theme = "my-theme"
1024-
smart-punctuation = true
1025-
additional-css = ["custom.css", "custom2.css"]
1026-
additional-js = ["custom.js"]
1027-
"#;
1028-
1029-
let book_should_be = BookConfig {
1030-
title: Some(String::from("mdBook Documentation")),
1031-
description: Some(String::from(
1032-
"Create book from markdown files. Like Gitbook but implemented in Rust",
1033-
)),
1034-
authors: vec![String::from("Mathieu David")],
1035-
src: PathBuf::from("./source"),
1036-
..Default::default()
1037-
};
1038-
1039-
let build_should_be = BuildConfig {
1040-
build_dir: PathBuf::from("my-book"),
1041-
create_missing: true,
1042-
use_default_preprocessors: true,
1043-
extra_watch_dirs: Vec::new(),
1044-
};
1045-
1046-
let html_should_be = HtmlConfig {
1047-
theme: Some(PathBuf::from("my-theme")),
1048-
smart_punctuation: true,
1049-
additional_css: vec![PathBuf::from("custom.css"), PathBuf::from("custom2.css")],
1050-
additional_js: vec![PathBuf::from("custom.js")],
1051-
..Default::default()
1052-
};
1053-
1054-
let got = Config::from_str(src).unwrap();
1055-
assert_eq!(got.book, book_should_be);
1056-
assert_eq!(got.build, build_should_be);
1057-
assert_eq!(got.html_config().unwrap(), html_should_be);
1058-
}
1059-
1060946
#[test]
1061947
fn set_a_config_item() {
1062948
let mut cfg = Config::default();

crates/mdbook-core/src/utils/toml_ext.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ pub(crate) trait TomlExt {
88
fn read(&self, key: &str) -> Option<&Value>;
99
/// Insert with a dotted key.
1010
fn insert(&mut self, key: &str, value: Value);
11-
/// Delete a dotted key value.
12-
fn delete(&mut self, key: &str) -> Option<Value>;
1311
}
1412

1513
impl TomlExt for Value {
@@ -37,16 +35,6 @@ impl TomlExt for Value {
3735
table.insert(key.to_string(), value);
3836
}
3937
}
40-
41-
fn delete(&mut self, key: &str) -> Option<Value> {
42-
if let Some((head, tail)) = split(key) {
43-
self.get_mut(head)?.delete(tail)
44-
} else if let Some(table) = self.as_table_mut() {
45-
table.remove(key)
46-
} else {
47-
None
48-
}
49-
}
5038
}
5139

5240
fn split(key: &str) -> Option<(&str, &str)> {
@@ -103,24 +91,4 @@ mod tests {
10391
let inserted = value.read("first.second").unwrap();
10492
assert_eq!(inserted, &item);
10593
}
106-
107-
#[test]
108-
fn delete_a_top_level_item() {
109-
let src = "top = true";
110-
let mut value: Value = toml::from_str(src).unwrap();
111-
112-
let got = value.delete("top").unwrap();
113-
114-
assert_eq!(got, Value::Boolean(true));
115-
}
116-
117-
#[test]
118-
fn delete_a_nested_item() {
119-
let src = "[table]\n nested = true";
120-
let mut value: Value = toml::from_str(src).unwrap();
121-
122-
let got = value.delete("table.nested").unwrap();
123-
124-
assert_eq!(got, Value::Boolean(true));
125-
}
12694
}

0 commit comments

Comments
 (0)