From 7e78446bb7227fc90f869f53e321853e91b2e34a Mon Sep 17 00:00:00 2001 From: veradec Date: Fri, 30 Oct 2026 19:42:26 +0530 Subject: add: static contents get copied to public dir --- src/main.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 4e6c706..0546a67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,10 +81,14 @@ fn markdown_to_html(path: String, content: String) -> HTMLFile { if file_name != "public/index.md" { file_name = file_name[0..(file_name.len() - 3)].to_string() + "/index.html"; - html = replace_with_content(fs::read_to_string("templates/post.html").unwrap(), &html); + html = fs::read_to_string("templates/post.html") + .unwrap() + .replace("{{content}}", &html); } else { file_name = "public/index.html".to_string(); - html = replace_with_content(fs::read_to_string("templates/index.html").unwrap(), &html); + html = fs::read_to_string("templates/index.html") + .unwrap() + .replace("{{content}}", &html); } return HTMLFile { @@ -113,11 +117,25 @@ fn write_content_to_file(f: HTMLFile) { fs::write(path, f.content); } -fn replace_with_content(html: String, content: &str) -> String { - return html.replace("{{content}}", content); +fn copy_dir(src: impl AsRef, dst: impl AsRef) -> std::io::Result<()> { + fs::create_dir_all(&dst)?; + for entry in fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir(entry.path(), dst.as_ref().join(entry.file_name()))?; + } else { + fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + Ok(()) } fn main() -> Result<()> { + // copy static folder to public folder + copy_dir(Path::new("static"), Path::new("public")); + ////// + for file in WalkDir::new("content/").into_iter().filter_map(|e| e.ok()) { let file_name = file.file_name().to_string_lossy(); if file_name.ends_with(".md") { -- cgit v1.2.3