diff options
| author | veradec <glitchmill.dyj3d@simplelogin.co> | 2026-10-30 19:17:01 +0530 |
|---|---|---|
| committer | veradec <glitchmill.dyj3d@simplelogin.co> | 2026-10-30 19:17:01 +0530 |
| commit | f3456ff62ec92774fcbdb3ee13d6afa53e359558 (patch) | |
| tree | 5b49711c3db6ad4957ac4133486a529502236bfa | |
| parent | e209b5617d2c1332e50c421112791f49b84e6d0b (diff) | |
add: template engine converts md to html (STATIC WEBSITE GENERATOR IS DONE WITH MVP STAGE!!!!!!!!)
| -rw-r--r-- | src/main.rs | 22 | ||||
| -rw-r--r-- | templates/post.html | 2 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index c84cdbc..4e6c706 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,15 +72,19 @@ fn markdown_to_html(path: String, content: String) -> HTMLFile { let mut header: bool; (date, title, description, toc, header) = meta_data_extractor(meta_data); - let html = markdown::to_html(&content[end + 7..]); + let mut html = markdown::to_html(&content[end + 7..]); + let mut file_name = std::path::Path::new(&path) .display() .to_string() .replacen("content", "public", 1); 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); } else { file_name = "public/index.html".to_string(); + html = replace_with_content(fs::read_to_string("templates/index.html").unwrap(), &html); } return HTMLFile { @@ -114,15 +118,11 @@ fn replace_with_content(html: String, content: &str) -> String { } fn main() -> Result<()> { - // 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") { - // write_content_to_file(get_html_from_file(file.path())); - // } - // } - println!( - "{}", - replace_with_content("This isn't {{content}}".to_string(), "Jinja2") - ); + 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") { + write_content_to_file(get_html_from_file(file.path())); + } + } Ok(()) } diff --git a/templates/post.html b/templates/post.html index 5503f17..b533b97 100644 --- a/templates/post.html +++ b/templates/post.html @@ -2,6 +2,8 @@ <html> <body> +This is a post ig? idk, you tell me + {{content}} </body> |
