From c9b59ea5d92fa0dfc163152c9ffc9c090ed8c256 Mon Sep 17 00:00:00 2001 From: Aria Beingessner Date: Tue, 5 Sep 2023 10:09:55 -0400 Subject: [PATCH] WIP: load oranda.toml as well --- Cargo.lock | 1 + Cargo.toml | 2 +- oranda.json | 38 ------------------------------------- oranda.toml | 29 ++++++++++++++++++++++++++++ src/config/oranda_config.rs | 30 +++++++++++++++++++---------- 5 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 oranda.toml diff --git a/Cargo.lock b/Cargo.lock index f2e2e2c3..aa937a5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,6 +207,7 @@ dependencies = [ "serde", "serde_json", "thiserror", + "toml", "toml_edit", "url", ] diff --git a/Cargo.toml b/Cargo.toml index 8ee81da8..76065b0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ members = ["generate-css"] [dependencies] ammonia = "3" -axoasset = { version = "0.4.0", features = ["json-serde", "toml-edit"] } +axoasset = { version = "0.4.0", features = ["json-serde", "toml-serde", "toml-edit"] } axocli = "0.1.0" axoproject = { version = "0.4.6", default-features = false, features = ["cargo-projects", "npm-projects"] } axum = "0.6.18" diff --git a/oranda.json b/oranda.json index fac5dbbb..e69de29b 100644 --- a/oranda.json +++ b/oranda.json @@ -1,38 +0,0 @@ -{ - "build": { - "path_prefix": "oranda" - }, - "styles": { - "theme": "axodark", - "favicon": "https://www.axo.dev/favicon.ico" - }, - "marketing": { - "social": { - "image": "https://www.axo.dev/meta_small.jpeg", - "image_alt": "axo", - "twitter_account": "@axodotdev" - }, - "analytics": { - "plausible": { - "domain": "opensource.axo.dev" - } - } - }, - "components": { - "changelog": true, - "artifacts": { - "package_managers": { - "preferred": { - "npm": "npm install @axodotdev/oranda --save-dev" - }, - "additional": { - "cargo": "cargo install oranda --locked --profile=dist", - "npx": "npx @axodotdev/oranda", - "binstall": "cargo binstall oranda", - "nix-env": "nix-env -i oranda", - "nix flake": "nix profile install github:axodotdev/oranda" - } - } - } - } -} diff --git a/oranda.toml b/oranda.toml new file mode 100644 index 00000000..000a4233 --- /dev/null +++ b/oranda.toml @@ -0,0 +1,29 @@ +[build] +path_prefix = "oranda" + +[styles] +theme = "axodark" +favicon = "https://www.axo.dev/favicon.ico" + +[marketing] +analytics = { plausible = { domain = "opensource.axo.dev" }} + +[marketing.social] +image = "https://www.axo.dev/meta_small.jpeg" +image_alt = "axo" +twitter_account = "@axodotdev" + + + +[components] +changelog = true + +[components.artifacts.package_managers.preferred] +npm = "npm install @axodotdev/oranda --save-dev" +cargo = "cargo install oranda --locked --profile=dist" + +[components.artifacts.package_managers.additional] +npx = "npx @axodotdev/oranda" +binstall = "cargo binstall oranda" +nix-env = "nix-env -i oranda" +"nix flake" = "nix profile install github:axodotdev/oranda" diff --git a/src/config/oranda_config.rs b/src/config/oranda_config.rs index 6eee43c3..be70aa10 100644 --- a/src/config/oranda_config.rs +++ b/src/config/oranda_config.rs @@ -35,17 +35,27 @@ pub struct OrandaLayer { impl OrandaLayer { pub fn load(config_path: &Utf8PathBuf) -> Result> { - let config_result = SourceFile::load_local(config_path.as_path()); - - match config_result { - Ok(config) => { - let data: OrandaLayer = config.deserialize_json()?; - Ok(Some(data)) - } - Err(_) => { - tracing::debug!("No config found, using default values"); - Ok(None) + let mut config_path = config_path.to_owned(); + if config_path.extension() == Some("json") { + if config_path.exists() { + let config = SourceFile::load_local(config_path.as_path())?; + return Ok(Some(config.deserialize_json()?)); + } else { + // Temporary hack + config_path.set_extension("toml"); } } + if !config_path.exists() { + tracing::debug!("No config found, using default values"); + return Ok(None); + } + if config_path.extension() == Some("toml") { + tracing::warn!("!!!Using toml config!!!!"); + let config = SourceFile::load_local(config_path.as_path())?; + return Ok(Some(config.deserialize_toml()?)); + } + + tracing::debug!("No config found, using default values"); + Ok(None) } }