Skip to main content

htmlpacker/
config.rs

1/*
2* config.rs
3*
4* where the configuration structs are declared
5* also where the config is built
6* the config determines how the sources get packed into html
7*/
8
9use std::path::PathBuf;
10use url::Url;
11use serde::{Deserialize, Serialize};
12
13// internal config structs
14
15// enum that distinguishes between local and remote files
16#[derive(Debug, Deserialize, Serialize)]
17#[serde(untagged)]
18pub enum AssetSource {
19    Local(PathBuf),
20    Remote(Url),
21}
22
23impl Default for AssetSource {
24    fn default() -> Self {
25        AssetSource::Local(PathBuf::new())
26    }
27}
28
29#[derive(Debug, Deserialize, Serialize)]
30//#[serde(rename_all = "lowercase")]
31pub enum CompressionType {
32    Brotli,
33    None,
34}
35
36impl Default for CompressionType {
37    fn default() -> Self {
38        CompressionType::None
39    }
40}
41
42impl Default for RuntimeConfig {
43    fn default() -> Self {
44        RuntimeConfig { enabled: true }
45    }
46}
47
48// these are the configuration options for the packer
49// this defines the source files that will be packed
50#[derive(Debug, Default, Deserialize, Serialize)]
51pub struct PackerConfig {
52    #[serde(default)]
53    pub runtime: RuntimeConfig,
54    pub meta: Option<MetaConfig>,
55    pub favicon: Option<Vec<AssetSource>>,
56    pub styles: Option<Vec<AssetSource>>,
57    pub scripts: Option<Vec<AssetSource>>,
58    pub wasm: Option<Vec<WasmModule>>,
59}
60
61#[derive(Debug, Deserialize, Serialize)]
62pub struct RuntimeConfig {
63    pub enabled: bool,
64}
65
66#[derive(Debug, Default, Deserialize, Serialize)]
67pub struct MetaConfig {
68    pub title: Option<String>,
69    pub author: Option<String>,
70    pub description: Option<String>,
71    pub keywords: Option<String>,
72}
73
74#[derive(Debug, Default, Deserialize, Serialize)]
75pub struct WasmModule {
76    pub compile_wasm: bool,
77    pub id: String,
78    pub source: AssetSource,
79    pub compression: CompressionType,
80}