-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge extra config of site and theme.
- Loading branch information
Showing
3 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ mod sass; | |
mod site; | ||
mod template; | ||
mod theme; | ||
mod utils; | ||
|
||
use site::Site; | ||
use theme::Theme; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// * Code taken from [Zola](https://www.getzola.org/) and adapted. | ||
// * Zola's MIT license applies. See: https://github.com/getzola/zola/blob/master/LICENSE | ||
|
||
use toml::Value as TomlValue; | ||
|
||
#[derive(Debug)] | ||
pub struct MergeError; | ||
|
||
// https://github.com/getzola/zola/blob/master/components/config/src/config/mod.rs | ||
|
||
pub fn merge(into: &mut TomlValue, from: &TomlValue) -> Result<(), MergeError> { | ||
match (from.is_table(), into.is_table()) { | ||
(false, false) => { | ||
// These are not tables so we have nothing to merge | ||
Ok(()) | ||
} | ||
(true, true) => { | ||
// Recursively merge these tables | ||
let into_table = into.as_table_mut().unwrap(); | ||
for (key, val) in from.as_table().unwrap() { | ||
if !into_table.contains_key(key) { | ||
// An entry was missing in the first table, insert it | ||
into_table.insert(key.to_string(), val.clone()); | ||
continue; | ||
} | ||
// Two entries to compare, recurse | ||
merge(into_table.get_mut(key).unwrap(), val)?; | ||
} | ||
Ok(()) | ||
} | ||
_ => Err(MergeError), | ||
} | ||
} |