Skip to content

Commit 77b2671

Browse files
committed
chore: cargo fmt
1 parent 7885796 commit 77b2671

File tree

11 files changed

+185
-82
lines changed

11 files changed

+185
-82
lines changed

src/cli.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ struct Cli {
3636
enum Commands {
3737
/// Initialize a new Norgolith site
3838
Init {
39-
#[arg(long, default_value_t = true, overrides_with = "_no_prompt", help = "Whether to prompt for site info")]
39+
#[arg(
40+
long,
41+
default_value_t = true,
42+
overrides_with = "_no_prompt",
43+
help = "Whether to prompt for site info"
44+
)]
4045
prompt: bool,
4146

4247
#[arg(long = "no-prompt")]
@@ -55,7 +60,12 @@ enum Commands {
5560
#[arg(short = 'p', long, default_value_t = 3030, help = "Port to be used")]
5661
port: u16,
5762

58-
#[arg(long, default_value_t = true, overrides_with = "_no_drafts", help = "Whether to serve draft content")]
63+
#[arg(
64+
long,
65+
default_value_t = true,
66+
overrides_with = "_no_drafts",
67+
help = "Whether to serve draft content"
68+
)]
5969
drafts: bool,
6070

6171
#[arg(long = "no-drafts")]
@@ -120,14 +130,22 @@ pub async fn start() -> Result<()> {
120130
}
121131

122132
match &cli.command {
123-
Commands::Init { name, prompt: _, _no_prompt } => init_site(name.as_ref(), !_no_prompt).await?,
133+
Commands::Init {
134+
name,
135+
prompt: _,
136+
_no_prompt,
137+
} => init_site(name.as_ref(), !_no_prompt).await?,
124138
Commands::Theme { subcommand } => theme_handle(subcommand).await?,
125-
Commands::Serve { port, drafts: _, _no_drafts, open } => check_and_serve(*port, !_no_drafts, *open).await?,
139+
Commands::Serve {
140+
port,
141+
drafts: _,
142+
_no_drafts,
143+
open,
144+
} => check_and_serve(*port, !_no_drafts, *open).await?,
126145
Commands::Build { minify } => build_site(*minify).await?,
127146
Commands::New { kind, name, open } => {
128147
new_asset(kind.as_ref(), name.as_ref(), *open).await?
129-
}
130-
// _ => bail!("Unsupported command"),
148+
} // _ => bail!("Unsupported command"),
131149
}
132150

133151
Ok(())

src/cmd/build.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use std::sync::Arc;
44
use eyre::{bail, Result};
55
use futures_util::{self, StreamExt};
66
use tera::{Context, Tera};
7-
use walkdir::WalkDir;
87
use tokio::sync::Mutex;
8+
use walkdir::WalkDir;
99

1010
use crate::{
11-
config,
12-
fs,
11+
config, fs,
12+
schema::{format_errors, validate_metadata, ContentSchema},
1313
shared,
14-
schema::{ContentSchema, format_errors, validate_metadata},
1514
};
1615

1716
async fn prepare_build_directory(root_path: &Path) -> Result<()> {
@@ -84,7 +83,8 @@ async fn generate_public_build(
8483
// Metadata schema validation
8584
if let Some(schema) = &site_config.content_schema {
8685
// Get relative content path
87-
let content_path = path.strip_prefix(&build_dir)
86+
let content_path = path
87+
.strip_prefix(&build_dir)
8888
.unwrap()
8989
.with_extension("")
9090
.to_str()
@@ -96,7 +96,8 @@ async fn generate_public_build(
9696
let merged_schema = ContentSchema::merge_hierarchy(&schema_nodes);
9797

9898
// Convert metadata to hashmap for validation
99-
let metadata_map = metadata.as_table()
99+
let metadata_map = metadata
100+
.as_table()
100101
.unwrap()
101102
.iter()
102103
.map(|(k, v)| (k.clone(), v.clone()))
@@ -107,15 +108,14 @@ async fn generate_public_build(
107108

108109
// Collect errors
109110
if !errors.is_empty() {
110-
let norg_path = content_dir.join(content_path.clone()).strip_prefix(root_path).unwrap().with_extension("norg");
111+
let norg_path = content_dir
112+
.join(content_path.clone())
113+
.strip_prefix(root_path)
114+
.unwrap()
115+
.with_extension("norg");
111116
let error_output = format!(
112117
"[build] {}",
113-
format_errors(
114-
&norg_path,
115-
&content_path,
116-
&errors,
117-
false
118-
)
118+
format_errors(&norg_path, &content_path, &errors, false)
119119
);
120120

121121
validation_errors.lock().await.push(error_output);

src/cmd/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1+
mod build;
12
mod init;
23
mod new;
34
mod serve;
4-
mod build;
55
mod theme;
66

77
pub use self::{
8-
init::init,
9-
new::new,
10-
serve::serve,
11-
build::build,
12-
theme::handle as theme,
13-
theme::ThemeCommands,
8+
build::build, init::init, new::new, serve::serve, theme::handle as theme, theme::ThemeCommands,
149
};

src/cmd/serve.rs

+34-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ use tokio::{
2121
};
2222
use tokio_tungstenite::accept_async;
2323

24-
use crate::{config, fs, shared, schema::{ContentSchema, format_errors, validate_metadata}};
24+
use crate::{
25+
config, fs,
26+
schema::{format_errors, validate_metadata, ContentSchema},
27+
shared,
28+
};
2529

2630
// Global state for reloading
2731
struct ServerState {
@@ -359,7 +363,9 @@ pub async fn serve(port: u16, drafts: bool, open: bool) -> Result<()> {
359363
let rt = Handle::current();
360364

361365
// Initialize Tera once
362-
let tera = Arc::new(RwLock::new(shared::init_tera(&templates_dir, &theme_dir).await?));
366+
let tera = Arc::new(RwLock::new(
367+
shared::init_tera(&templates_dir, &theme_dir).await?,
368+
));
363369

364370
// Create reload channel
365371
let (reload_tx, _) = broadcast::channel(16);
@@ -524,33 +530,50 @@ pub async fn serve(port: u16, drafts: bool, open: bool) -> Result<()> {
524530
.to_string();
525531

526532
// Read generated metadata
527-
let build_dir = state.content_dir.parent().unwrap().join(".build");
533+
let build_dir =
534+
state.content_dir.parent().unwrap().join(".build");
528535
let meta_path = build_dir
529536
.join(stripped_path)
530537
.with_extension("meta.toml");
531538

532-
if let Ok(metadata_content) = tokio::fs::read_to_string(&meta_path).await {
533-
let metadata: toml::Value = toml::from_str(&metadata_content).unwrap_or_else(|e| {
539+
if let Ok(metadata_content) =
540+
tokio::fs::read_to_string(&meta_path).await
541+
{
542+
let metadata: toml::Value = toml::from_str(
543+
&metadata_content,
544+
)
545+
.unwrap_or_else(|e| {
534546
// Fallback to empty table on parse errors
535-
eprintln!("[server] Failed to parse metadata: {}", e);
547+
eprintln!(
548+
"[server] Failed to parse metadata: {}",
549+
e
550+
);
536551
toml::Value::Table(toml::map::Map::new())
537552
});
538-
let metadata_map = metadata.as_table().unwrap().iter()
553+
let metadata_map = metadata
554+
.as_table()
555+
.unwrap()
556+
.iter()
539557
.map(|(k, v)| (k.clone(), v.clone()))
540558
.collect();
541559

542560
// Resolve schema
543-
let schema_nodes = schema.resolve_path(&content_path);
544-
let merged_schema = ContentSchema::merge_hierarchy(&schema_nodes);
561+
let schema_nodes =
562+
schema.resolve_path(&content_path);
563+
let merged_schema =
564+
ContentSchema::merge_hierarchy(&schema_nodes);
545565

546566
// Validate and report warnings
547-
let errors = validate_metadata(&metadata_map, &merged_schema);
567+
let errors = validate_metadata(
568+
&metadata_map,
569+
&merged_schema,
570+
);
548571
if !errors.is_empty() {
549572
let error_output = format_errors(
550573
&rebuild_document_path,
551574
&content_path,
552575
&errors,
553-
true
576+
true,
554577
);
555578
eprintln!("[server] {}", error_output);
556579
}

src/cmd/theme.rs

+40-22
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::collections::HashMap;
22

3+
use clap::Subcommand;
4+
use eyre::{bail, eyre, Context, Result};
35
use indoc::formatdoc;
46
use inquire::{validator::Validation, Confirm, Select, Text};
5-
use eyre::{bail, eyre, Context, Result};
6-
use spinoff::{Spinner, spinners};
7-
use clap::Subcommand;
7+
use spinoff::{spinners, Spinner};
88

99
use crate::{
1010
fs,
@@ -57,7 +57,14 @@ async fn pull_theme(repo: &str, version: &Option<String>, pin: bool) -> Result<(
5757
semver::Version::parse(version).context("No valid semantic version provided")?;
5858
}
5959

60-
let mut sp = Spinner::new(spinners::Dots2, format!("Pulling theme from '{}'...", theme::resolve_repo_shorthand(repo).await?), None);
60+
let mut sp = Spinner::new(
61+
spinners::Dots2,
62+
format!(
63+
"Pulling theme from '{}'...",
64+
theme::resolve_repo_shorthand(repo).await?
65+
),
66+
None,
67+
);
6168
theme.pull(&mut sp).await?;
6269
sp.stop_and_persist("✓", "Successfully pulled theme");
6370
} else {
@@ -117,7 +124,8 @@ async fn rollback_theme() -> Result<()> {
117124
root.pop();
118125
let theme_dir = root.join("theme");
119126

120-
let backup_dir = theme_dir.parent()
127+
let backup_dir = theme_dir
128+
.parent()
121129
.ok_or_else(|| eyre!("Invalid theme directory"))?
122130
.join(".theme_backup");
123131

@@ -185,24 +193,31 @@ async fn init_theme() -> Result<()> {
185193
.with_default("0.1.0")
186194
.with_validator(|v: &str| match semver::Version::parse(v) {
187195
Ok(_) => Ok(Validation::Valid),
188-
Err(_) => Ok(Validation::Invalid("Invalid semantic version format".into())),
196+
Err(_) => Ok(Validation::Invalid(
197+
"Invalid semantic version format".into(),
198+
)),
189199
})
190200
.prompt()?;
191-
let license = Select::new("License:", vec![
192-
"MIT",
193-
"Apache-2.0",
194-
"GPL-2.0",
195-
"GPL-3.0",
196-
"BSD-3-Clause",
197-
"Unlicense",
198-
"Other",
199-
])
200-
// .with_starting_cursor(0)
201-
.with_help_message("Choose a license for your theme")
202-
.prompt()?;
201+
let license = Select::new(
202+
"License:",
203+
vec![
204+
"MIT",
205+
"Apache-2.0",
206+
"GPL-2.0",
207+
"GPL-3.0",
208+
"BSD-3-Clause",
209+
"Unlicense",
210+
"Other",
211+
],
212+
)
213+
// .with_starting_cursor(0)
214+
.with_help_message("Choose a license for your theme")
215+
.prompt()?;
203216

204217
let repository = Text::new("Repository URL (optional):")
205-
.with_help_message("Format: 'github:user/repo', 'codeberg:user/repo' or 'sourcehut:user/repo'")
218+
.with_help_message(
219+
"Format: 'github:user/repo', 'codeberg:user/repo' or 'sourcehut:user/repo'",
220+
)
206221
.prompt()?;
207222

208223
let theme_config = theme::ThemeMetadata {
@@ -270,9 +285,12 @@ async fn init_theme() -> Result<()> {
270285
.context("Failed to write README.md")?;
271286

272287
// Write theme.toml
273-
tokio::fs::write(theme_dir.join("theme.toml"), toml::to_string_pretty(&theme_config)?)
274-
.await
275-
.context("Failed to write theme.toml")?;
288+
tokio::fs::write(
289+
theme_dir.join("theme.toml"),
290+
toml::to_string_pretty(&theme_config)?,
291+
)
292+
.await
293+
.context("Failed to write theme.toml")?;
276294

277295
println!("\nTheme initialized successfully!");
278296
println!("Next steps:");

0 commit comments

Comments
 (0)