[Web] Use template file to render markdown
This commit is contained in:
parent
a9ee398440
commit
ab5c38003a
@ -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
|
||||
<!-- Some html -->
|
||||
{{markdown}}
|
||||
<!-- More html -->
|
||||
```
|
||||
|
||||
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
|
||||
|
@ -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(())
|
||||
|
Loading…
Reference in New Issue
Block a user