From ab5c38003a02b33a94eb62eaa078bb9c3ec21821 Mon Sep 17 00:00:00 2001 From: Araozu Date: Tue, 28 Mar 2023 19:32:06 -0500 Subject: [PATCH] [Web] Use template file to render markdown --- doc-generator/README.md | 13 +++++++++++++ doc-generator/src/main.rs | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc-generator/README.md b/doc-generator/README.md index f797a3b..c9fd7b4 100644 --- a/doc-generator/README.md +++ b/doc-generator/README.md @@ -23,6 +23,19 @@ markdown, and have the `.md` file extension. Contains CSS, JS, and HTML templates. Here the MD files are written to after being converted. +There must be a `template.html` file inside this folder. This file will be used to generate the HTML from MD files. + +Inside `template.html` there must be a string `{{markdown}}`: + +```html + + {{markdown}} + +``` + +This string, `{{markdown}}`, will be replaced with the HTML generated +from Markdown + ## `dist` folder Coming soon, this folder will contain all HTML, CSS & JS minified after diff --git a/doc-generator/src/main.rs b/doc-generator/src/main.rs index 9f4765d..7d61ee3 100644 --- a/doc-generator/src/main.rs +++ b/doc-generator/src/main.rs @@ -112,9 +112,18 @@ fn process_markdown(file: &Path, input_folder: &Path, output_folder: &Path) -> R println!("Compiling: from -> to\n{:?}\n{:?}\n", input_file, output_file); + // Read template.html + let mut template_path = output_folder.clone(); + template_path.push("template.html"); + + let template_contents = fs::read(template_path).unwrap(); + let template_contents = String::from_utf8(template_contents).unwrap(); + + let final_output = template_contents.replace("{{markdown}}", &html_text); + let _ = File::create(&output_file) .unwrap() - .write_all(html_text.as_bytes()) + .write_all(final_output.as_bytes()) .unwrap(); Ok(())