Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable MDBOOK_BOOK to overwrite book.toml #1207

Merged
merged 5 commits into from
May 8, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 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,22 @@ 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`
let prefix = &key; // "book" or "build"
let mut s = String::new();
for (k, v) in map {
s.clear();
s.push_str(prefix);
s.push('.');
s.push_str(k);
self.set(&s, v).expect("unreachable");
}
toyboot4e marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}

self.set(key, parsed_value).expect("unreachable");
}
}
Expand Down