@@ -74,17 +74,6 @@ impl<'a> SourceCollector<'a> {
7474 return Ok ( ( ) ) ;
7575 }
7676
77- let contents = match fs:: read_to_string ( & p) {
78- Ok ( contents) => contents,
79- Err ( e) => {
80- return Err ( Error :: new ( e, & p) ) ;
81- }
82- } ;
83-
84- // Remove the utf-8 BOM if any
85- let contents =
86- if contents. starts_with ( "\u{feff} " ) { & contents[ 3 ..] } else { & contents[ ..] } ;
87-
8877 // Create the intermediate directories
8978 let mut cur = self . dst . clone ( ) ;
9079 let mut root_path = String :: from ( "../../" ) ;
@@ -101,30 +90,44 @@ impl<'a> SourceCollector<'a> {
10190 cur. push ( & fname) ;
10291 href. push_str ( & fname. to_string_lossy ( ) ) ;
10392
104- let title = format ! (
105- "{} -- source" ,
106- cur. file_name( ) . expect( "failed to get file name" ) . to_string_lossy( )
107- ) ;
108- let desc = format ! ( "Source to the Rust file `{}`." , filename) ;
109- let page = layout:: Page {
110- title : & title,
111- css_class : "source" ,
112- root_path : & root_path,
113- static_root_path : self . scx . static_root_path . as_deref ( ) ,
114- description : & desc,
115- keywords : BASIC_KEYWORDS ,
116- resource_suffix : & self . scx . resource_suffix ,
117- extra_scripts : & [ & format ! ( "source-files{}" , self . scx. resource_suffix) ] ,
118- static_extra_scripts : & [ & format ! ( "source-script{}" , self . scx. resource_suffix) ] ,
119- } ;
120- let v = layout:: render (
121- & self . scx . layout ,
122- & page,
123- "" ,
124- |buf : & mut _ | print_src ( buf, & contents) ,
125- & self . scx . themes ,
126- ) ;
127- self . scx . fs . write ( & cur, v. as_bytes ( ) ) ?;
93+ // we don't emit source if we have an external location for it
94+ if self . scx . source_code_external_url . is_none ( ) {
95+ let contents = match fs:: read_to_string ( & p) {
96+ Ok ( contents) => contents,
97+ Err ( e) => {
98+ return Err ( Error :: new ( e, & p) ) ;
99+ }
100+ } ;
101+
102+ // Remove the utf-8 BOM if any
103+ let contents =
104+ if contents. starts_with ( "\u{feff} " ) { & contents[ 3 ..] } else { & contents[ ..] } ;
105+
106+ let title = format ! (
107+ "{} -- source" ,
108+ cur. file_name( ) . expect( "failed to get file name" ) . to_string_lossy( )
109+ ) ;
110+ let desc = format ! ( "Source to the Rust file `{}`." , filename) ;
111+ let page = layout:: Page {
112+ title : & title,
113+ css_class : "source" ,
114+ root_path : & root_path,
115+ static_root_path : self . scx . static_root_path . as_deref ( ) ,
116+ description : & desc,
117+ keywords : BASIC_KEYWORDS ,
118+ resource_suffix : & self . scx . resource_suffix ,
119+ extra_scripts : & [ & format ! ( "source-files{}" , self . scx. resource_suffix) ] ,
120+ static_extra_scripts : & [ & format ! ( "source-script{}" , self . scx. resource_suffix) ] ,
121+ } ;
122+ let v = layout:: render (
123+ & self . scx . layout ,
124+ & page,
125+ "" ,
126+ |buf : & mut _ | print_src ( buf, & contents) ,
127+ & self . scx . themes ,
128+ ) ;
129+ self . scx . fs . write ( & cur, v. as_bytes ( ) ) ?;
130+ }
128131 self . scx . local_sources . insert ( p. clone ( ) , href) ;
129132 Ok ( ( ) )
130133 }
0 commit comments