forked from lambda-fairy/maud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
30 lines (21 loc) · 875 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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();
}