@@ -42,6 +42,7 @@ use std::collections::{BTreeMap, HashSet, VecDeque};
42
42
use std:: default:: Default ;
43
43
use std:: error;
44
44
use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
45
+ use std:: ffi:: OsStr ;
45
46
use std:: fs:: { self , File , OpenOptions } ;
46
47
use std:: io:: prelude:: * ;
47
48
use std:: io:: { self , BufWriter , BufReader } ;
@@ -756,10 +757,12 @@ fn write_shared(cx: &Context,
756
757
// Add all the static files. These may already exist, but we just
757
758
// overwrite them anyway to make sure that they're fresh and up-to-date.
758
759
759
- write ( cx. dst . join ( & format ! ( "rustdoc{}.css" , cx. shared. resource_suffix) ) ,
760
- include_bytes ! ( "static/rustdoc.css" ) ) ?;
761
- write ( cx. dst . join ( & format ! ( "settings{}.css" , cx. shared. resource_suffix) ) ,
762
- include_bytes ! ( "static/settings.css" ) ) ?;
760
+ write_minify ( cx. dst . join ( & format ! ( "rustdoc{}.css" , cx. shared. resource_suffix) ) ,
761
+ include_str ! ( "static/rustdoc.css" ) ,
762
+ enable_minification) ?;
763
+ write_minify ( cx. dst . join ( & format ! ( "settings{}.css" , cx. shared. resource_suffix) ) ,
764
+ include_str ! ( "static/settings.css" ) ,
765
+ enable_minification) ?;
763
766
764
767
// To avoid "light.css" to be overwritten, we'll first run over the received themes and only
765
768
// then we'll run over the "official" styles.
@@ -781,11 +784,13 @@ fn write_shared(cx: &Context,
781
784
include_bytes ! ( "static/brush.svg" ) ) ?;
782
785
write ( cx. dst . join ( & format ! ( "wheel{}.svg" , cx. shared. resource_suffix) ) ,
783
786
include_bytes ! ( "static/wheel.svg" ) ) ?;
784
- write ( cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
785
- include_bytes ! ( "static/themes/light.css" ) ) ?;
787
+ write_minify ( cx. dst . join ( & format ! ( "light{}.css" , cx. shared. resource_suffix) ) ,
788
+ include_str ! ( "static/themes/light.css" ) ,
789
+ enable_minification) ?;
786
790
themes. insert ( "light" . to_owned ( ) ) ;
787
- write ( cx. dst . join ( & format ! ( "dark{}.css" , cx. shared. resource_suffix) ) ,
788
- include_bytes ! ( "static/themes/dark.css" ) ) ?;
791
+ write_minify ( cx. dst . join ( & format ! ( "dark{}.css" , cx. shared. resource_suffix) ) ,
792
+ include_str ! ( "static/themes/dark.css" ) ,
793
+ enable_minification) ?;
789
794
themes. insert ( "dark" . to_owned ( ) ) ;
790
795
791
796
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
@@ -857,10 +862,19 @@ themePicker.onblur = handleThemeButtonsBlur;
857
862
858
863
if let Some ( ref css) = cx. shared . css_file_extension {
859
864
let out = cx. dst . join ( & format ! ( "theme{}.css" , cx. shared. resource_suffix) ) ;
860
- try_err ! ( fs:: copy( css, out) , css) ;
865
+ if !enable_minification {
866
+ try_err ! ( fs:: copy( css, out) , css) ;
867
+ } else {
868
+ let mut f = try_err ! ( File :: open( css) , css) ;
869
+ let mut buffer = String :: with_capacity ( 1000 ) ;
870
+
871
+ try_err ! ( f. read_to_string( & mut buffer) , css) ;
872
+ write_minify ( out, & buffer, enable_minification) ?;
873
+ }
861
874
}
862
- write ( cx. dst . join ( & format ! ( "normalize{}.css" , cx. shared. resource_suffix) ) ,
863
- include_bytes ! ( "static/normalize.css" ) ) ?;
875
+ write_minify ( cx. dst . join ( & format ! ( "normalize{}.css" , cx. shared. resource_suffix) ) ,
876
+ include_str ! ( "static/normalize.css" ) ,
877
+ enable_minification) ?;
864
878
write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
865
879
include_bytes ! ( "static/FiraSans-Regular.woff" ) ) ?;
866
880
write ( cx. dst . join ( "FiraSans-Medium.woff" ) ,
@@ -1051,7 +1065,12 @@ fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> {
1051
1065
1052
1066
fn write_minify ( dst : PathBuf , contents : & str , enable_minification : bool ) -> Result < ( ) , Error > {
1053
1067
if enable_minification {
1054
- write ( dst, minifier:: js:: minify ( contents) . as_bytes ( ) )
1068
+ if dst. extension ( ) == Some ( & OsStr :: new ( "css" ) ) {
1069
+ let res = try_none ! ( minifier:: css:: minify( contents) . ok( ) , & dst) ;
1070
+ write ( dst, res. as_bytes ( ) )
1071
+ } else {
1072
+ write ( dst, minifier:: js:: minify ( contents) . as_bytes ( ) )
1073
+ }
1055
1074
} else {
1056
1075
write ( dst, contents. as_bytes ( ) )
1057
1076
}
0 commit comments