diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index cd48c219e4..3b4cdb50ab 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -38,6 +38,8 @@ pub enum BuildMode { Disk, /// In memory for the content -> `zola serve` Memory, + /// Both on the filesystem and in memory + Both, } #[derive(Debug)] @@ -114,10 +116,10 @@ impl Site { } /// Enable some `zola serve` related options - pub fn enable_serve_mode(&mut self) { + pub fn enable_serve_mode(&mut self, both: bool) { SITE_CONTENT.write().unwrap().clear(); self.config.enable_serve_mode(); - self.build_mode = BuildMode::Memory; + self.build_mode = if both { BuildMode::Both } else { BuildMode::Memory }; } /// Set the site to load the drafts. @@ -660,16 +662,20 @@ impl Site { }; match self.build_mode { - BuildMode::Disk => { + BuildMode::Disk | BuildMode::Both => { let end_path = current_path.join(filename); create_file(&end_path, &final_content)?; } - BuildMode::Memory => { + _ => (), + } + match self.build_mode { + BuildMode::Memory | BuildMode::Both => { let site_path = if filename != "index.html" { site_path.join(filename) } else { site_path }; SITE_CONTENT.write().unwrap().insert(site_path, final_content); } + _ => (), } Ok(current_path) diff --git a/src/cli.rs b/src/cli.rs index c3f68a493c..a15dbeb3e5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -82,6 +82,10 @@ pub enum Command { #[clap(short = 'O', long)] open: bool, + /// Also store HTML in the public/ folder (by default HTML is only stored in-memory) + #[clap(short = 'H', long)] + store_html: bool, + /// Only rebuild the minimum on change - useful when working on a specific page/section #[clap(short = 'f', long)] fast: bool, diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 2ab661b0f3..b6cedb9aae 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -367,6 +367,7 @@ fn create_new_site( base_url: Option<&str>, config_file: &Path, include_drafts: bool, + store_html: bool, mut no_port_append: bool, ws_port: Option, ) -> Result<(Site, SocketAddr, String)> { @@ -390,7 +391,7 @@ fn create_new_site( constructed_base_url.truncate(constructed_base_url.len() - 1); } - site.enable_serve_mode(); + site.enable_serve_mode(store_html); site.set_base_url(constructed_base_url.clone()); if let Some(output_dir) = output_dir { if !force && output_dir.exists() { @@ -427,6 +428,7 @@ pub fn serve( config_file: &Path, open: bool, include_drafts: bool, + store_html: bool, fast_rebuild: bool, no_port_append: bool, utc_offset: UtcOffset, @@ -442,6 +444,7 @@ pub fn serve( base_url, config_file, include_drafts, + store_html, no_port_append, None, )?; @@ -672,6 +675,7 @@ pub fn serve( base_url, config_file, include_drafts, + store_html, no_port_append, ws_port, ) { @@ -916,6 +920,7 @@ mod tests { base_url.as_deref(), &config_file, include_drafts, + store_html, no_port_append, ws_port, ) diff --git a/src/main.rs b/src/main.rs index 88b3e0e617..1dbfc86b5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,6 +84,7 @@ fn main() { base_url, drafts, open, + store_html, fast, no_port_append, extra_watch_path, @@ -112,6 +113,7 @@ fn main() { &config_file, open, drafts, + store_html, fast, no_port_append, UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC),