about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-16 07:32:57 +0000
committerbors <bors@rust-lang.org>2021-05-16 07:32:57 +0000
commit94ecdfd115a353f65d4b21056b23c7074339be6e (patch)
tree158a03e0d1787c89ba1549d467cedeef05935972
parente78bccfbc01526808c4222ee49c1b6a2f7d8ab5b (diff)
parentaaf0ff83fb5473a1bd73f9062e168a7e183c444f (diff)
downloadrust-94ecdfd115a353f65d4b21056b23c7074339be6e.tar.gz
rust-94ecdfd115a353f65d4b21056b23c7074339be6e.zip
Auto merge of #85304 - Stupremee:crates-in-sidebar-in-root, r=Nemo157
rustdoc: Call `initSidebarItems` in root module of crate

r? `@jsha`

Resolves #85301
-rw-r--r--src/librustdoc/html/render/mod.rs11
-rw-r--r--src/librustdoc/html/render/write_shared.rs2
-rw-r--r--src/librustdoc/html/static/sidebar-items.js1
-rw-r--r--src/librustdoc/html/static_files.rs3
4 files changed, 14 insertions, 3 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index e4dbf145866..b807c5ccc47 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1745,12 +1745,17 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
         ty = it.type_(),
         path = relpath
     );
+
     if parentlen == 0 {
-        // There is no sidebar-items.js beyond the crate root path
-        // FIXME maybe dynamic crate loading can be merged here
+        write!(
+            buffer,
+            "<script defer src=\"{}sidebar-items{}.js\"></script>",
+            relpath, cx.shared.resource_suffix
+        );
     } else {
-        write!(buffer, "<script defer src=\"{path}sidebar-items.js\"></script>", path = relpath);
+        write!(buffer, "<script defer src=\"{}sidebar-items.js\"></script>", relpath);
     }
+
     // Closes sidebar-elems div.
     buffer.write_str("</div>");
 }
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index c25a73f58eb..bd781e7b741 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -225,6 +225,8 @@ pub(super) fn write_shared(
     )?;
     write_minify("search.js", static_files::SEARCH_JS)?;
     write_minify("settings.js", static_files::SETTINGS_JS)?;
+    write_minify("sidebar-items.js", static_files::sidebar::ITEMS)?;
+
     if cx.shared.include_sources {
         write_minify("source-script.js", static_files::sidebar::SOURCE_SCRIPT)?;
     }
diff --git a/src/librustdoc/html/static/sidebar-items.js b/src/librustdoc/html/static/sidebar-items.js
new file mode 100644
index 00000000000..81172ba0d92
--- /dev/null
+++ b/src/librustdoc/html/static/sidebar-items.js
@@ -0,0 +1 @@
+initSidebarItems({});
diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs
index 1abb1f7294a..4e3d5ff0a4a 100644
--- a/src/librustdoc/html/static_files.rs
+++ b/src/librustdoc/html/static_files.rs
@@ -130,4 +130,7 @@ crate mod source_code_pro {
 crate mod sidebar {
     /// File script to handle sidebar.
     crate static SOURCE_SCRIPT: &str = include_str!("static/source-script.js");
+
+    /// Top Level sidebar items script which will load a sidebar without items.
+    crate static ITEMS: &str = include_str!("static/sidebar-items.js");
 }