Skip to main content

oseda_cli/templates/html/
mod.rs

1use std::{collections::HashMap, fs};
2
3use crate::templates::{render_template, Renderer, RendererError};
4
5pub const HTML_VITE_CONFIG_JS: &str = include_str!("static/vite.config.js");
6pub const HTML_INDEX_HTML: &str = include_str!("static/index.html");
7pub const HTML_MAIN_JS: &str = include_str!("static/main.js");
8pub const HTML_SLIDES: &str = include_str!("static/slides.html");
9pub const HTML_CUSTOM_CSS: &str = include_str!("static/custom.css");
10pub const HTML_FERRIS: &[u8] = include_bytes!("static/ferris.png");
11pub const HTML_GITIGNORE: &str = include_str!("static/.gitignore");
12pub const HTML_FAVICON: &[u8] = include_bytes!("static/favicon.png");
13
14pub struct HtmlRenderer {
15    pub params: HashMap<String, String>,
16}
17
18impl Renderer for HtmlRenderer {
19    fn write_to_fs(&self, target_dir: &str) -> Result<(), RendererError> {
20        fs::write(
21            format!("{}/vite.config.js", target_dir),
22            render_template(HTML_VITE_CONFIG_JS, &self.params),
23        )?;
24        fs::write(
25            format!("{}/index.html", target_dir),
26            render_template(HTML_INDEX_HTML, &self.params),
27        )?;
28        fs::write(
29            format!("{}/.gitignore", target_dir),
30            render_template(HTML_GITIGNORE, &self.params),
31        )?;
32
33        std::fs::create_dir_all(format!("{}/src", target_dir))?;
34        fs::write(
35            format!("{}/src/main.js", target_dir),
36            render_template(HTML_MAIN_JS, &self.params),
37        )?;
38
39        std::fs::create_dir_all(format!("{}/slides", target_dir))?;
40        fs::write(
41            format!("{}/slides/slides.html", target_dir),
42            render_template(HTML_SLIDES, &self.params),
43        )?;
44
45        std::fs::create_dir_all(format!("{}/css", target_dir))?;
46        fs::write(
47            format!("{}/css/custom.css", target_dir),
48            render_template(HTML_CUSTOM_CSS, &self.params),
49        )?;
50
51        std::fs::create_dir_all(format!("{}/public", target_dir))?;
52        fs::write(format!("{}/public/ferris.png", target_dir), HTML_FERRIS)?;
53        fs::write(format!("{}/public/favicon.png", target_dir), HTML_FAVICON)?;
54
55        Ok(())
56    }
57}