Config: templates dir
This commit is contained in:
parent
fa306e9542
commit
81681303b2
3 changed files with 14 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::db::*;
|
||||
use crate::{config::Config, db::*};
|
||||
|
||||
use serde::Serialize;
|
||||
use std::path::Path;
|
||||
|
|
@ -17,15 +17,15 @@ pub struct Templates {
|
|||
}
|
||||
|
||||
impl Templates {
|
||||
pub fn new(dir: &Path) -> Self {
|
||||
let dir = dir.join("templates");
|
||||
pub fn new(dir: &Path, config: &Config) -> Self {
|
||||
let dir = dir.join(&config.templates_dir);
|
||||
std::fs::create_dir_all(&dir).expect("Cannot create templates dir");
|
||||
|
||||
for &(file, default) in TEMPLATE_FILES {
|
||||
let file_path = dir.join(file);
|
||||
if !file_path.is_file() {
|
||||
std::fs::write(file_path, default)
|
||||
.unwrap_or_else(|_| panic!("Cannot write template file {}", file));
|
||||
.unwrap_or_else(|_| panic!("Cannot write template file {file}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue