@@ -92,6 +92,8 @@ pub struct Context {
92
92
/// The current destination folder of where HTML artifacts should be placed.
93
93
/// This changes as the context descends into the module hierarchy.
94
94
pub dst : PathBuf ,
95
+ /// The configurable destination folder for static resources (css, js, etc...).
96
+ pub resources_dst : PathBuf ,
95
97
/// A flag, which when `true`, will render pages which redirect to the
96
98
/// real location of an item. This is used to allow external links to
97
99
/// publicly reused items to redirect to the right location.
@@ -128,6 +130,8 @@ pub struct SharedContext {
128
130
pub sort_modules_alphabetically : bool ,
129
131
/// Additional themes to be added to the generated docs.
130
132
pub themes : Vec < PathBuf > ,
133
+ /// The path where all non-HTML resources will be stored.
134
+ pub root_path : String ,
131
135
}
132
136
133
137
impl SharedContext {
@@ -476,12 +480,14 @@ pub fn derive_id(candidate: String) -> String {
476
480
pub fn run ( mut krate : clean:: Crate ,
477
481
external_html : & ExternalHtml ,
478
482
playground_url : Option < String > ,
483
+ html_dst : PathBuf ,
479
484
dst : PathBuf ,
480
485
passes : FxHashSet < String > ,
481
486
css_file_extension : Option < PathBuf > ,
482
487
renderinfo : RenderInfo ,
483
488
sort_modules_alphabetically : bool ,
484
- themes : Vec < PathBuf > ) -> Result < ( ) , Error > {
489
+ themes : Vec < PathBuf > ,
490
+ root_path : String ) -> Result < ( ) , Error > {
485
491
let src_root = match krate. src {
486
492
FileName :: Real ( ref p) => match p. parent ( ) {
487
493
Some ( p) => p. to_path_buf ( ) ,
@@ -505,6 +511,7 @@ pub fn run(mut krate: clean::Crate,
505
511
created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
506
512
sort_modules_alphabetically,
507
513
themes,
514
+ root_path,
508
515
} ;
509
516
510
517
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -543,10 +550,12 @@ pub fn run(mut krate: clean::Crate,
543
550
}
544
551
}
545
552
try_err ! ( fs:: create_dir_all( & dst) , & dst) ;
546
- krate = render_sources ( & dst, & mut scx, krate) ?;
553
+ try_err ! ( fs:: create_dir_all( & html_dst) , & html_dst) ;
554
+ krate = render_sources ( & html_dst, & mut scx, krate) ?;
547
555
let cx = Context {
548
556
current : Vec :: new ( ) ,
549
- dst,
557
+ dst : html_dst,
558
+ resources_dst : dst,
550
559
render_redirect_pages : false ,
551
560
shared : Arc :: new ( scx) ,
552
561
} ;
@@ -717,7 +726,7 @@ fn write_shared(cx: &Context,
717
726
// Add all the static files. These may already exist, but we just
718
727
// overwrite them anyway to make sure that they're fresh and up-to-date.
719
728
720
- write ( cx. dst . join ( "rustdoc.css" ) ,
729
+ write ( cx. resources_dst . join ( "rustdoc.css" ) ,
721
730
include_bytes ! ( "static/rustdoc.css" ) ) ?;
722
731
723
732
// To avoid "main.css" to be overwritten, we'll first run over the received themes and only
@@ -729,24 +738,24 @@ fn write_shared(cx: &Context,
729
738
730
739
let mut f = try_err ! ( File :: open( & entry) , & entry) ;
731
740
try_err ! ( f. read_to_end( & mut content) , & entry) ;
732
- write ( cx. dst . join ( try_none ! ( entry. file_name( ) , & entry) ) , content. as_slice ( ) ) ?;
741
+ write ( cx. resources_dst . join ( try_none ! ( entry. file_name( ) , & entry) ) , content. as_slice ( ) ) ?;
733
742
themes. insert ( try_none ! ( try_none!( entry. file_stem( ) , & entry) . to_str( ) , & entry) . to_owned ( ) ) ;
734
743
}
735
744
736
- write ( cx. dst . join ( "brush.svg" ) ,
745
+ write ( cx. resources_dst . join ( "brush.svg" ) ,
737
746
include_bytes ! ( "static/brush.svg" ) ) ?;
738
- write ( cx. dst . join ( "main.css" ) ,
747
+ write ( cx. resources_dst . join ( "main.css" ) ,
739
748
include_bytes ! ( "static/themes/main.css" ) ) ?;
740
749
themes. insert ( "main" . to_owned ( ) ) ;
741
- write ( cx. dst . join ( "dark.css" ) ,
750
+ write ( cx. resources_dst . join ( "dark.css" ) ,
742
751
include_bytes ! ( "static/themes/dark.css" ) ) ?;
743
752
themes. insert ( "dark" . to_owned ( ) ) ;
744
753
745
754
let mut themes: Vec < & String > = themes. iter ( ) . collect ( ) ;
746
755
themes. sort ( ) ;
747
756
// To avoid theme switch latencies as much as possible, we put everything theme related
748
757
// at the beginning of the html files into another js file.
749
- write ( cx. dst . join ( "theme.js" ) , format ! (
758
+ write ( cx. resources_dst . join ( "theme.js" ) , format ! (
750
759
r#"var themes = document.getElementById("theme-choices");
751
760
var themePicker = document.getElementById("theme-picker");
752
761
themePicker.onclick = function() {{
@@ -773,42 +782,42 @@ themePicker.onclick = function() {{
773
782
. collect:: <Vec <String >>( )
774
783
. join( "," ) ) . as_bytes ( ) ) ?;
775
784
776
- write ( cx. dst . join ( "main.js" ) , include_bytes ! ( "static/main.js" ) ) ?;
777
- write ( cx. dst . join ( "storage.js" ) , include_bytes ! ( "static/storage.js" ) ) ?;
785
+ write ( cx. resources_dst . join ( "main.js" ) , include_bytes ! ( "static/main.js" ) ) ?;
786
+ write ( cx. resources_dst . join ( "storage.js" ) , include_bytes ! ( "static/storage.js" ) ) ?;
778
787
779
788
if let Some ( ref css) = cx. shared . css_file_extension {
780
- let out = cx. dst . join ( "theme.css" ) ;
789
+ let out = cx. resources_dst . join ( "theme.css" ) ;
781
790
try_err ! ( fs:: copy( css, out) , css) ;
782
791
}
783
- write ( cx. dst . join ( "normalize.css" ) ,
792
+ write ( cx. resources_dst . join ( "normalize.css" ) ,
784
793
include_bytes ! ( "static/normalize.css" ) ) ?;
785
- write ( cx. dst . join ( "FiraSans-Regular.woff" ) ,
794
+ write ( cx. resources_dst . join ( "FiraSans-Regular.woff" ) ,
786
795
include_bytes ! ( "static/FiraSans-Regular.woff" ) ) ?;
787
- write ( cx. dst . join ( "FiraSans-Medium.woff" ) ,
796
+ write ( cx. resources_dst . join ( "FiraSans-Medium.woff" ) ,
788
797
include_bytes ! ( "static/FiraSans-Medium.woff" ) ) ?;
789
- write ( cx. dst . join ( "FiraSans-LICENSE.txt" ) ,
798
+ write ( cx. resources_dst . join ( "FiraSans-LICENSE.txt" ) ,
790
799
include_bytes ! ( "static/FiraSans-LICENSE.txt" ) ) ?;
791
- write ( cx. dst . join ( "Heuristica-Italic.woff" ) ,
800
+ write ( cx. resources_dst . join ( "Heuristica-Italic.woff" ) ,
792
801
include_bytes ! ( "static/Heuristica-Italic.woff" ) ) ?;
793
- write ( cx. dst . join ( "Heuristica-LICENSE.txt" ) ,
802
+ write ( cx. resources_dst . join ( "Heuristica-LICENSE.txt" ) ,
794
803
include_bytes ! ( "static/Heuristica-LICENSE.txt" ) ) ?;
795
- write ( cx. dst . join ( "SourceSerifPro-Regular.woff" ) ,
804
+ write ( cx. resources_dst . join ( "SourceSerifPro-Regular.woff" ) ,
796
805
include_bytes ! ( "static/SourceSerifPro-Regular.woff" ) ) ?;
797
- write ( cx. dst . join ( "SourceSerifPro-Bold.woff" ) ,
806
+ write ( cx. resources_dst . join ( "SourceSerifPro-Bold.woff" ) ,
798
807
include_bytes ! ( "static/SourceSerifPro-Bold.woff" ) ) ?;
799
- write ( cx. dst . join ( "SourceSerifPro-LICENSE.txt" ) ,
808
+ write ( cx. resources_dst . join ( "SourceSerifPro-LICENSE.txt" ) ,
800
809
include_bytes ! ( "static/SourceSerifPro-LICENSE.txt" ) ) ?;
801
- write ( cx. dst . join ( "SourceCodePro-Regular.woff" ) ,
810
+ write ( cx. resources_dst . join ( "SourceCodePro-Regular.woff" ) ,
802
811
include_bytes ! ( "static/SourceCodePro-Regular.woff" ) ) ?;
803
- write ( cx. dst . join ( "SourceCodePro-Semibold.woff" ) ,
812
+ write ( cx. resources_dst . join ( "SourceCodePro-Semibold.woff" ) ,
804
813
include_bytes ! ( "static/SourceCodePro-Semibold.woff" ) ) ?;
805
- write ( cx. dst . join ( "SourceCodePro-LICENSE.txt" ) ,
814
+ write ( cx. resources_dst . join ( "SourceCodePro-LICENSE.txt" ) ,
806
815
include_bytes ! ( "static/SourceCodePro-LICENSE.txt" ) ) ?;
807
- write ( cx. dst . join ( "LICENSE-MIT.txt" ) ,
816
+ write ( cx. resources_dst . join ( "LICENSE-MIT.txt" ) ,
808
817
include_bytes ! ( "static/LICENSE-MIT.txt" ) ) ?;
809
- write ( cx. dst . join ( "LICENSE-APACHE.txt" ) ,
818
+ write ( cx. resources_dst . join ( "LICENSE-APACHE.txt" ) ,
810
819
include_bytes ! ( "static/LICENSE-APACHE.txt" ) ) ?;
811
- write ( cx. dst . join ( "COPYRIGHT.txt" ) ,
820
+ write ( cx. resources_dst . join ( "COPYRIGHT.txt" ) ,
812
821
include_bytes ! ( "static/COPYRIGHT.txt" ) ) ?;
813
822
814
823
fn collect ( path : & Path , krate : & str ,
@@ -830,7 +839,7 @@ themePicker.onclick = function() {{
830
839
}
831
840
832
841
// Update the search index
833
- let dst = cx. dst . join ( "search-index.js" ) ;
842
+ let dst = cx. resources_dst . join ( "search-index.js" ) ;
834
843
let mut all_indexes = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
835
844
all_indexes. push ( search_index) ;
836
845
// Sort the indexes by crate so the file will be generated identically even
@@ -1039,12 +1048,11 @@ impl<'a> SourceCollector<'a> {
1039
1048
1040
1049
// Create the intermediate directories
1041
1050
let mut cur = self . dst . clone ( ) ;
1042
- let mut root_path = String :: from ( "../../" ) ;
1051
+ let root_path = self . scx . root_path . clone ( ) ;
1043
1052
let mut href = String :: new ( ) ;
1044
1053
clean_srcpath ( & self . scx . src_root , & p, false , |component| {
1045
1054
cur. push ( component) ;
1046
1055
fs:: create_dir_all ( & cur) . unwrap ( ) ;
1047
- root_path. push_str ( "../" ) ;
1048
1056
href. push_str ( component) ;
1049
1057
href. push ( '/' ) ;
1050
1058
} ) ;
@@ -1340,6 +1348,14 @@ impl Context {
1340
1348
repeat ( "../" ) . take ( self . current . len ( ) ) . collect :: < String > ( )
1341
1349
}
1342
1350
1351
+ /// String representation of how to get back to the root path of the
1352
+ /// resources folder in terms of a relative URL.
1353
+ fn resources_root_path ( & self ) -> String {
1354
+ let mut s = repeat ( "../" ) . take ( self . current . len ( ) ) . collect :: < String > ( ) ;
1355
+ s. push_str ( & self . shared . root_path . replace ( "../../" , "" ) ) ;
1356
+ s
1357
+ }
1358
+
1343
1359
/// Recurse in the directory structure and change the "root path" to make
1344
1360
/// sure it always points to the top (relatively).
1345
1361
fn recurse < T , F > ( & mut self , s : String , f : F ) -> T where
@@ -1422,7 +1438,7 @@ impl Context {
1422
1438
let keywords = make_item_keywords ( it) ;
1423
1439
let page = layout:: Page {
1424
1440
css_class : tyname,
1425
- root_path : & self . root_path ( ) ,
1441
+ root_path : & self . resources_root_path ( ) ,
1426
1442
title : & title,
1427
1443
description : & desc,
1428
1444
keywords : & keywords,
0 commit comments