From 2973430c007e4f2ed0a09182ab7da796302c8b42 Mon Sep 17 00:00:00 2001 From: eiiko6 Date: Thu, 26 Feb 2026 14:42:24 +0100 Subject: [PATCH] eliminated unneeded panics --- src/analysis.rs | 10 +++++----- src/entry.rs | 6 +++++- src/main.rs | 43 ++++++++++++++++++++----------------------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/analysis.rs b/src/analysis.rs index cc1820b..17d0179 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -25,11 +25,11 @@ impl WikiGraph { let config: WikiConfig = toml::from_str(&content) .with_context(|| format!("Failed to parse {:?}", path))?; - let slug = path - .file_stem() - .and_then(|s| s.to_str()) - .unwrap() - .to_string(); + let slug: String = if let Some(file_stem) = path.file_stem() { + file_stem.to_string_lossy().into_owned() + } else { + continue; + }; nodes.insert(slug.clone(), config.clone()); raw_files.insert(slug, config); diff --git a/src/entry.rs b/src/entry.rs index 57de675..73673b1 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -23,7 +23,11 @@ async fn list_entries(root: &PathBuf) -> Result<()> { while let Some(entry) = entries.next_entry().await? { let path = entry.path(); if path.extension().and_then(|s| s.to_str()) == Some("toml") { - let name = path.file_stem().unwrap().to_string_lossy().to_string(); + let name = if let Some(file_stem) = path.file_stem() { + file_stem.to_string_lossy().to_string() + } else { + continue; + }; // Read configuration to check for linked files let content = fs::read_to_string(&path).await.unwrap_or_default(); diff --git a/src/main.rs b/src/main.rs index 478d705..0c95d81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -182,7 +182,7 @@ async fn get_summary_data(docs_dir: &PathBuf, is_static: bool) -> Vec { } async fn run_build(docs_dir: PathBuf, out_dir: PathBuf, no_navigation: bool) -> anyhow::Result<()> { - tracing::info!("Building static site to: {:?}", out_dir); + tracing::info!("Building static site to: {}", out_dir.display()); if !no_navigation { let pages = get_summary_data(&docs_dir, true).await; @@ -209,10 +209,20 @@ async fn run_build(docs_dir: PathBuf, out_dir: PathBuf, no_navigation: bool) -> let mut entries = tokio::fs::read_dir(&docs_dir).await?; while let Some(entry) = entries.next_entry().await? { let path = entry.path(); - if let Some(ext) = path.extension().and_then(|s| s.to_str()) { - if ["png", "jpg", "jpeg", "gif", "webp"].contains(&ext) { - let dest = out_dir.join(path.file_name().unwrap()); - tokio::fs::copy(path, dest).await?; + if path.extension().and_then(|s| s.to_str()) == Some("toml") { + let filename = if let Some(file_name) = entry.file_name().to_str() { + file_name.to_string() + } else { + continue; + }; + + match render_wiki_page(&filename, &docs_dir, no_navigation, true).await { + Ok(rendered) => { + let out_file = out_dir.join(filename.replace(".toml", ".html")); + tokio::fs::write(&out_file, rendered).await?; + tracing::info!("Generated {}", out_file.display()); + } + Err(e) => tracing::error!("Failed to generate {}: {}", filename, e), } } } @@ -227,29 +237,16 @@ async fn run_build(docs_dir: PathBuf, out_dir: PathBuf, no_navigation: bool) -> tracing::info!("Copied {}", entry.file_name().display(),); let path = entry.path(); if path.is_file() { - let dest = out_images.join(path.file_name().unwrap()); + let dest = out_images.join(if let Some(file_name) = path.file_name() { + file_name + } else { + continue; + }); tokio::fs::copy(path, dest).await?; } } } - let mut entries = tokio::fs::read_dir(&docs_dir).await?; - while let Some(entry) = entries.next_entry().await? { - let path = entry.path(); - if path.extension().and_then(|s| s.to_str()) == Some("toml") { - let filename = entry.file_name().to_str().unwrap().to_string(); - - match render_wiki_page(&filename, &docs_dir, no_navigation, true).await { - Ok(rendered) => { - let out_file = out_dir.join(filename.replace(".toml", ".html")); - tokio::fs::write(out_file, rendered).await?; - tracing::info!("Generated {}", filename); - } - Err(e) => tracing::error!("Failed to generate {}: {}", filename, e), - } - } - } - tracing::info!("Build complete!"); Ok(()) }