maud/doctest/build.rs
2021-05-20 05:16:04 +00:00

30 lines
875 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use std::ffi::OsStr;
use std::fmt::Write as _;
use std::fs;
fn main() {
const DOCS_DIR: &str = "../docs/content";
// Rebuild if a chapter is added or removed
println!("cargo:rerun-if-changed={}", DOCS_DIR);
let mut buffer = r#"// Automatically @generated do not edit
"#.to_string();
for entry in fs::read_dir(DOCS_DIR).unwrap() {
let entry = entry.unwrap();
assert!(entry.file_type().unwrap().is_file());
let path = entry.path();
assert_eq!(path.extension(), Some(OsStr::new("md")));
let path_str = path.to_str().unwrap();
let slug_str = path.file_stem().unwrap().to_str().unwrap().replace("-", "_");
writeln!(buffer, r#"#[doc = include_str!("{}")]"#, path_str).unwrap();
writeln!(buffer, r#"mod {} {{ }}"#, slug_str).unwrap();
}
fs::write("lib.rs", buffer).unwrap();
}