about summary refs log tree commit diff
path: root/src/librustdoc/html/layout.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/html/layout.rs')
-rw-r--r--src/librustdoc/html/layout.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs
index 37ff693bdf1..1ead428ff49 100644
--- a/src/librustdoc/html/layout.rs
+++ b/src/librustdoc/html/layout.rs
@@ -26,6 +26,7 @@ pub struct Page<'a> {
     pub title: &'a str,
     pub css_class: &'a str,
     pub root_path: &'a str,
+    pub static_root_path: Option<&'a str>,
     pub description: &'a str,
     pub keywords: &'a str,
     pub resource_suffix: &'a str,
@@ -36,6 +37,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
     css_file_extension: bool, themes: &[PathBuf], extra_scripts: &[&str])
     -> io::Result<()>
 {
+    let static_root_path = page.static_root_path.unwrap_or(page.root_path);
     write!(dst,
 "<!DOCTYPE html>\
 <html lang=\"en\">\
@@ -46,20 +48,20 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
     <meta name=\"description\" content=\"{description}\">\
     <meta name=\"keywords\" content=\"{keywords}\">\
     <title>{title}</title>\
-    <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}normalize{suffix}.css\">\
-    <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}rustdoc{suffix}.css\" \
+    <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
+    <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \
           id=\"mainThemeStyle\">\
     {themes}\
-    <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}dark{suffix}.css\">\
-    <link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}light{suffix}.css\" \
+    <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}dark{suffix}.css\">\
+    <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}light{suffix}.css\" \
           id=\"themeStyle\">\
-    <script src=\"{root_path}storage{suffix}.js\"></script>\
-    <noscript><link rel=\"stylesheet\" href=\"{root_path}noscript{suffix}.css\"></noscript>\
+    <script src=\"{static_root_path}storage{suffix}.js\"></script>\
+    <noscript><link rel=\"stylesheet\" href=\"{static_root_path}noscript{suffix}.css\"></noscript>\
     {css_extension}\
     {favicon}\
     {in_header}\
     <style type=\"text/css\">\
-    #crate-search{{background-image:url(\"{root_path}down-arrow{suffix}.svg\");}}\
+    #crate-search{{background-image:url(\"{static_root_path}down-arrow{suffix}.svg\");}}\
     </style>\
 </head>\
 <body class=\"rustdoc {css_class}\">\
@@ -77,11 +79,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
     </nav>\
     <div class=\"theme-picker\">\
         <button id=\"theme-picker\" aria-label=\"Pick another theme!\">\
-            <img src=\"{root_path}brush{suffix}.svg\" width=\"18\" alt=\"Pick another theme!\">\
+            <img src=\"{static_root_path}brush{suffix}.svg\" \
+                 width=\"18\" \
+                 alt=\"Pick another theme!\">\
         </button>\
         <div id=\"theme-choices\"></div>\
     </div>\
-    <script src=\"{root_path}theme{suffix}.js\"></script>\
+    <script src=\"{static_root_path}theme{suffix}.js\"></script>\
     <nav class=\"sub\">\
         <form class=\"search-form js-only\">\
             <div class=\"search-container\">\
@@ -96,7 +100,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
                            type=\"search\">\
                 </div>\
                 <a id=\"settings-menu\" href=\"{root_path}settings.html\">\
-                    <img src=\"{root_path}wheel{suffix}.svg\" width=\"18\" alt=\"Change settings\">\
+                    <img src=\"{static_root_path}wheel{suffix}.svg\" \
+                         width=\"18\" \
+                         alt=\"Change settings\">\
                 </a>\
             </div>\
         </form>\
@@ -157,19 +163,22 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
         window.currentCrate = \"{krate}\";\
     </script>\
     <script src=\"{root_path}aliases.js\"></script>\
-    <script src=\"{root_path}main{suffix}.js\"></script>\
+    <script src=\"{static_root_path}main{suffix}.js\"></script>\
     {extra_scripts}\
     <script defer src=\"{root_path}search-index.js\"></script>\
 </body>\
 </html>",
     css_extension = if css_file_extension {
-        format!("<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}theme{suffix}.css\">",
-                root_path = page.root_path,
+        format!("<link rel=\"stylesheet\" \
+                       type=\"text/css\" \
+                       href=\"{static_root_path}theme{suffix}.css\">",
+                static_root_path = static_root_path,
                 suffix=page.resource_suffix)
     } else {
         String::new()
     },
     content   = *t,
+    static_root_path = static_root_path,
     root_path = page.root_path,
     css_class = page.css_class,
     logo      = if layout.logo.is_empty() {
@@ -197,11 +206,13 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
                    .filter_map(|t| t.file_stem())
                    .filter_map(|t| t.to_str())
                    .map(|t| format!(r#"<link rel="stylesheet" type="text/css" href="{}{}{}.css">"#,
-                                    page.root_path,
+                                    static_root_path,
                                     t,
                                     page.resource_suffix))
                    .collect::<String>(),
     suffix=page.resource_suffix,
+    // TODO: break out a separate `static_extra_scripts` that uses `static_root_path` instead,
+    // then leave `source-files.js` here and move `source-script.js` to the static version
     extra_scripts=extra_scripts.iter().map(|e| {
         format!("<script src=\"{root_path}{extra_script}.js\"></script>",
                 root_path=page.root_path,