diff options
| author | veradec <glitchmill.dyj3d@simplelogin.co> | 2026-10-30 00:02:54 +0530 |
|---|---|---|
| committer | veradec <glitchmill.dyj3d@simplelogin.co> | 2026-10-30 00:02:54 +0530 |
| commit | e209b5617d2c1332e50c421112791f49b84e6d0b (patch) | |
| tree | b46d29cbf28d600be0cfd129a8724d70624430fa | |
| parent | 3bcecbec61f21112c79feadb938852ff645656da (diff) | |
add: template engine to replace instances of {{content}} to the actual content.
| -rw-r--r-- | src/main.rs | 23 | ||||
| -rw-r--r-- | templates/index.html | 5 | ||||
| -rw-r--r-- | templates/list.html | 10 | ||||
| -rw-r--r-- | templates/post.html | 8 |
4 files changed, 35 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index 717ff5c..c84cdbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,6 @@ fn markdown_to_html(path: String, content: String) -> HTMLFile { } else { file_name = "public/index.html".to_string(); } - println!("File Path: {file_name}"); return HTMLFile { file_name, @@ -104,20 +103,26 @@ fn get_html_from_file(path: &Path) -> HTMLFile { fn write_content_to_file(f: HTMLFile) { let file_path = f.file_name; let path = Path::new(&file_path); - if let Some(parent) = path.parent() { fs::create_dir_all(parent); } fs::write(path, f.content); } -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())); - } - } +fn replace_with_content(html: String, content: &str) -> String { + return html.replace("{{content}}", content); +} +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") + ); Ok(()) } diff --git a/templates/index.html b/templates/index.html index 9ad19d3..92314c6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,8 +2,9 @@ <html> <body> -<h1>My First Heading</h1> -<p>My first paragraph.</p> +<h1>Venkata Rao Dechiraju's Website</h1> + +{{content}} </body> </html> diff --git a/templates/list.html b/templates/list.html new file mode 100644 index 0000000..15cfb96 --- /dev/null +++ b/templates/list.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html> +<body> + +<h1>Blog List</h1> + +{{content}} + +</body> +</html> diff --git a/templates/post.html b/templates/post.html new file mode 100644 index 0000000..5503f17 --- /dev/null +++ b/templates/post.html @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<html> +<body> + +{{content}} + +</body> +</html> |
