Add mdBook documentation with Ghostty-style sidebar
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
// Verify that required directories exist at build time
|
||||
@@ -46,9 +47,87 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Build mdBook documentation
|
||||
build_documentation();
|
||||
|
||||
// Tell cargo to rerun if these directories change
|
||||
println!("cargo:rerun-if-changed=static/");
|
||||
println!("cargo:rerun-if-changed=templates/");
|
||||
println!("cargo:rerun-if-changed=package.json");
|
||||
println!("cargo:rerun-if-changed=package-lock.json");
|
||||
println!("cargo:rerun-if-changed=docs/");
|
||||
}
|
||||
|
||||
fn build_documentation() {
|
||||
let docs_dir = Path::new("docs");
|
||||
let static_docs_dir = Path::new("static/docs");
|
||||
|
||||
// If static/docs already exists (e.g., from Docker COPY), we're done
|
||||
if static_docs_dir.exists() {
|
||||
println!("cargo:warning=Documentation already present in static/docs");
|
||||
return;
|
||||
}
|
||||
|
||||
if !docs_dir.exists() {
|
||||
println!("cargo:warning=Documentation directory not found, skipping docs build");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if mdbook is installed
|
||||
let mdbook_check = Command::new("mdbook").arg("--version").output();
|
||||
|
||||
if mdbook_check.is_err() {
|
||||
println!("cargo:warning=mdbook not found. Install with: cargo install mdbook");
|
||||
println!("cargo:warning=Skipping documentation build");
|
||||
println!("cargo:warning=Documentation will be available if pre-built in static/docs");
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: mdbook-catppuccin preprocessor is deprecated
|
||||
// Catppuccin theme is now applied via CSS file in docs/theme/
|
||||
// No need to check for mdbook-catppuccin installation
|
||||
|
||||
// Build the documentation
|
||||
println!("cargo:warning=Building documentation with mdbook...");
|
||||
let build_result = Command::new("mdbook")
|
||||
.arg("build")
|
||||
.current_dir("docs")
|
||||
.status();
|
||||
|
||||
match build_result {
|
||||
Ok(status) if status.success() => {
|
||||
println!("cargo:warning=Documentation built successfully");
|
||||
|
||||
// Copy docs to static directory for serving
|
||||
if Path::new("docs/book").exists() {
|
||||
// Ensure static directory exists
|
||||
let _ = std::fs::create_dir_all("static");
|
||||
|
||||
let copy_result = if cfg!(target_os = "windows") {
|
||||
Command::new("xcopy")
|
||||
.args(&["/E", "/I", "/Y", "docs\\book", "static\\docs"])
|
||||
.status()
|
||||
} else {
|
||||
Command::new("cp")
|
||||
.args(&["-r", "docs/book", "static/docs"])
|
||||
.status()
|
||||
};
|
||||
|
||||
match copy_result {
|
||||
Ok(status) if status.success() => {
|
||||
println!("cargo:warning=Documentation copied to static/docs");
|
||||
}
|
||||
_ => {
|
||||
println!("cargo:warning=Failed to copy documentation to static directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(_) => {
|
||||
println!("cargo:warning=mdbook build failed");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("cargo:warning=Failed to run mdbook: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user