Skip to content

Commit

Permalink
WIP: load oranda.toml as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra authored and liv committed Dec 13, 2023
1 parent 3e2a347 commit c9b59ea
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 49 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 0 additions & 38 deletions oranda.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
29 changes: 29 additions & 0 deletions oranda.toml
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 20 additions & 10 deletions src/config/oranda_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,27 @@ pub struct OrandaLayer {

impl OrandaLayer {
pub fn load(config_path: &Utf8PathBuf) -> Result<Option<OrandaLayer>> {
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)
}
}

0 comments on commit c9b59ea

Please sign in to comment.