Skip to content

Commit 48bac50

Browse files
committed
WIP: load oranda.toml as well
1 parent e64fc31 commit 48bac50

5 files changed

Lines changed: 92 additions & 90 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ members = ["generate-css"]
1616

1717
[dependencies]
1818
ammonia = "3"
19-
axoasset = { version = "0.4.0", features = ["json-serde", "toml-edit"] }
19+
axoasset = { version = "0.4.0", features = ["json-serde", "toml-serde", "toml-edit"] }
2020
axocli = "0.1.0"
2121
axoproject = { version = "0.4.6", default-features = false, features = ["cargo-projects", "npm-projects"] }
2222
axum = "0.6.18"

oranda.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

oranda.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[build]
2+
path_prefix = "oranda"
3+
4+
[styles]
5+
theme = "axodark"
6+
favicon = "https://www.axo.dev/favicon.ico"
7+
8+
[marketing]
9+
analytics = { plausible = { domain = "opensource.axo.dev" }}
10+
11+
[marketing.social]
12+
image = "https://www.axo.dev/meta_small.jpeg"
13+
image_alt = "axo"
14+
twitter_account = "@axodotdev"
15+
16+
17+
18+
[components]
19+
changelog = true
20+
21+
[components.artifacts.package_managers.preferred]
22+
npm = "npm install @axodotdev/oranda --save-dev"
23+
cargo = "cargo install oranda --locked --profile=dist"
24+
25+
[components.artifacts.package_managers.additional]
26+
npx = "npx @axodotdev/oranda"
27+
binstall = "cargo binstall oranda"
28+
nix-env = "nix-env -i oranda"
29+
"nix flake" = "nix profile install github:axodotdev/oranda"

src/config/oranda_config.rs

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
1-
use axoasset::SourceFile;
2-
use camino::Utf8PathBuf;
3-
use schemars::JsonSchema;
4-
use serde::{Deserialize, Serialize};
5-
6-
use crate::errors::*;
7-
8-
use super::{BuildLayer, ComponentLayer, MarketingLayer, ProjectLayer, StyleLayer, WorkspaceLayer};
9-
10-
/// Configuration for `oranda` (typically stored in oranda.json)
11-
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
12-
#[serde(deny_unknown_fields)]
13-
pub struct OrandaLayer {
14-
/// Info about the project/application you're making a site for
15-
///
16-
/// All of these values should automatically be sourced from your Cargo.toml or package.json
17-
/// whenever possible. You should only need to set these if you want to override the value.
18-
pub project: Option<ProjectLayer>,
19-
/// Settings for the build/output of the site
20-
pub build: Option<BuildLayer>,
21-
/// Settings for social/marketing/analytics
22-
pub marketing: Option<MarketingLayer>,
23-
/// Settings for themes/styles of the site
24-
pub styles: Option<StyleLayer>,
25-
/// Additional optional components
26-
pub components: Option<ComponentLayer>,
27-
/// Workspace configuration
28-
pub workspace: Option<WorkspaceLayer>,
29-
/// Field that text-editors can use to fetch the schema for this struct
30-
///
31-
/// We never use this, but we don't want to error out if its set.
32-
#[serde(rename = "$schema")]
33-
pub _schema: Option<String>,
34-
}
35-
36-
impl OrandaLayer {
37-
pub fn load(config_path: &Utf8PathBuf) -> Result<Option<OrandaLayer>> {
38-
let config_result = SourceFile::load_local(config_path.as_path());
39-
40-
match config_result {
41-
Ok(config) => {
42-
let data: OrandaLayer = config.deserialize_json()?;
43-
Ok(Some(data))
44-
}
45-
Err(_) => {
46-
tracing::debug!("No config found, using default values");
47-
Ok(None)
48-
}
49-
}
50-
}
51-
}
1+
use axoasset::SourceFile;
2+
use camino::Utf8PathBuf;
3+
use schemars::JsonSchema;
4+
use serde::{Deserialize, Serialize};
5+
6+
use crate::errors::*;
7+
8+
use super::{BuildLayer, ComponentLayer, MarketingLayer, ProjectLayer, StyleLayer, WorkspaceLayer};
9+
10+
/// Configuration for `oranda` (typically stored in oranda.json)
11+
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
12+
#[serde(deny_unknown_fields)]
13+
pub struct OrandaLayer {
14+
/// Info about the project/application you're making a site for
15+
///
16+
/// All of these values should automatically be sourced from your Cargo.toml or package.json
17+
/// whenever possible. You should only need to set these if you want to override the value.
18+
pub project: Option<ProjectLayer>,
19+
/// Settings for the build/output of the site
20+
pub build: Option<BuildLayer>,
21+
/// Settings for social/marketing/analytics
22+
pub marketing: Option<MarketingLayer>,
23+
/// Settings for themes/styles of the site
24+
pub styles: Option<StyleLayer>,
25+
/// Additional optional components
26+
pub components: Option<ComponentLayer>,
27+
/// Workspace configuration
28+
pub workspace: Option<WorkspaceLayer>,
29+
/// Field that text-editors can use to fetch the schema for this struct
30+
///
31+
/// We never use this, but we don't want to error out if its set.
32+
#[serde(rename = "$schema")]
33+
pub _schema: Option<String>,
34+
}
35+
36+
impl OrandaLayer {
37+
pub fn load(config_path: &Utf8PathBuf) -> Result<Option<OrandaLayer>> {
38+
let mut config_path = config_path.to_owned();
39+
if config_path.extension() == Some("json") {
40+
if config_path.exists() {
41+
let config = SourceFile::load_local(config_path.as_path())?;
42+
return Ok(Some(config.deserialize_json()?));
43+
} else {
44+
// Temporary hack
45+
config_path.set_extension("toml");
46+
}
47+
}
48+
if !config_path.exists() {
49+
tracing::debug!("No config found, using default values");
50+
return Ok(None);
51+
}
52+
if config_path.extension() == Some("toml") {
53+
tracing::warn!("!!!Using toml config!!!!");
54+
let config = SourceFile::load_local(config_path.as_path())?;
55+
return Ok(Some(config.deserialize_toml()?));
56+
}
57+
58+
tracing::debug!("No config found, using default values");
59+
Ok(None)
60+
}
61+
}

0 commit comments

Comments
 (0)