Skip to main content

oseda_cli/templates/md/
mod.rs

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