-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
40 lines (34 loc) · 1.21 KB
/
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
31
32
33
34
35
36
37
38
39
40
use std::env;
use std::fs;
use std::path::Path;
fn main() {
// Get OUT_DIR environment variable
let out_dir = env::var_os("OUT_DIR").unwrap();
let templates_dir = Path::new(&out_dir).join("templates");
// Create templates directory in OUT_DIR
fs::create_dir_all(&templates_dir).unwrap();
// Get the project root directory (where Cargo.toml lives)
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let project_templates = Path::new(&manifest_dir).join("templates");
println!("{manifest_dir}");
println!("{}", project_templates.display());
// List of template files to copy
let template_files = [
"config.toml",
"example.md",
"base.html",
"index.html",
"post.html",
"style.css",
"terminal_velocity.png",
];
// Copy each template file
for &file in &template_files {
let src = project_templates.join(file);
let dest = templates_dir.join(file);
fs::copy(&src, &dest)
.unwrap_or_else(|_| panic!("Failed to copy template file: {}", src.display()));
}
// Tell Cargo to rerun this build script if templates change
println!("cargo:rerun-if-changed=templates/");
}