systemprompt_provider_contracts/web_config/
paths.rs1use std::path::Path;
7
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct PathsConfig {
12 pub templates: String,
13 pub assets: String,
14 #[serde(default)]
15 pub css_url_prefix: Option<String>,
16}
17
18impl PathsConfig {
19 pub fn resolve_relative_to(&mut self, base: &Path) {
20 self.templates = resolve_path(base, &self.templates);
21 }
22}
23
24fn resolve_path(base: &Path, path: &str) -> String {
25 if path.is_empty() {
26 return path.to_owned();
27 }
28
29 let p = Path::new(path);
30 if p.is_absolute() {
31 return path.to_owned();
32 }
33
34 let resolved = base.join(p);
35 resolved.canonicalize().map_or_else(
36 |_| resolved.to_string_lossy().to_string(),
37 |canonical| canonical.to_string_lossy().to_string(),
38 )
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct ScriptConfig {
43 pub src: String,
44 #[serde(default)]
45 pub defer: bool,
46 #[serde(default)]
47 pub r#async: bool,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct ContentConfig {
52 #[serde(default)]
53 pub config_file: Option<String>,
54 #[serde(default)]
55 pub sources: Vec<String>,
56}