Merge pull request #1207 from toyboot4e/fix-mdbook_book

Enable `MDBOOK_BOOK`  to overwrite `book.toml`
This commit is contained in:
Eric Huss 2020-05-08 06:51:21 -07:00 committed by GitHub
commit 07dfc4b89a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -124,7 +124,7 @@ impl Config {
/// > when building the book with something like /// > when building the book with something like
/// > /// >
/// > ```text /// > ```text
/// > $ export MDBOOK_BOOK="{'title': 'My Awesome Book', authors: ['Michael-F-Bryan']}" /// > $ export MDBOOK_BOOK='{"title": "My Awesome Book", "authors": ["Michael-F-Bryan"]}'
/// > $ mdbook build /// > $ mdbook build
/// > ``` /// > ```
/// ///
@ -142,6 +142,17 @@ impl Config {
let parsed_value = serde_json::from_str(&value) let parsed_value = serde_json::from_str(&value)
.unwrap_or_else(|_| serde_json::Value::String(value.to_string())); .unwrap_or_else(|_| serde_json::Value::String(value.to_string()));
if key == "book" || key == "build" {
if let serde_json::Value::Object(ref map) = parsed_value {
// To `set` each `key`, we wrap them as `prefix.key`
for (k, v) in map {
let full_key = format!("{}.{}", key, k);
self.set(&full_key, v).expect("unreachable");
}
return;
}
}
self.set(key, parsed_value).expect("unreachable"); self.set(key, parsed_value).expect("unreachable");
} }
} }