Commit 8ba104f 1 parent 967c54a commit 8ba104f Copy full SHA for 8ba104f
File tree 4 files changed +22
-5
lines changed
4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ pub enum BuildMode {
38
38
Disk ,
39
39
/// In memory for the content -> `zola serve`
40
40
Memory ,
41
+ /// Both on the filesystem and in memory
42
+ Both ,
41
43
}
42
44
43
45
#[ derive( Debug ) ]
@@ -114,10 +116,10 @@ impl Site {
114
116
}
115
117
116
118
/// Enable some `zola serve` related options
117
- pub fn enable_serve_mode ( & mut self ) {
119
+ pub fn enable_serve_mode ( & mut self , both : bool ) {
118
120
SITE_CONTENT . write ( ) . unwrap ( ) . clear ( ) ;
119
121
self . config . enable_serve_mode ( ) ;
120
- self . build_mode = BuildMode :: Memory ;
122
+ self . build_mode = if both { BuildMode :: Both } else { BuildMode :: Memory } ;
121
123
}
122
124
123
125
/// Set the site to load the drafts.
@@ -660,16 +662,20 @@ impl Site {
660
662
} ;
661
663
662
664
match self . build_mode {
663
- BuildMode :: Disk => {
665
+ BuildMode :: Disk | BuildMode :: Both => {
664
666
let end_path = current_path. join ( filename) ;
665
667
create_file ( & end_path, & final_content) ?;
666
668
}
667
- BuildMode :: Memory => {
669
+ _ => ( ) ,
670
+ }
671
+ match self . build_mode {
672
+ BuildMode :: Memory | BuildMode :: Both => {
668
673
let site_path =
669
674
if filename != "index.html" { site_path. join ( filename) } else { site_path } ;
670
675
671
676
SITE_CONTENT . write ( ) . unwrap ( ) . insert ( site_path, final_content) ;
672
677
}
678
+ _ => ( ) ,
673
679
}
674
680
675
681
Ok ( current_path)
Original file line number Diff line number Diff line change @@ -82,6 +82,10 @@ pub enum Command {
82
82
#[ clap( short = 'O' , long) ]
83
83
open : bool ,
84
84
85
+ /// Also store HTML in the public/ folder (by default HTML is only stored in-memory)
86
+ #[ clap( short = 'H' , long) ]
87
+ store_html : bool ,
88
+
85
89
/// Only rebuild the minimum on change - useful when working on a specific page/section
86
90
#[ clap( short = 'f' , long) ]
87
91
fast : bool ,
Original file line number Diff line number Diff line change @@ -367,6 +367,7 @@ fn create_new_site(
367
367
base_url : Option < & str > ,
368
368
config_file : & Path ,
369
369
include_drafts : bool ,
370
+ store_html : bool ,
370
371
mut no_port_append : bool ,
371
372
ws_port : Option < u16 > ,
372
373
) -> Result < ( Site , SocketAddr , String ) > {
@@ -390,7 +391,7 @@ fn create_new_site(
390
391
constructed_base_url. truncate ( constructed_base_url. len ( ) - 1 ) ;
391
392
}
392
393
393
- site. enable_serve_mode ( ) ;
394
+ site. enable_serve_mode ( store_html ) ;
394
395
site. set_base_url ( constructed_base_url. clone ( ) ) ;
395
396
if let Some ( output_dir) = output_dir {
396
397
if !force && output_dir. exists ( ) {
@@ -427,6 +428,7 @@ pub fn serve(
427
428
config_file : & Path ,
428
429
open : bool ,
429
430
include_drafts : bool ,
431
+ store_html : bool ,
430
432
fast_rebuild : bool ,
431
433
no_port_append : bool ,
432
434
utc_offset : UtcOffset ,
@@ -442,6 +444,7 @@ pub fn serve(
442
444
base_url,
443
445
config_file,
444
446
include_drafts,
447
+ store_html,
445
448
no_port_append,
446
449
None ,
447
450
) ?;
@@ -672,6 +675,7 @@ pub fn serve(
672
675
base_url,
673
676
config_file,
674
677
include_drafts,
678
+ store_html,
675
679
no_port_append,
676
680
ws_port,
677
681
) {
@@ -916,6 +920,7 @@ mod tests {
916
920
base_url. as_deref ( ) ,
917
921
& config_file,
918
922
include_drafts,
923
+ store_html,
919
924
no_port_append,
920
925
ws_port,
921
926
)
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ fn main() {
84
84
base_url,
85
85
drafts,
86
86
open,
87
+ store_html,
87
88
fast,
88
89
no_port_append,
89
90
extra_watch_path,
@@ -112,6 +113,7 @@ fn main() {
112
113
& config_file,
113
114
open,
114
115
drafts,
116
+ store_html,
115
117
fast,
116
118
no_port_append,
117
119
UtcOffset :: current_local_offset ( ) . unwrap_or ( UtcOffset :: UTC ) ,
You can’t perform that action at this time.
0 commit comments