Skip to content

Commit

Permalink
Merge pull request #1207 from toyboot4e/fix-mdbook_book
Browse files Browse the repository at this point in the history
Enable `MDBOOK_BOOK`  to overwrite `book.toml`
  • Loading branch information
ehuss authored May 8, 2020
2 parents 17210b0 + 282e551 commit 07dfc4b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Config {
/// > when building the book with something like
/// >
/// > ```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
/// > ```
///
Expand All @@ -142,6 +142,17 @@ impl Config {
let parsed_value = serde_json::from_str(&value)
.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");
}
}
Expand Down

0 comments on commit 07dfc4b

Please sign in to comment.