fix: initialization_script now reads the same way as html

This commit is contained in:
Tim-Paik 2022-05-01 16:43:11 +08:00
parent d31ddba08a
commit eb5eb5283a
Signed by: Tim-Paik
GPG Key ID: DC36A050DB42566D
1 changed files with 5 additions and 8 deletions

View File

@ -66,7 +66,7 @@ pub struct Config {
pub spa: bool, pub spa: bool,
pub url: Option<String>, pub url: Option<String>,
pub html: Option<PathBuf>, pub html: Option<PathBuf>,
pub initialization_script: Option<String>, pub initialization_script: Option<PathBuf>,
} }
#[derive(Serialize, Deserialize, Clone, Debug, Default)] #[derive(Serialize, Deserialize, Clone, Debug, Default)]
@ -248,7 +248,7 @@ impl Default for Config {
spa: false, spa: false,
url: Some("/index.html".into()), url: Some("/index.html".into()),
html: None, html: None,
initialization_script: Some("".into()), initialization_script: None,
} }
} }
} }
@ -284,12 +284,9 @@ impl Config {
Some(path) => fs::read_to_string(path.as_path()).ok(), Some(path) => fs::read_to_string(path.as_path()).ok(),
None => None, None => None,
}, },
initialization_script: { initialization_script: match &self.initialization_script {
if let Some(script_path) = &self.initialization_script { Some(path) => fs::read_to_string(path.as_path()).ok(),
fs::read_to_string(Path::new(script_path)).ok() None => None,
} else {
None
}
}, },
}) })
} }